Changeset: 1d0bc11dbd60 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1d0bc11dbd60
Modified Files:
        common/options/monet_options.c
        sql/server/sql_scan.c
        tools/mserver/mserver5.1.in
Branch: default
Log Message:

Add new mserver5 option for string interpretation

The boolean option raw_strings controls how the sql scanner interprets string
literals. If the value is false then strings are interpreted as if they were
delimited with E-quotes, that is `SELECT '\"';` will return a single character
string. If the value is true then strings are interpreted as if they were
delimited with R-quotes, that is `SELECT '\"';` will return a two-character
string. The default value is false.

mserver5 --set raw_strings=false
mserver5 --set raw_strings=true


diffs (88 lines):

diff --git a/common/options/monet_options.c b/common/options/monet_options.c
--- a/common/options/monet_options.c
+++ b/common/options/monet_options.c
@@ -43,7 +43,7 @@
 #define getpid _getpid
 #endif
 
-/* these two are used of the set parameter passed into functions is NULL */
+/* these two are used if the set parameter passed into functions is NULL */
 static int default_setlen = 0;
 static opt *default_set = NULL;
 
@@ -218,7 +218,7 @@ mo_builtin_settings(opt **Set)
        if (Set == NULL)
                return 0;
 
-#define N_OPTIONS      7       /*MUST MATCH # OPTIONS BELOW */
+#define N_OPTIONS      8       /*MUST MATCH # OPTIONS BELOW */
        set = malloc(sizeof(opt) * N_OPTIONS);
        if (set == NULL)
                return 0;
@@ -252,6 +252,10 @@ mo_builtin_settings(opt **Set)
        set[i].name = strdup("sql_debug");
        set[i].value = strdup("0");
        i++;
+       set[i].kind = opt_builtin;
+       set[i].name = strdup("raw_strings");
+       set[i].value = strdup("false");
+       i++;
 
        assert(i == N_OPTIONS);
        *Set = set;
diff --git a/sql/server/sql_scan.c b/sql/server/sql_scan.c
--- a/sql/server/sql_scan.c
+++ b/sql/server/sql_scan.c
@@ -1309,17 +1309,18 @@ sql_get_next_token(YYSTYPE *yylval, void
                        quote = '\'';
                        *dst = 0;
                } else {
-#if 0
-                       char *dst = str;
-                       for (char *src = yylval->sval + 1; *src; dst++)
-                               if ((*dst = *src++) == '\'' && *src == '\'')
-                                       src++;
-                       *dst = 0;
-#else
-                       GDKstrFromStr((unsigned char *) str,
-                                     (unsigned char *) yylval->sval + 1,
-                                     lc->yycur-lc->yysval - 1);
-#endif
+                       bool raw_strings = GDKgetenv_istrue("raw_strings");
+                       if (raw_strings) {
+                               char *dst = str;
+                               for (char *src = yylval->sval + 1; *src; dst++)
+                                       if ((*dst = *src++) == '\'' && *src == 
'\'')
+                                               src++;
+                               *dst = 0;
+                       } else {
+                               GDKstrFromStr((unsigned char *)str,
+                                             (unsigned char *)yylval->sval + 1,
+                                             lc->yycur - lc->yysval - 1);
+                       }
                }
                yylval->sval = str;
 
diff --git a/tools/mserver/mserver5.1.in b/tools/mserver/mserver5.1.in
--- a/tools/mserver/mserver5.1.in
+++ b/tools/mserver/mserver5.1.in
@@ -335,6 +335,19 @@ users of the server are allowed to execu
 therefore able to read and modify all data that the server process has
 access to.  In addition, if the C code causes a crash, all bets are
 off.
+.TP
+.B raw_strings=true
+The boolean option raw_strings controls how the sql scanner interprets string
+literals. If the value is
+.B false
+then strings are interpreted as if they were delimited with E-quotes, that is
+strings are interpreted as C strings and backslash characters are needed to
+escape special characters. If the value is
+.B true
+then strings are interpreted as if they were delimited with R-quotes, that is
+all characters are interpreted literally. Single quote characters need to be
+doubled inside strings. The default value is
+.BR false .
 .SH CONFIG FILE FORMAT
 The configuration file readable by
 .I mserver5
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to