Merge pull request #77 from lawben/master
Add stringLength information to Statement
This commit is contained in:
commit
fe51c9e4f7
2
Makefile
2
Makefile
|
@ -60,7 +60,7 @@ $(LIB_BUILD): $(LIB_OBJ)
|
||||||
$(LIBLINKER) $(LIB_LFLAGS) $(LIB_BUILD) $(LIB_OBJ)
|
$(LIBLINKER) $(LIB_LFLAGS) $(LIB_BUILD) $(LIB_OBJ)
|
||||||
|
|
||||||
$(SRCPARSER)/flex_lexer.o: $(SRCPARSER)/flex_lexer.cpp $(SRCPARSER)/bison_parser.cpp
|
$(SRCPARSER)/flex_lexer.o: $(SRCPARSER)/flex_lexer.cpp $(SRCPARSER)/bison_parser.cpp
|
||||||
$(CXX) $(LIB_CFLAGS) -c -o $@ $< -Wno-sign-compare -Wno-unneeded-internal-declaration
|
$(CXX) $(LIB_CFLAGS) -c -o $@ $< -Wno-sign-compare -Wno-unneeded-internal-declaration -Wno-register
|
||||||
|
|
||||||
%.o: %.cpp $(PARSER_CPP) $(LIB_H)
|
%.o: %.cpp $(PARSER_CPP) $(LIB_H)
|
||||||
$(CXX) $(LIB_CFLAGS) -c -o $@ $<
|
$(CXX) $(LIB_CFLAGS) -c -o $@ $<
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
|
# bison's version is too old on OSX, allow user to pass in custom path
|
||||||
|
BISON?=bison
|
||||||
|
|
||||||
all: bison_parser.cpp flex_lexer.cpp
|
all: bison_parser.cpp flex_lexer.cpp
|
||||||
|
|
||||||
bison_parser.cpp: bison_parser.y
|
bison_parser.cpp: bison_parser.y
|
||||||
@bison --version | head -n 1
|
@$(BISON) --version | head -n 1
|
||||||
bison bison_parser.y --output=bison_parser.cpp --defines=bison_parser.h --verbose
|
$(BISON) bison_parser.y --output=bison_parser.cpp --defines=bison_parser.h --verbose
|
||||||
|
|
||||||
flex_lexer.cpp: flex_lexer.l
|
flex_lexer.cpp: flex_lexer.l
|
||||||
@flex --version
|
@flex --version
|
||||||
|
@ -14,4 +16,4 @@ clean:
|
||||||
|
|
||||||
# Tests if the parser builds correctly and doesn't contain conflicts.
|
# Tests if the parser builds correctly and doesn't contain conflicts.
|
||||||
test:
|
test:
|
||||||
! bison bison_parser.y -v --output=conflict_test.cpp 2>&1 | grep "conflict" >&2
|
! $(BISON) bison_parser.y -v --output=conflict_test.cpp 2>&1 | grep "conflict" >&2
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -48,7 +48,7 @@
|
||||||
extern int hsql_debug;
|
extern int hsql_debug;
|
||||||
#endif
|
#endif
|
||||||
/* "%code requires" blocks. */
|
/* "%code requires" blocks. */
|
||||||
#line 35 "bison_parser.y" /* yacc.c:1909 */
|
#line 35 "bison_parser.y" /* yacc.c:1915 */
|
||||||
|
|
||||||
// %code requires block
|
// %code requires block
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ extern int hsql_debug;
|
||||||
yylloc->first_column = yylloc->last_column; \
|
yylloc->first_column = yylloc->last_column; \
|
||||||
for(int i = 0; yytext[i] != '\0'; i++) { \
|
for(int i = 0; yytext[i] != '\0'; i++) { \
|
||||||
yylloc->total_column++; \
|
yylloc->total_column++; \
|
||||||
|
yylloc->string_length++; \
|
||||||
if(yytext[i] == '\n') { \
|
if(yytext[i] == '\n') { \
|
||||||
yylloc->last_line++; \
|
yylloc->last_line++; \
|
||||||
yylloc->last_column = 0; \
|
yylloc->last_column = 0; \
|
||||||
|
@ -71,7 +72,7 @@ extern int hsql_debug;
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 75 "bison_parser.h" /* yacc.c:1909 */
|
#line 76 "bison_parser.h" /* yacc.c:1915 */
|
||||||
|
|
||||||
/* Token type. */
|
/* Token type. */
|
||||||
#ifndef HSQL_TOKENTYPE
|
#ifndef HSQL_TOKENTYPE
|
||||||
|
@ -217,7 +218,7 @@ extern int hsql_debug;
|
||||||
|
|
||||||
union HSQL_STYPE
|
union HSQL_STYPE
|
||||||
{
|
{
|
||||||
#line 93 "bison_parser.y" /* yacc.c:1909 */
|
#line 95 "bison_parser.y" /* yacc.c:1915 */
|
||||||
|
|
||||||
double fval;
|
double fval;
|
||||||
int64_t ival;
|
int64_t ival;
|
||||||
|
@ -256,7 +257,7 @@ union HSQL_STYPE
|
||||||
std::vector<hsql::Expr*>* expr_vec;
|
std::vector<hsql::Expr*>* expr_vec;
|
||||||
std::vector<hsql::OrderDescription*>* order_vec;
|
std::vector<hsql::OrderDescription*>* order_vec;
|
||||||
|
|
||||||
#line 260 "bison_parser.h" /* yacc.c:1909 */
|
#line 261 "bison_parser.h" /* yacc.c:1915 */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef union HSQL_STYPE HSQL_STYPE;
|
typedef union HSQL_STYPE HSQL_STYPE;
|
||||||
|
|
|
@ -45,6 +45,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
|
||||||
yylloc->first_column = yylloc->last_column; \
|
yylloc->first_column = yylloc->last_column; \
|
||||||
for(int i = 0; yytext[i] != '\0'; i++) { \
|
for(int i = 0; yytext[i] != '\0'; i++) { \
|
||||||
yylloc->total_column++; \
|
yylloc->total_column++; \
|
||||||
|
yylloc->string_length++; \
|
||||||
if(yytext[i] == '\n') { \
|
if(yytext[i] == '\n') { \
|
||||||
yylloc->last_line++; \
|
yylloc->last_line++; \
|
||||||
yylloc->last_column = 0; \
|
yylloc->last_column = 0; \
|
||||||
|
@ -76,6 +77,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
|
||||||
@$.first_line = 0;
|
@$.first_line = 0;
|
||||||
@$.last_line = 0;
|
@$.last_line = 0;
|
||||||
@$.total_column = 0;
|
@$.total_column = 0;
|
||||||
|
@$.string_length = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,8 +265,18 @@ input:
|
||||||
|
|
||||||
|
|
||||||
statement_list:
|
statement_list:
|
||||||
statement { $$ = new std::vector<SQLStatement*>(); $$->push_back($1); }
|
statement {
|
||||||
| statement_list ';' statement { $1->push_back($3); $$ = $1; }
|
$1->stringLength = yylloc.string_length;
|
||||||
|
yylloc.string_length = 0;
|
||||||
|
$$ = new std::vector<SQLStatement*>();
|
||||||
|
$$->push_back($1);
|
||||||
|
}
|
||||||
|
| statement_list ';' statement {
|
||||||
|
$3->stringLength = yylloc.string_length;
|
||||||
|
yylloc.string_length = 0;
|
||||||
|
$1->push_back($3);
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
statement:
|
statement:
|
||||||
|
|
|
@ -22,6 +22,9 @@ struct HSQL_CUST_LTYPE {
|
||||||
|
|
||||||
int total_column;
|
int total_column;
|
||||||
|
|
||||||
|
// Length of the string in the SQL query string
|
||||||
|
int string_length;
|
||||||
|
|
||||||
// Parameters.
|
// Parameters.
|
||||||
// int param_id;
|
// int param_id;
|
||||||
std::vector<void*> param_list;
|
std::vector<void*> param_list;
|
||||||
|
|
|
@ -37,6 +37,9 @@ namespace hsql {
|
||||||
// Shorthand for isType(type).
|
// Shorthand for isType(type).
|
||||||
bool is(StatementType type) const;
|
bool is(StatementType type) const;
|
||||||
|
|
||||||
|
// Length of the string in the SQL query string
|
||||||
|
size_t stringLength;
|
||||||
|
|
||||||
std::vector<Expr*>* hints;
|
std::vector<Expr*>* hints;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -213,4 +213,15 @@ TEST(HintTest) {
|
||||||
ASSERT_EQ(10, stmt->hints->at(1)->exprList->at(0)->ival);
|
ASSERT_EQ(10, stmt->hints->at(1)->exprList->at(0)->ival);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(StringLengthTest) {
|
||||||
|
TEST_PARSE_SQL_QUERY(
|
||||||
|
"SELECT * FROM bar; INSERT INTO foo VALUES (4);\t\n SELECT * FROM foo;",
|
||||||
|
result,
|
||||||
|
3);
|
||||||
|
|
||||||
|
ASSERT_EQ(result.getStatement(0)->stringLength, 18);
|
||||||
|
ASSERT_EQ(result.getStatement(1)->stringLength, 28);
|
||||||
|
ASSERT_EQ(result.getStatement(2)->stringLength, 21);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_MAIN();
|
TEST_MAIN();
|
||||||
|
|
Loading…
Reference in New Issue