Changeset: dafd6ab8390e for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dafd6ab8390e Modified Files: sql/ChangeLog sql/server/sql_parser.y sql/server/sql_scan.c Branch: default Log Message:
Implemented PostrgreSQL-like string constants with C-style escapes. The strings look like E'...'. The code to disable C-style escapes in '...' strings is also there, but currently disabled using "#if 0" (twice) in sql_scan.c. diffs (126 lines): diff --git a/sql/ChangeLog b/sql/ChangeLog --- a/sql/ChangeLog +++ b/sql/ChangeLog @@ -1,6 +1,12 @@ # ChangeLog file for sql # This file is updated with Maddlog +* Fri Nov 23 2018 Sjoerd Mullender <sjo...@acm.org> +- Implemented PostgreSQL-like E'...' strings. The strings can contain + C-style backslash escapes. The old format strings '...' currently + still also accept C-style escapes, but that feature will be removed + in a future release. + * Thu Nov 8 2018 Sjoerd Mullender <sjo...@acm.org> - Imlemented the NULLS FIRST and NULLS LAST option to ORDER BY. The default is NULLS FIRST for ASC(ending) and NULLS LAST for DESC(ending). diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y --- a/sql/server/sql_parser.y +++ b/sql/server/sql_parser.y @@ -1200,7 +1200,7 @@ alter_table_element: $$ = _symbol_create_list( SQL_NOT_NULL, l); } | opt_column ident DROP DEFAULT { $$ = _symbol_create( SQL_DROP_DEFAULT, $2); } - | opt_column ident SET STORAGE STRING + | opt_column ident SET STORAGE string { dlist *l = L(); append_string(l, $2); if (!strlen($5)) @@ -1395,7 +1395,7 @@ opt_encrypted: table_opt_storage: /* empty */ { $$ = NULL; } - | STORAGE ident STRING { $$ = append_string(append_string(L(), $2), $3); } + | STORAGE ident string { $$ = append_string(append_string(L(), $2), $3); } ; table_def: @@ -1462,7 +1462,7 @@ table_def: /* mapi:monetdb://host:port/database[/schema[/table]] This also allows access via monetdbd. We assume the monetdb user with default password */ - | REMOTE TABLE if_not_exists qname table_content_source ON STRING with_opt_credentials + | REMOTE TABLE if_not_exists qname table_content_source ON string with_opt_credentials { int commit_action = CA_COMMIT, tpe = SQL_REMOTE; dlist *l = L(); @@ -2951,7 +2951,7 @@ header: { dlist *l = L(); append_string(l, $1 ); $$ = l; } - | ident STRING + | ident string { dlist *l = L(); append_string(l, $1 ); append_string(l, $2 ); @@ -6589,4 +6589,3 @@ int sqlerror(mvc * c, const char *err) sqlstate, err, QUERY(c->scanner)); return 1; } - 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 @@ -969,7 +969,13 @@ int scanner_symbol(mvc * c, int cur) return tokenize(c, cur); case '\'': case '"': - return scanner_string(c, cur, cur == '\''); + return scanner_string(c, cur, +#if 0 + false +#else + cur == '\'' +#endif + ); case '{': return scanner_body(c); case '-': @@ -1136,6 +1142,10 @@ tokenize(mvc * c, int cur) } else if (iswdigit(cur)) { return number(c, cur); } else if (iswalpha(cur) || cur == '_') { + if (cur == 'E' && + lc->rs->buf[lc->rs->pos + lc->yycur] == '\'') { + return scanner_string(c, scanner_getc(lc), true); + } return keyword_or_ident(c, cur); } else if (iswpunct(cur)) { return scanner_symbol(c, cur); @@ -1220,9 +1230,9 @@ sql_get_next_token(YYSTYPE *yylval, void else if (token == STRING) { char quote = *yylval->sval; char *str = sa_alloc( c->sa, (lc->yycur-lc->yysval-2)*2 + 1 ); - assert(quote == '"' || quote == '\''); + assert(quote == '"' || quote == '\'' || quote == 'E'); - lc->rs->buf[lc->rs->pos+lc->yycur- 1] = 0; + lc->rs->buf[lc->rs->pos + lc->yycur - 1] = 0; if (quote == '"') { if (valid_ident(yylval->sval+1,str)) { token = IDENT; @@ -1230,10 +1240,24 @@ sql_get_next_token(YYSTYPE *yylval, void sql_error(c, 1, SQLSTATE(42000) "Invalid identifier '%s'", yylval->sval+1); return LEX_ERROR; } + } else if (quote == 'E') { + assert(yylval->sval[1] == '\''); + GDKstrFromStr((unsigned char *) str, + (unsigned char *) yylval->sval + 2, + lc->yycur-lc->yysval - 2); + quote = '\''; } 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 } yylval->sval = str; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list