2015-12-23 16:01:08 +01:00
|
|
|
|
2014-10-09 01:30:22 +02:00
|
|
|
#include "SQLParser.h"
|
2015-12-23 16:01:08 +01:00
|
|
|
#include "parser/bison_parser.h"
|
|
|
|
#include "parser/flex_lexer.h"
|
2014-10-09 01:30:22 +02:00
|
|
|
#include <stdio.h>
|
2015-05-23 18:39:19 +02:00
|
|
|
#include <string>
|
2014-10-09 01:30:22 +02:00
|
|
|
|
|
|
|
|
2014-10-31 18:36:02 +01:00
|
|
|
namespace hsql {
|
|
|
|
|
2016-02-27 15:01:06 +01:00
|
|
|
SQLParser::SQLParser() {
|
|
|
|
fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n");
|
|
|
|
}
|
2014-10-09 01:30:22 +02:00
|
|
|
|
|
|
|
|
2016-02-27 15:01:06 +01:00
|
|
|
SQLParserResult* SQLParser::parseSQLString(const char *text) {
|
|
|
|
SQLParserResult* result = NULL;
|
|
|
|
yyscan_t scanner;
|
|
|
|
YY_BUFFER_STATE state;
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2016-02-27 15:01:06 +01:00
|
|
|
if (hsql_lex_init(&scanner)) {
|
|
|
|
// couldn't initialize
|
|
|
|
fprintf(stderr, "[Error] SQLParser: Error when initializing lexer!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2016-02-27 15:01:06 +01:00
|
|
|
state = hsql__scan_string(text, scanner);
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2016-02-27 15:01:06 +01:00
|
|
|
if (hsql_parse(&result, scanner)) {
|
|
|
|
// Returns an error stmt object
|
|
|
|
return result;
|
|
|
|
}
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2016-02-27 15:01:06 +01:00
|
|
|
hsql__delete_buffer(state, scanner);
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2016-02-27 15:01:06 +01:00
|
|
|
hsql_lex_destroy(scanner);
|
|
|
|
return result;
|
|
|
|
}
|
2015-01-07 13:24:39 +01:00
|
|
|
|
2016-02-27 14:45:59 +01:00
|
|
|
|
2016-02-27 15:01:06 +01:00
|
|
|
SQLParserResult* SQLParser::parseSQLString(const std::string& text) {
|
|
|
|
return parseSQLString(text.c_str());
|
|
|
|
}
|
|
|
|
|
2015-01-07 13:24:39 +01:00
|
|
|
|
2014-10-31 18:36:02 +01:00
|
|
|
} // namespace hsql
|