2014-10-09 01:30:22 +02:00
|
|
|
#include "SQLParser.h"
|
2014-10-16 15:35:38 +02:00
|
|
|
#include "bison_parser.h"
|
|
|
|
#include "flex_lexer.h"
|
2014-10-09 01:30:22 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
2014-10-31 18:36:02 +01:00
|
|
|
namespace hsql {
|
|
|
|
|
2014-10-09 01:30:22 +02:00
|
|
|
SQLParser::SQLParser() {
|
|
|
|
fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-03 17:43:02 +01:00
|
|
|
SQLStatementList* SQLParser::parseSQLString(const char *text) {
|
|
|
|
SQLStatementList* result;
|
2014-10-09 01:30:22 +02:00
|
|
|
yyscan_t scanner;
|
|
|
|
YY_BUFFER_STATE state;
|
|
|
|
|
2014-10-31 18:24:47 +01:00
|
|
|
if (hsql_lex_init(&scanner)) {
|
2014-10-09 01:30:22 +02:00
|
|
|
// couldn't initialize
|
2014-11-03 23:57:42 +01:00
|
|
|
fprintf(stderr, "[Error] SQLParser: Error when initializing lexer!\n");
|
2014-10-09 01:30:22 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-10-31 18:24:47 +01:00
|
|
|
state = hsql__scan_string(text, scanner);
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2014-11-07 02:00:09 +01:00
|
|
|
if (hsql_parse(&result, scanner)) {
|
2014-11-04 00:02:40 +01:00
|
|
|
// Returns an error stmt object
|
2014-11-07 02:00:09 +01:00
|
|
|
return result;
|
2014-10-09 01:30:22 +02:00
|
|
|
}
|
|
|
|
|
2014-10-31 18:24:47 +01:00
|
|
|
hsql__delete_buffer(state, scanner);
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2014-10-31 18:24:47 +01:00
|
|
|
hsql_lex_destroy(scanner);
|
2014-11-07 02:00:09 +01:00
|
|
|
return result;
|
2014-10-31 18:36:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace hsql
|