Support escaped strings (e.g., 'Max O''Mustermann') (#104)
* Support escaped strings (e.g., 'Max O''Mustermann') * review
This commit is contained in:
parent
a59deb43c3
commit
62d162579a
File diff suppressed because it is too large
Load Diff
|
@ -457,7 +457,8 @@ void yyfree ( void * , yyscan_t yyscanner );
|
|||
|
||||
#ifdef YY_HEADER_EXPORT_START_CONDITIONS
|
||||
#define INITIAL 0
|
||||
#define COMMENT 1
|
||||
#define singlequotedstring 1
|
||||
#define COMMENT 2
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -729,9 +730,9 @@ extern int yylex \
|
|||
#undef yyTABLES_NAME
|
||||
#endif
|
||||
|
||||
#line 231 "flex_lexer.l"
|
||||
#line 236 "flex_lexer.l"
|
||||
|
||||
|
||||
#line 735 "flex_lexer.h"
|
||||
#line 736 "flex_lexer.h"
|
||||
#undef hsql_IN_HEADER
|
||||
#endif /* hsql_HEADER_H */
|
||||
|
|
|
@ -13,10 +13,15 @@
|
|||
#include "../sql/Expr.h"
|
||||
#include "bison_parser.h"
|
||||
#include <stdio.h>
|
||||
#include <sstream>
|
||||
|
||||
#define TOKEN(name) { return SQL_##name; }
|
||||
|
||||
static std::stringstream strbuf;
|
||||
|
||||
%}
|
||||
%x singlequotedstring
|
||||
|
||||
/***************************
|
||||
** Section 2: Rules
|
||||
***************************/
|
||||
|
@ -219,11 +224,11 @@ FALSE TOKEN(FALSE)
|
|||
return SQL_IDENTIFIER;
|
||||
}
|
||||
|
||||
'[^'\n]*' {
|
||||
// Crop the leading and trailing quote char
|
||||
yylval->sval = hsql::substr(yytext, 1, strlen(yytext)-1);
|
||||
return SQL_STRING;
|
||||
}
|
||||
\' { BEGIN singlequotedstring; strbuf = std::stringstream{}; }
|
||||
<singlequotedstring>\'\' { strbuf << '\''; }
|
||||
<singlequotedstring>[^']* { strbuf << yytext; }
|
||||
<singlequotedstring>\' { BEGIN 0; yylval->sval = strdup(strbuf.str().c_str()); return SQL_STRING; }
|
||||
<singlequotedstring><<EOF>> { fprintf(stderr, "[SQL-Lexer-Error] Unterminated string\n"); return 0; }
|
||||
|
||||
. { fprintf(stderr, "[SQL-Lexer-Error] Unknown Character: %c\n", yytext[0]); return 0; }
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ TEST(CreateStatementTest) {
|
|||
|
||||
TEST(UpdateStatementTest) {
|
||||
SQLParserResult result;
|
||||
SQLParser::parse("UPDATE students SET grade = 5.0, name = 'test' WHERE name = 'Max Mustermann';", &result);
|
||||
SQLParser::parse("UPDATE students SET grade = 5.0, name = 'test' WHERE name = 'Max O''Mustermann';", &result);
|
||||
|
||||
ASSERT(result.isValid());
|
||||
ASSERT_EQ(result.size(), 1);
|
||||
|
@ -84,7 +84,7 @@ TEST(UpdateStatementTest) {
|
|||
ASSERT(stmt->where->isType(kExprOperator));
|
||||
ASSERT_EQ(stmt->where->opType, kOpEquals);
|
||||
ASSERT_STREQ(stmt->where->expr->name, "name");
|
||||
ASSERT_STREQ(stmt->where->expr2->name, "Max Mustermann");
|
||||
ASSERT_STREQ(stmt->where->expr2->name, "Max O'Mustermann");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue