1. add scheme name support for tables names

2. add IF EXIST support for DROP TABLE/VIEW
3. fix memory free bug: delete -> free
4. add features in sqlhelper.cpp
This commit is contained in:
root 2017-09-13 17:37:31 +08:00
parent 6dade78794
commit 1922210f70
14 changed files with 1390 additions and 1294 deletions

File diff suppressed because it is too large Load Diff

View File

@ -237,6 +237,7 @@ union HSQL_STYPE
hsql::ExecuteStatement* exec_stmt; hsql::ExecuteStatement* exec_stmt;
hsql::ShowStatement* show_stmt; hsql::ShowStatement* show_stmt;
hsql::TableName table_n;
hsql::TableRef* table; hsql::TableRef* table;
hsql::Expr* expr; hsql::Expr* expr;
hsql::OrderDescription* order; hsql::OrderDescription* order;
@ -255,7 +256,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 259 "bison_parser.h" /* yacc.c:1909 */ #line 260 "bison_parser.h" /* yacc.c:1909 */
}; };
typedef union HSQL_STYPE HSQL_STYPE; typedef union HSQL_STYPE HSQL_STYPE;

64
src/parser/bison_parser.y Normal file → Executable file
View File

@ -109,6 +109,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
hsql::ExecuteStatement* exec_stmt; hsql::ExecuteStatement* exec_stmt;
hsql::ShowStatement* show_stmt; hsql::ShowStatement* show_stmt;
hsql::TableName table_n;
hsql::TableRef* table; hsql::TableRef* table;
hsql::Expr* expr; hsql::Expr* expr;
hsql::OrderDescription* order; hsql::OrderDescription* order;
@ -132,7 +133,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
/********************************* /*********************************
** Descrutor symbols ** Descrutor symbols
*********************************/ *********************************/
%destructor { } <fval> <ival> <uval> <bval> <order_type> %destructor { } <fval> <ival> <uval> <bval> <order_type> <table_n>
%destructor { free( ($$) ); } <sval> %destructor { free( ($$) ); } <sval>
%destructor { %destructor {
if (($$) != nullptr) { if (($$) != nullptr) {
@ -184,8 +185,9 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
%type <update_stmt> update_statement %type <update_stmt> update_statement
%type <drop_stmt> drop_statement %type <drop_stmt> drop_statement
%type <show_stmt> show_statement %type <show_stmt> show_statement
%type <sval> table_name opt_alias alias file_path prepare_target_query %type <table_n> table_name
%type <bval> opt_not_exists opt_distinct %type <sval> opt_alias alias file_path prepare_target_query
%type <bval> opt_not_exists opt_exists opt_distinct
%type <uval> import_file_type opt_join_type column_type %type <uval> import_file_type opt_join_type column_type
%type <table> from_clause table_ref table_ref_atomic table_ref_name nonjoin_table_ref_atomic %type <table> from_clause table_ref table_ref_atomic table_ref_name nonjoin_table_ref_atomic
%type <table> join_clause table_ref_name_no_alias %type <table> join_clause table_ref_name_no_alias
@ -353,7 +355,8 @@ import_statement:
IMPORT FROM import_file_type FILE file_path INTO table_name { IMPORT FROM import_file_type FILE file_path INTO table_name {
$$ = new ImportStatement((ImportType) $3); $$ = new ImportStatement((ImportType) $3);
$$->filePath = $5; $$->filePath = $5;
$$->tableName = $7; $$->schema = $7.schema;
$$->tableName = $7.name;
} }
; ;
@ -377,7 +380,8 @@ show_statement:
} }
| SHOW COLUMNS table_name { | SHOW COLUMNS table_name {
$$ = new ShowStatement(kShowColumns); $$ = new ShowStatement(kShowColumns);
$$->name = $3; $$->schema = $3.schema;
$$->name = $3.name;
} }
; ;
@ -391,19 +395,22 @@ create_statement:
CREATE TABLE opt_not_exists table_name FROM TBL FILE file_path { CREATE TABLE opt_not_exists table_name FROM TBL FILE file_path {
$$ = new CreateStatement(kCreateTableFromTbl); $$ = new CreateStatement(kCreateTableFromTbl);
$$->ifNotExists = $3; $$->ifNotExists = $3;
$$->tableName = $4; $$->schema = $4.schema;
$$->tableName = $4.name;
$$->filePath = $8; $$->filePath = $8;
} }
| CREATE TABLE opt_not_exists table_name '(' column_def_commalist ')' { | CREATE TABLE opt_not_exists table_name '(' column_def_commalist ')' {
$$ = new CreateStatement(kCreateTable); $$ = new CreateStatement(kCreateTable);
$$->ifNotExists = $3; $$->ifNotExists = $3;
$$->tableName = $4; $$->schema = $4.schema;
$$->tableName = $4.name;
$$->columns = $6; $$->columns = $6;
} }
| CREATE VIEW opt_not_exists table_name opt_column_list AS select_statement { | CREATE VIEW opt_not_exists table_name opt_column_list AS select_statement {
$$ = new CreateStatement(kCreateView); $$ = new CreateStatement(kCreateView);
$$->ifNotExists = $3; $$->ifNotExists = $3;
$$->tableName = $4; $$->schema = $4.schema;
$$->tableName = $4.name;
$$->viewColumns = $5; $$->viewColumns = $5;
$$->select = $7; $$->select = $7;
} }
@ -440,20 +447,30 @@ column_type:
******************************/ ******************************/
drop_statement: drop_statement:
DROP TABLE table_name { DROP TABLE opt_exists table_name {
$$ = new DropStatement(kDropTable); $$ = new DropStatement(kDropTable);
$$->name = $3; $$->ifExists = $3;
$$->schema = $4.schema;
$$->name = $4.name;
} }
| DROP VIEW table_name { | DROP VIEW opt_exists table_name {
$$ = new DropStatement(kDropView); $$ = new DropStatement(kDropView);
$$->name = $3; $$->ifExists = $3;
$$->schema = $4.schema;
$$->name = $4.name;
} }
| DEALLOCATE PREPARE IDENTIFIER { | DEALLOCATE PREPARE IDENTIFIER {
$$ = new DropStatement(kDropPreparedStatement); $$ = new DropStatement(kDropPreparedStatement);
$$->ifExists = false;
$$->name = $3; $$->name = $3;
} }
; ;
opt_exists:
IF EXISTS { $$ = true; }
| /* empty */ { $$ = false; }
;
/****************************** /******************************
* Delete Statement / Truncate statement * Delete Statement / Truncate statement
* DELETE FROM students WHERE grade > 3.0 * DELETE FROM students WHERE grade > 3.0
@ -462,7 +479,8 @@ drop_statement:
delete_statement: delete_statement:
DELETE FROM table_name opt_where { DELETE FROM table_name opt_where {
$$ = new DeleteStatement(); $$ = new DeleteStatement();
$$->tableName = $3; $$->schema = $3.schema;
$$->tableName = $3.name;
$$->expr = $4; $$->expr = $4;
} }
; ;
@ -470,7 +488,8 @@ delete_statement:
truncate_statement: truncate_statement:
TRUNCATE table_name { TRUNCATE table_name {
$$ = new DeleteStatement(); $$ = new DeleteStatement();
$$->tableName = $2; $$->schema = $2.schema;
$$->tableName = $2.name;
} }
; ;
@ -482,13 +501,15 @@ truncate_statement:
insert_statement: insert_statement:
INSERT INTO table_name opt_column_list VALUES '(' literal_list ')' { INSERT INTO table_name opt_column_list VALUES '(' literal_list ')' {
$$ = new InsertStatement(kInsertValues); $$ = new InsertStatement(kInsertValues);
$$->tableName = $3; $$->schema = $3.schema;
$$->tableName = $3.name;
$$->columns = $4; $$->columns = $4;
$$->values = $7; $$->values = $7;
} }
| INSERT INTO table_name opt_column_list select_no_paren { | INSERT INTO table_name opt_column_list select_no_paren {
$$ = new InsertStatement(kInsertSelect); $$ = new InsertStatement(kInsertSelect);
$$->tableName = $3; $$->schema = $3.schema;
$$->tableName = $3.name;
$$->columns = $4; $$->columns = $4;
$$->select = $5; $$->select = $5;
} }
@ -626,6 +647,7 @@ select_list:
from_clause: from_clause:
FROM table_ref { $$ = $2; } FROM table_ref { $$ = $2; }
| /* empty */ { $$ = nullptr; }
; ;
@ -876,7 +898,8 @@ table_ref_commalist:
table_ref_name: table_ref_name:
table_name opt_alias { table_name opt_alias {
auto tbl = new TableRef(kTableName); auto tbl = new TableRef(kTableName);
tbl->name = $1; tbl->schema = $1.schema;
tbl->name = $1.name;
tbl->alias = $2; tbl->alias = $2;
$$ = tbl; $$ = tbl;
} }
@ -886,14 +909,15 @@ table_ref_name:
table_ref_name_no_alias: table_ref_name_no_alias:
table_name { table_name {
$$ = new TableRef(kTableName); $$ = new TableRef(kTableName);
$$->name = $1; $$->schema = $1.schema;
$$->name = $1.name;
} }
; ;
table_name: table_name:
IDENTIFIER IDENTIFIER { $$.schema = nullptr; $$.name = $1;}
| IDENTIFIER '.' IDENTIFIER { $$ = $3; } | IDENTIFIER '.' IDENTIFIER { $$.schema = $1; $$.name = $3; }
; ;

View File

@ -8,8 +8,8 @@
#define FLEX_SCANNER #define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6 #define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 1 #define YY_FLEX_SUBMINOR_VERSION 37
#if YY_FLEX_SUBMINOR_VERSION > 0 #if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA #define FLEX_BETA
#endif #endif
@ -88,13 +88,25 @@ typedef unsigned int flex_uint32_t;
#endif /* ! FLEXINT_H */ #endif /* ! FLEXINT_H */
/* TODO: this is always defined, so inline it */ #ifdef __cplusplus
#define yyconst const
#if defined(__GNUC__) && __GNUC__ >= 3 /* The "const" storage-class-modifier is valid. */
#define yynoreturn __attribute__((__noreturn__)) #define YY_USE_CONST
#else /* ! __cplusplus */
/* C99 requires __STDC__ to be defined as 1. */
#if defined (__STDC__)
#define YY_USE_CONST
#endif /* defined (__STDC__) */
#endif /* ! __cplusplus */
#ifdef YY_USE_CONST
#define yyconst const
#else #else
#define yynoreturn #define yyconst
#endif #endif
/* Returned upon end-of-file. */ /* Returned upon end-of-file. */
@ -147,15 +159,7 @@ typedef void* yyscan_t;
/* Size of default input buffer. */ /* Size of default input buffer. */
#ifndef YY_BUF_SIZE #ifndef YY_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k.
* Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
* Ditto for the __ia64__ case accordingly.
*/
#define YY_BUF_SIZE 32768
#else
#define YY_BUF_SIZE 16384 #define YY_BUF_SIZE 16384
#endif /* __ia64__ */
#endif #endif
/* The state buf must be large enough to hold one state per character in the main buffer. /* The state buf must be large enough to hold one state per character in the main buffer.
@ -177,7 +181,6 @@ typedef size_t yy_size_t;
#define EOB_ACT_LAST_MATCH 2 #define EOB_ACT_LAST_MATCH 2
#define YY_LESS_LINENO(n) #define YY_LESS_LINENO(n)
#define YY_LINENO_REWIND_TO(ptr)
/* Return all but the first "n" matched characters back to the input stream. */ /* Return all but the first "n" matched characters back to the input stream. */
#define yyless(n) \ #define yyless(n) \
@ -207,12 +210,12 @@ struct yy_buffer_state
/* Size of input buffer in bytes, not including room for EOB /* Size of input buffer in bytes, not including room for EOB
* characters. * characters.
*/ */
int yy_buf_size; yy_size_t yy_buf_size;
/* Number of characters read into yy_ch_buf, not including EOB /* Number of characters read into yy_ch_buf, not including EOB
* characters. * characters.
*/ */
int yy_n_chars; yy_size_t yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it, /* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to * and can realloc() it to grow it, and should free() it to
@ -291,7 +294,7 @@ static void hsql__init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner
YY_BUFFER_STATE hsql__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); YY_BUFFER_STATE hsql__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
YY_BUFFER_STATE hsql__scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); YY_BUFFER_STATE hsql__scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
YY_BUFFER_STATE hsql__scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); YY_BUFFER_STATE hsql__scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
void *hsql_alloc (yy_size_t ,yyscan_t yyscanner ); void *hsql_alloc (yy_size_t ,yyscan_t yyscanner );
void *hsql_realloc (void *,yy_size_t ,yyscan_t yyscanner ); void *hsql_realloc (void *,yy_size_t ,yyscan_t yyscanner );
@ -323,7 +326,7 @@ void hsql_free (void * ,yyscan_t yyscanner );
/* Begin user sect3 */ /* Begin user sect3 */
#define hsql_wrap(yyscanner) (/*CONSTCOND*/1) #define hsql_wrap(yyscanner) 1
#define YY_SKIP_YYWRAP #define YY_SKIP_YYWRAP
typedef unsigned char YY_CHAR; typedef unsigned char YY_CHAR;
@ -335,14 +338,14 @@ typedef int yy_state_type;
static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
static int yy_get_next_buffer (yyscan_t yyscanner ); static int yy_get_next_buffer (yyscan_t yyscanner );
static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner ); static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
/* Done after the current pattern has been matched and before the /* Done after the current pattern has been matched and before the
* corresponding action - sets up yytext. * corresponding action - sets up yytext.
*/ */
#define YY_DO_BEFORE_ACTION \ #define YY_DO_BEFORE_ACTION \
yyg->yytext_ptr = yy_bp; \ yyg->yytext_ptr = yy_bp; \
yyleng = (int) (yy_cp - yy_bp); \ yyleng = (size_t) (yy_cp - yy_bp); \
yyg->yy_hold_char = *yy_cp; \ yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \ *yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp; yyg->yy_c_buf_p = yy_cp;
@ -463,7 +466,7 @@ static yyconst flex_int16_t yy_accept[938] =
2, 2, 5, 6, 2, 2, 0 2, 2, 5, 6, 2, 2, 0
} ; } ;
static yyconst YY_CHAR yy_ec[256] = static yyconst flex_int32_t yy_ec[256] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -495,7 +498,7 @@ static yyconst YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1 1, 1, 1, 1, 1
} ; } ;
static yyconst YY_CHAR yy_meta[68] = static yyconst flex_int32_t yy_meta[68] =
{ 0, { 0,
1, 1, 2, 1, 3, 1, 1, 1, 1, 4, 1, 1, 2, 1, 3, 1, 1, 1, 1, 4,
1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4,
@ -506,7 +509,7 @@ static yyconst YY_CHAR yy_meta[68] =
4, 4, 4, 4, 4, 4, 1 4, 4, 4, 4, 4, 4, 1
} ; } ;
static yyconst flex_uint16_t yy_base[945] = static yyconst flex_int16_t yy_base[945] =
{ 0, { 0,
0, 0, 67, 0, 433, 3713, 133, 135, 418, 0, 0, 0, 67, 0, 433, 3713, 133, 135, 418, 0,
3713, 410, 131, 401, 133, 132, 384, 129, 129, 137, 3713, 410, 131, 401, 133, 132, 384, 129, 129, 137,
@ -722,7 +725,7 @@ static yyconst flex_int16_t yy_def[945] =
937, 937, 937, 937 937, 937, 937, 937
} ; } ;
static yyconst flex_uint16_t yy_nxt[3781] = static yyconst flex_int16_t yy_nxt[3781] =
{ 0, { 0,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 11, 17, 18, 19, 20, 21, 22, 23, 24, 16, 11, 17, 18, 19, 20, 21, 22, 23, 24,
@ -1596,7 +1599,7 @@ static yyconst flex_int16_t yy_chk[3781] =
/*************************** /***************************
** Section 3: Rules ** Section 3: Rules
***************************/ ***************************/
#line 1600 "flex_lexer.cpp" #line 1603 "flex_lexer.cpp"
#define INITIAL 0 #define INITIAL 0
#define COMMENT 1 #define COMMENT 1
@ -1626,8 +1629,8 @@ struct yyguts_t
size_t yy_buffer_stack_max; /**< capacity of stack. */ size_t yy_buffer_stack_max; /**< capacity of stack. */
YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
char yy_hold_char; char yy_hold_char;
int yy_n_chars; yy_size_t yy_n_chars;
int yyleng_r; yy_size_t yyleng_r;
char *yy_c_buf_p; char *yy_c_buf_p;
int yy_init; int yy_init;
int yy_start; int yy_start;
@ -1678,23 +1681,23 @@ void hsql_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
FILE *hsql_get_in (yyscan_t yyscanner ); FILE *hsql_get_in (yyscan_t yyscanner );
void hsql_set_in (FILE * _in_str ,yyscan_t yyscanner ); void hsql_set_in (FILE * in_str ,yyscan_t yyscanner );
FILE *hsql_get_out (yyscan_t yyscanner ); FILE *hsql_get_out (yyscan_t yyscanner );
void hsql_set_out (FILE * _out_str ,yyscan_t yyscanner ); void hsql_set_out (FILE * out_str ,yyscan_t yyscanner );
int hsql_get_leng (yyscan_t yyscanner ); yy_size_t hsql_get_leng (yyscan_t yyscanner );
char *hsql_get_text (yyscan_t yyscanner ); char *hsql_get_text (yyscan_t yyscanner );
int hsql_get_lineno (yyscan_t yyscanner ); int hsql_get_lineno (yyscan_t yyscanner );
void hsql_set_lineno (int _line_number ,yyscan_t yyscanner ); void hsql_set_lineno (int line_number ,yyscan_t yyscanner );
int hsql_get_column (yyscan_t yyscanner ); int hsql_get_column (yyscan_t yyscanner );
void hsql_set_column (int _column_no ,yyscan_t yyscanner ); void hsql_set_column (int column_no ,yyscan_t yyscanner );
YYSTYPE * hsql_get_lval (yyscan_t yyscanner ); YYSTYPE * hsql_get_lval (yyscan_t yyscanner );
@ -1716,10 +1719,6 @@ extern int hsql_wrap (yyscan_t yyscanner );
#endif #endif
#endif #endif
#ifndef YY_NO_UNPUT
#endif
#ifndef yytext_ptr #ifndef yytext_ptr
static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
#endif #endif
@ -1740,12 +1739,7 @@ static int input (yyscan_t yyscanner );
/* Amount of stuff to slurp up with each read. */ /* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE #ifndef YY_READ_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k */
#define YY_READ_BUF_SIZE 16384
#else
#define YY_READ_BUF_SIZE 8192 #define YY_READ_BUF_SIZE 8192
#endif /* __ia64__ */
#endif #endif
/* Copy whatever the last rule matched to the standard output. */ /* Copy whatever the last rule matched to the standard output. */
@ -1753,7 +1747,7 @@ static int input (yyscan_t yyscanner );
/* This used to be an fputs(), but since the string might contain NUL's, /* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite(). * we now use fwrite().
*/ */
#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) #define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
#endif #endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
@ -1777,7 +1771,7 @@ static int input (yyscan_t yyscanner );
else \ else \
{ \ { \
errno=0; \ errno=0; \
while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
{ \ { \
if( errno != EINTR) \ if( errno != EINTR) \
{ \ { \
@ -1834,7 +1828,7 @@ extern int hsql_lex \
/* Code executed at the end of each rule. */ /* Code executed at the end of each rule. */
#ifndef YY_BREAK #ifndef YY_BREAK
#define YY_BREAK /*LINTED*/break; #define YY_BREAK break;
#endif #endif
#define YY_RULE_SETUP \ #define YY_RULE_SETUP \
@ -1844,11 +1838,16 @@ extern int hsql_lex \
*/ */
YY_DECL YY_DECL
{ {
yy_state_type yy_current_state; register yy_state_type yy_current_state;
char *yy_cp, *yy_bp; register char *yy_cp, *yy_bp;
int yy_act; register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
#line 51 "flex_lexer.l"
#line 1850 "flex_lexer.cpp"
yylval = yylval_param; yylval = yylval_param;
yylloc = yylloc_param; yylloc = yylloc_param;
@ -1879,13 +1878,7 @@ YY_DECL
hsql__load_buffer_state(yyscanner ); hsql__load_buffer_state(yyscanner );
} }
{ while ( 1 ) /* loops until end-of-file is reached */
#line 51 "flex_lexer.l"
#line 1887 "flex_lexer.cpp"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{ {
yy_cp = yyg->yy_c_buf_p; yy_cp = yyg->yy_c_buf_p;
@ -1901,7 +1894,7 @@ YY_DECL
yy_match: yy_match:
do do
{ {
YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
if ( yy_accept[yy_current_state] ) if ( yy_accept[yy_current_state] )
{ {
yyg->yy_last_accepting_state = yy_current_state; yyg->yy_last_accepting_state = yy_current_state;
@ -1913,7 +1906,7 @@ yy_match:
if ( yy_current_state >= 938 ) if ( yy_current_state >= 938 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp; ++yy_cp;
} }
while ( yy_current_state != 937 ); while ( yy_current_state != 937 );
@ -2632,7 +2625,7 @@ YY_RULE_SETUP
#line 217 "flex_lexer.l" #line 217 "flex_lexer.l"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 2636 "flex_lexer.cpp" #line 2629 "flex_lexer.cpp"
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(COMMENT): case YY_STATE_EOF(COMMENT):
yyterminate(); yyterminate();
@ -2765,7 +2758,6 @@ case YY_STATE_EOF(COMMENT):
"fatal flex scanner internal error--no action found" ); "fatal flex scanner internal error--no action found" );
} /* end of action switch */ } /* end of action switch */
} /* end of scanning one token */ } /* end of scanning one token */
} /* end of user's declarations */
} /* end of hsql_lex */ } /* end of hsql_lex */
/* yy_get_next_buffer - try to read in a new buffer /* yy_get_next_buffer - try to read in a new buffer
@ -2778,9 +2770,9 @@ case YY_STATE_EOF(COMMENT):
static int yy_get_next_buffer (yyscan_t yyscanner) static int yy_get_next_buffer (yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
char *source = yyg->yytext_ptr; register char *source = yyg->yytext_ptr;
int number_to_move, i; register int number_to_move, i;
int ret_val; int ret_val;
if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
@ -2809,7 +2801,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
/* Try to read more data. */ /* Try to read more data. */
/* First move last chars to start of buffer. */ /* First move last chars to start of buffer. */
number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
for ( i = 0; i < number_to_move; ++i ) for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++); *(dest++) = *(source++);
@ -2822,7 +2814,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else else
{ {
int num_to_read = yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 ) while ( num_to_read <= 0 )
@ -2836,7 +2828,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( b->yy_is_our_buffer ) if ( b->yy_is_our_buffer )
{ {
int new_size = b->yy_buf_size * 2; yy_size_t new_size = b->yy_buf_size * 2;
if ( new_size <= 0 ) if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8; b->yy_buf_size += b->yy_buf_size / 8;
@ -2849,7 +2841,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
} }
else else
/* Can't grow it, we don't own it. */ /* Can't grow it, we don't own it. */
b->yy_ch_buf = NULL; b->yy_ch_buf = 0;
if ( ! b->yy_ch_buf ) if ( ! b->yy_ch_buf )
YY_FATAL_ERROR( YY_FATAL_ERROR(
@ -2891,9 +2883,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else else
ret_val = EOB_ACT_CONTINUE_SCAN; ret_val = EOB_ACT_CONTINUE_SCAN;
if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
/* Extend the array by 50%, plus the number we really need. */ /* Extend the array by 50%, plus the number we really need. */
int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) hsql_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) hsql_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
@ -2912,15 +2904,15 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
static yy_state_type yy_get_previous_state (yyscan_t yyscanner) static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
{ {
yy_state_type yy_current_state; register yy_state_type yy_current_state;
char *yy_cp; register char *yy_cp;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_current_state = yyg->yy_start; yy_current_state = yyg->yy_start;
for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
{ {
YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
if ( yy_accept[yy_current_state] ) if ( yy_accept[yy_current_state] )
{ {
yyg->yy_last_accepting_state = yy_current_state; yyg->yy_last_accepting_state = yy_current_state;
@ -2932,7 +2924,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( yy_current_state >= 938 ) if ( yy_current_state >= 938 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
} }
return yy_current_state; return yy_current_state;
@ -2945,11 +2937,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
*/ */
static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
{ {
int yy_is_jam; register int yy_is_jam;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
char *yy_cp = yyg->yy_c_buf_p; register char *yy_cp = yyg->yy_c_buf_p;
YY_CHAR yy_c = 1; register YY_CHAR yy_c = 1;
if ( yy_accept[yy_current_state] ) if ( yy_accept[yy_current_state] )
{ {
yyg->yy_last_accepting_state = yy_current_state; yyg->yy_last_accepting_state = yy_current_state;
@ -2961,17 +2953,13 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( yy_current_state >= 938 ) if ( yy_current_state >= 938 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 937); yy_is_jam = (yy_current_state == 937);
(void)yyg; (void)yyg;
return yy_is_jam ? 0 : yy_current_state; return yy_is_jam ? 0 : yy_current_state;
} }
#ifndef YY_NO_UNPUT
#endif
#ifndef YY_NO_INPUT #ifndef YY_NO_INPUT
#ifdef __cplusplus #ifdef __cplusplus
static int yyinput (yyscan_t yyscanner) static int yyinput (yyscan_t yyscanner)
@ -2997,7 +2985,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else else
{ /* need more input */ { /* need more input */
int offset = yyg->yy_c_buf_p - yyg->yytext_ptr; yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
++yyg->yy_c_buf_p; ++yyg->yy_c_buf_p;
switch ( yy_get_next_buffer( yyscanner ) ) switch ( yy_get_next_buffer( yyscanner ) )
@ -3021,7 +3009,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
case EOB_ACT_END_OF_FILE: case EOB_ACT_END_OF_FILE:
{ {
if ( hsql_wrap(yyscanner ) ) if ( hsql_wrap(yyscanner ) )
return 0; return EOF;
if ( ! yyg->yy_did_buffer_switch_on_eof ) if ( ! yyg->yy_did_buffer_switch_on_eof )
YY_NEW_FILE; YY_NEW_FILE;
@ -3125,7 +3113,7 @@ static void hsql__load_buffer_state (yyscan_t yyscanner)
if ( ! b ) if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in hsql__create_buffer()" ); YY_FATAL_ERROR( "out of dynamic memory in hsql__create_buffer()" );
b->yy_buf_size = (yy_size_t)size; b->yy_buf_size = size;
/* yy_ch_buf has to be 2 characters longer than the size given because /* yy_ch_buf has to be 2 characters longer than the size given because
* we need to put in 2 end-of-buffer characters. * we need to put in 2 end-of-buffer characters.
@ -3277,7 +3265,7 @@ void hsql_pop_buffer_state (yyscan_t yyscanner)
*/ */
static void hsql_ensure_buffer_stack (yyscan_t yyscanner) static void hsql_ensure_buffer_stack (yyscan_t yyscanner)
{ {
int num_to_alloc; yy_size_t num_to_alloc;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!yyg->yy_buffer_stack) { if (!yyg->yy_buffer_stack) {
@ -3286,7 +3274,7 @@ static void hsql_ensure_buffer_stack (yyscan_t yyscanner)
* scanner will even need a stack. We use 2 instead of 1 to avoid an * scanner will even need a stack. We use 2 instead of 1 to avoid an
* immediate realloc on the next call. * immediate realloc on the next call.
*/ */
num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ num_to_alloc = 1;
yyg->yy_buffer_stack = (struct yy_buffer_state**)hsql_alloc yyg->yy_buffer_stack = (struct yy_buffer_state**)hsql_alloc
(num_to_alloc * sizeof(struct yy_buffer_state*) (num_to_alloc * sizeof(struct yy_buffer_state*)
, yyscanner); , yyscanner);
@ -3303,7 +3291,7 @@ static void hsql_ensure_buffer_stack (yyscan_t yyscanner)
if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
/* Increase the buffer to prepare for a possible push. */ /* Increase the buffer to prepare for a possible push. */
yy_size_t grow_size = 8 /* arbitrary grow size */; int grow_size = 8 /* arbitrary grow size */;
num_to_alloc = yyg->yy_buffer_stack_max + grow_size; num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
yyg->yy_buffer_stack = (struct yy_buffer_state**)hsql_realloc yyg->yy_buffer_stack = (struct yy_buffer_state**)hsql_realloc
@ -3333,7 +3321,7 @@ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yysc
base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-2] != YY_END_OF_BUFFER_CHAR ||
base[size-1] != YY_END_OF_BUFFER_CHAR ) base[size-1] != YY_END_OF_BUFFER_CHAR )
/* They forgot to leave room for the EOB's. */ /* They forgot to leave room for the EOB's. */
return NULL; return 0;
b = (YY_BUFFER_STATE) hsql_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); b = (YY_BUFFER_STATE) hsql_alloc(sizeof( struct yy_buffer_state ) ,yyscanner );
if ( ! b ) if ( ! b )
@ -3342,7 +3330,7 @@ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yysc
b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
b->yy_buf_pos = b->yy_ch_buf = base; b->yy_buf_pos = b->yy_ch_buf = base;
b->yy_is_our_buffer = 0; b->yy_is_our_buffer = 0;
b->yy_input_file = NULL; b->yy_input_file = 0;
b->yy_n_chars = b->yy_buf_size; b->yy_n_chars = b->yy_buf_size;
b->yy_is_interactive = 0; b->yy_is_interactive = 0;
b->yy_at_bol = 1; b->yy_at_bol = 1;
@ -3365,7 +3353,7 @@ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yysc
YY_BUFFER_STATE hsql__scan_string (yyconst char * yystr , yyscan_t yyscanner) YY_BUFFER_STATE hsql__scan_string (yyconst char * yystr , yyscan_t yyscanner)
{ {
return hsql__scan_bytes(yystr,(int) strlen(yystr) ,yyscanner); return hsql__scan_bytes(yystr,strlen(yystr) ,yyscanner);
} }
/** Setup the input buffer state to scan the given bytes. The next call to hsql_lex() will /** Setup the input buffer state to scan the given bytes. The next call to hsql_lex() will
@ -3375,7 +3363,7 @@ YY_BUFFER_STATE hsql__scan_string (yyconst char * yystr , yyscan_t yyscanner)
* @param yyscanner The scanner object. * @param yyscanner The scanner object.
* @return the newly allocated buffer state object. * @return the newly allocated buffer state object.
*/ */
YY_BUFFER_STATE hsql__scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) YY_BUFFER_STATE hsql__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner)
{ {
YY_BUFFER_STATE b; YY_BUFFER_STATE b;
char *buf; char *buf;
@ -3383,7 +3371,7 @@ YY_BUFFER_STATE hsql__scan_bytes (yyconst char * yybytes, int _yybytes_len , y
int i; int i;
/* Get memory for full buffer, including space for trailing EOB's. */ /* Get memory for full buffer, including space for trailing EOB's. */
n = (yy_size_t) (_yybytes_len + 2); n = _yybytes_len + 2;
buf = (char *) hsql_alloc(n ,yyscanner ); buf = (char *) hsql_alloc(n ,yyscanner );
if ( ! buf ) if ( ! buf )
YY_FATAL_ERROR( "out of dynamic memory in hsql__scan_bytes()" ); YY_FATAL_ERROR( "out of dynamic memory in hsql__scan_bytes()" );
@ -3409,11 +3397,9 @@ YY_BUFFER_STATE hsql__scan_bytes (yyconst char * yybytes, int _yybytes_len , y
#define YY_EXIT_FAILURE 2 #define YY_EXIT_FAILURE 2
#endif #endif
static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; (void) fprintf( stderr, "%s\n", msg );
(void)yyg;
(void) fprintf( stderr, "%s\n", msg );
exit( YY_EXIT_FAILURE ); exit( YY_EXIT_FAILURE );
} }
@ -3492,7 +3478,7 @@ FILE *hsql_get_out (yyscan_t yyscanner)
/** Get the length of the current token. /** Get the length of the current token.
* @param yyscanner The scanner object. * @param yyscanner The scanner object.
*/ */
int hsql_get_leng (yyscan_t yyscanner) yy_size_t hsql_get_leng (yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng; return yyleng;
@ -3519,10 +3505,10 @@ void hsql_set_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
} }
/** Set the current line number. /** Set the current line number.
* @param _line_number line number * @param line_number
* @param yyscanner The scanner object. * @param yyscanner The scanner object.
*/ */
void hsql_set_lineno (int _line_number , yyscan_t yyscanner) void hsql_set_lineno (int line_number , yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@ -3530,14 +3516,14 @@ void hsql_set_lineno (int _line_number , yyscan_t yyscanner)
if (! YY_CURRENT_BUFFER ) if (! YY_CURRENT_BUFFER )
YY_FATAL_ERROR( "hsql_set_lineno called with no buffer" ); YY_FATAL_ERROR( "hsql_set_lineno called with no buffer" );
yylineno = _line_number; yylineno = line_number;
} }
/** Set the current column. /** Set the current column.
* @param _column_no column number * @param line_number
* @param yyscanner The scanner object. * @param yyscanner The scanner object.
*/ */
void hsql_set_column (int _column_no , yyscan_t yyscanner) void hsql_set_column (int column_no , yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@ -3545,25 +3531,25 @@ void hsql_set_column (int _column_no , yyscan_t yyscanner)
if (! YY_CURRENT_BUFFER ) if (! YY_CURRENT_BUFFER )
YY_FATAL_ERROR( "hsql_set_column called with no buffer" ); YY_FATAL_ERROR( "hsql_set_column called with no buffer" );
yycolumn = _column_no; yycolumn = column_no;
} }
/** Set the input stream. This does not discard the current /** Set the input stream. This does not discard the current
* input buffer. * input buffer.
* @param _in_str A readable stream. * @param in_str A readable stream.
* @param yyscanner The scanner object. * @param yyscanner The scanner object.
* @see hsql__switch_to_buffer * @see hsql__switch_to_buffer
*/ */
void hsql_set_in (FILE * _in_str , yyscan_t yyscanner) void hsql_set_in (FILE * in_str , yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyin = _in_str ; yyin = in_str ;
} }
void hsql_set_out (FILE * _out_str , yyscan_t yyscanner) void hsql_set_out (FILE * out_str , yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyout = _out_str ; yyout = out_str ;
} }
int hsql_get_debug (yyscan_t yyscanner) int hsql_get_debug (yyscan_t yyscanner)
@ -3572,10 +3558,10 @@ int hsql_get_debug (yyscan_t yyscanner)
return yy_flex_debug; return yy_flex_debug;
} }
void hsql_set_debug (int _bdebug , yyscan_t yyscanner) void hsql_set_debug (int bdebug , yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_flex_debug = _bdebug ; yy_flex_debug = bdebug ;
} }
/* Accessor methods for yylval and yylloc */ /* Accessor methods for yylval and yylloc */
@ -3675,10 +3661,10 @@ static int yy_init_globals (yyscan_t yyscanner)
* This function is called from hsql_lex_destroy(), so don't allocate here. * This function is called from hsql_lex_destroy(), so don't allocate here.
*/ */
yyg->yy_buffer_stack = NULL; yyg->yy_buffer_stack = 0;
yyg->yy_buffer_stack_top = 0; yyg->yy_buffer_stack_top = 0;
yyg->yy_buffer_stack_max = 0; yyg->yy_buffer_stack_max = 0;
yyg->yy_c_buf_p = NULL; yyg->yy_c_buf_p = (char *) 0;
yyg->yy_init = 0; yyg->yy_init = 0;
yyg->yy_start = 0; yyg->yy_start = 0;
@ -3691,8 +3677,8 @@ static int yy_init_globals (yyscan_t yyscanner)
yyin = stdin; yyin = stdin;
yyout = stdout; yyout = stdout;
#else #else
yyin = NULL; yyin = (FILE *) 0;
yyout = NULL; yyout = (FILE *) 0;
#endif #endif
/* For future reference: Set errno on error, since we are called by /* For future reference: Set errno on error, since we are called by
@ -3738,10 +3724,7 @@ int hsql_lex_destroy (yyscan_t yyscanner)
#ifndef yytext_ptr #ifndef yytext_ptr
static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; register int i;
(void)yyg;
int i;
for ( i = 0; i < n; ++i ) for ( i = 0; i < n; ++i )
s1[i] = s2[i]; s1[i] = s2[i];
} }
@ -3750,7 +3733,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yysca
#ifdef YY_NEED_STRLEN #ifdef YY_NEED_STRLEN
static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
{ {
int n; register int n;
for ( n = 0; s[n]; ++n ) for ( n = 0; s[n]; ++n )
; ;
@ -3760,16 +3743,11 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
void *hsql_alloc (yy_size_t size , yyscan_t yyscanner) void *hsql_alloc (yy_size_t size , yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; return (void *) malloc( size );
(void)yyg;
return malloc(size);
} }
void *hsql_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner) void *hsql_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
/* The cast to (char *) in the following accommodates both /* The cast to (char *) in the following accommodates both
* implementations that use char* generic pointers, and those * implementations that use char* generic pointers, and those
* that use void* generic pointers. It works with the latter * that use void* generic pointers. It works with the latter
@ -3777,13 +3755,11 @@ void *hsql_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
* any pointer type to void*, and deal with argument conversions * any pointer type to void*, and deal with argument conversions
* as though doing an assignment. * as though doing an assignment.
*/ */
return realloc(ptr, size); return (void *) realloc( (char *) ptr, size );
} }
void hsql_free (void * ptr , yyscan_t yyscanner) void hsql_free (void * ptr , yyscan_t yyscanner)
{ {
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
free( (char *) ptr ); /* see hsql_realloc() for (char *) cast */ free( (char *) ptr ); /* see hsql_realloc() for (char *) cast */
} }

View File

@ -12,8 +12,8 @@
#define FLEX_SCANNER #define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6 #define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 1 #define YY_FLEX_SUBMINOR_VERSION 37
#if YY_FLEX_SUBMINOR_VERSION > 0 #if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA #define FLEX_BETA
#endif #endif
@ -92,13 +92,25 @@ typedef unsigned int flex_uint32_t;
#endif /* ! FLEXINT_H */ #endif /* ! FLEXINT_H */
/* TODO: this is always defined, so inline it */ #ifdef __cplusplus
#define yyconst const
#if defined(__GNUC__) && __GNUC__ >= 3 /* The "const" storage-class-modifier is valid. */
#define yynoreturn __attribute__((__noreturn__)) #define YY_USE_CONST
#else /* ! __cplusplus */
/* C99 requires __STDC__ to be defined as 1. */
#if defined (__STDC__)
#define YY_USE_CONST
#endif /* defined (__STDC__) */
#endif /* ! __cplusplus */
#ifdef YY_USE_CONST
#define yyconst const
#else #else
#define yynoreturn #define yyconst
#endif #endif
/* An opaque pointer. */ /* An opaque pointer. */
@ -120,15 +132,7 @@ typedef void* yyscan_t;
/* Size of default input buffer. */ /* Size of default input buffer. */
#ifndef YY_BUF_SIZE #ifndef YY_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k.
* Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
* Ditto for the __ia64__ case accordingly.
*/
#define YY_BUF_SIZE 32768
#else
#define YY_BUF_SIZE 16384 #define YY_BUF_SIZE 16384
#endif /* __ia64__ */
#endif #endif
#ifndef YY_TYPEDEF_YY_BUFFER_STATE #ifndef YY_TYPEDEF_YY_BUFFER_STATE
@ -153,12 +157,12 @@ struct yy_buffer_state
/* Size of input buffer in bytes, not including room for EOB /* Size of input buffer in bytes, not including room for EOB
* characters. * characters.
*/ */
int yy_buf_size; yy_size_t yy_buf_size;
/* Number of characters read into yy_ch_buf, not including EOB /* Number of characters read into yy_ch_buf, not including EOB
* characters. * characters.
*/ */
int yy_n_chars; yy_size_t yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it, /* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to * and can realloc() it to grow it, and should free() it to
@ -202,7 +206,7 @@ void hsql_pop_buffer_state (yyscan_t yyscanner );
YY_BUFFER_STATE hsql__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); YY_BUFFER_STATE hsql__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
YY_BUFFER_STATE hsql__scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); YY_BUFFER_STATE hsql__scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
YY_BUFFER_STATE hsql__scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); YY_BUFFER_STATE hsql__scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
void *hsql_alloc (yy_size_t ,yyscan_t yyscanner ); void *hsql_alloc (yy_size_t ,yyscan_t yyscanner );
void *hsql_realloc (void *,yy_size_t ,yyscan_t yyscanner ); void *hsql_realloc (void *,yy_size_t ,yyscan_t yyscanner );
@ -210,7 +214,7 @@ void hsql_free (void * ,yyscan_t yyscanner );
/* Begin user sect3 */ /* Begin user sect3 */
#define hsql_wrap(yyscanner) (/*CONSTCOND*/1) #define hsql_wrap(yyscanner) 1
#define YY_SKIP_YYWRAP #define YY_SKIP_YYWRAP
#define yytext_ptr yytext_r #define yytext_ptr yytext_r
@ -252,23 +256,23 @@ void hsql_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
FILE *hsql_get_in (yyscan_t yyscanner ); FILE *hsql_get_in (yyscan_t yyscanner );
void hsql_set_in (FILE * _in_str ,yyscan_t yyscanner ); void hsql_set_in (FILE * in_str ,yyscan_t yyscanner );
FILE *hsql_get_out (yyscan_t yyscanner ); FILE *hsql_get_out (yyscan_t yyscanner );
void hsql_set_out (FILE * _out_str ,yyscan_t yyscanner ); void hsql_set_out (FILE * out_str ,yyscan_t yyscanner );
int hsql_get_leng (yyscan_t yyscanner ); yy_size_t hsql_get_leng (yyscan_t yyscanner );
char *hsql_get_text (yyscan_t yyscanner ); char *hsql_get_text (yyscan_t yyscanner );
int hsql_get_lineno (yyscan_t yyscanner ); int hsql_get_lineno (yyscan_t yyscanner );
void hsql_set_lineno (int _line_number ,yyscan_t yyscanner ); void hsql_set_lineno (int line_number ,yyscan_t yyscanner );
int hsql_get_column (yyscan_t yyscanner ); int hsql_get_column (yyscan_t yyscanner );
void hsql_set_column (int _column_no ,yyscan_t yyscanner ); void hsql_set_column (int column_no ,yyscan_t yyscanner );
YYSTYPE * hsql_get_lval (yyscan_t yyscanner ); YYSTYPE * hsql_get_lval (yyscan_t yyscanner );
@ -304,12 +308,7 @@ static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
/* Amount of stuff to slurp up with each read. */ /* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE #ifndef YY_READ_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k */
#define YY_READ_BUF_SIZE 16384
#else
#define YY_READ_BUF_SIZE 8192 #define YY_READ_BUF_SIZE 8192
#endif /* __ia64__ */
#endif #endif
/* Number of entries by which start-condition stack grows. */ /* Number of entries by which start-condition stack grows. */
@ -347,6 +346,6 @@ extern int hsql_lex \
#line 217 "flex_lexer.l" #line 217 "flex_lexer.l"
#line 351 "flex_lexer.h" #line 350 "flex_lexer.h"
#undef hsql_IN_HEADER #undef hsql_IN_HEADER
#endif /* hsql_HEADER_H */ #endif /* hsql_HEADER_H */

5
src/sql/CreateStatement.h Normal file → Executable file
View File

@ -37,8 +37,9 @@ namespace hsql {
CreateType type; CreateType type;
bool ifNotExists; // default: false bool ifNotExists; // default: false
char* filePath; // default: nullptr char* filePath; // default: nullptr
char* tableName; // default: nullptr char* schema; // default: nullptr
char* tableName; // default: nullptr
std::vector<ColumnDefinition*>* columns; // default: nullptr std::vector<ColumnDefinition*>* columns; // default: nullptr
std::vector<char*>* viewColumns; std::vector<char*>* viewColumns;
SelectStatement* select; SelectStatement* select;

1
src/sql/DeleteStatement.h Normal file → Executable file
View File

@ -13,6 +13,7 @@ namespace hsql {
DeleteStatement(); DeleteStatement();
virtual ~DeleteStatement(); virtual ~DeleteStatement();
char* schema;
char* tableName; char* tableName;
Expr* expr; Expr* expr;
}; };

2
src/sql/DropStatement.h Normal file → Executable file
View File

@ -22,6 +22,8 @@ namespace hsql {
virtual ~DropStatement(); virtual ~DropStatement();
DropType type; DropType type;
bool ifExists;
char* schema;
char* name; char* name;
}; };

5
src/sql/ImportStatement.h Normal file → Executable file
View File

@ -15,8 +15,9 @@ namespace hsql {
virtual ~ImportStatement(); virtual ~ImportStatement();
ImportType type; ImportType type;
const char* filePath; char* filePath;
const char* tableName; char* schema;
char* tableName;
}; };
} // namespace hsql } // namespace hsql

1
src/sql/InsertStatement.h Normal file → Executable file
View File

@ -17,6 +17,7 @@ namespace hsql {
virtual ~InsertStatement(); virtual ~InsertStatement();
InsertType type; InsertType type;
char* schema;
char* tableName; char* tableName;
std::vector<char*>* columns; std::vector<char*>* columns;
std::vector<Expr*>* values; std::vector<Expr*>* values;

1
src/sql/ShowStatement.h Normal file → Executable file
View File

@ -19,6 +19,7 @@ namespace hsql {
virtual ~ShowStatement(); virtual ~ShowStatement();
ShowType type; ShowType type;
char* schema;
char* name; char* name;
}; };

5
src/sql/Table.h Normal file → Executable file
View File

@ -19,6 +19,11 @@ namespace hsql {
kTableCrossProduct kTableCrossProduct
}; };
struct TableName {
char* schema;
char* name;
};
// Holds reference to tables. Can be either table names or a select statement. // Holds reference to tables. Can be either table names or a select statement.
struct TableRef { struct TableRef {
TableRef(TableRefType type); TableRef(TableRefType type);

16
src/sql/statements.cpp Normal file → Executable file
View File

@ -18,6 +18,7 @@ namespace hsql {
type(type), type(type),
ifNotExists(false), ifNotExists(false),
filePath(nullptr), filePath(nullptr),
schema(nullptr),
tableName(nullptr), tableName(nullptr),
columns(nullptr), columns(nullptr),
viewColumns(nullptr), viewColumns(nullptr),
@ -25,6 +26,7 @@ namespace hsql {
CreateStatement::~CreateStatement() { CreateStatement::~CreateStatement() {
free(filePath); free(filePath);
free(schema);
free(tableName); free(tableName);
delete select; delete select;
@ -46,10 +48,12 @@ namespace hsql {
// DeleteStatement // DeleteStatement
DeleteStatement::DeleteStatement() : DeleteStatement::DeleteStatement() :
SQLStatement(kStmtDelete), SQLStatement(kStmtDelete),
schema(nullptr),
tableName(nullptr), tableName(nullptr),
expr(nullptr) {}; expr(nullptr) {};
DeleteStatement::~DeleteStatement() { DeleteStatement::~DeleteStatement() {
free(schema);
free(tableName); free(tableName);
delete expr; delete expr;
} }
@ -58,9 +62,11 @@ namespace hsql {
DropStatement::DropStatement(DropType type) : DropStatement::DropStatement(DropType type) :
SQLStatement(kStmtDrop), SQLStatement(kStmtDrop),
type(type), type(type),
schema(nullptr),
name(nullptr) {} name(nullptr) {}
DropStatement::~DropStatement() { DropStatement::~DropStatement() {
free(schema);
free(name); free(name);
} }
@ -86,23 +92,27 @@ namespace hsql {
SQLStatement(kStmtImport), SQLStatement(kStmtImport),
type(type), type(type),
filePath(nullptr), filePath(nullptr),
schema(nullptr),
tableName(nullptr) {}; tableName(nullptr) {};
ImportStatement::~ImportStatement() { ImportStatement::~ImportStatement() {
delete filePath; free(filePath);
delete tableName; free(schema);
free(tableName);
} }
// InsertStatement // InsertStatement
InsertStatement::InsertStatement(InsertType type) : InsertStatement::InsertStatement(InsertType type) :
SQLStatement(kStmtInsert), SQLStatement(kStmtInsert),
type(type), type(type),
schema(nullptr),
tableName(nullptr), tableName(nullptr),
columns(nullptr), columns(nullptr),
values(nullptr), values(nullptr),
select(nullptr) {} select(nullptr) {}
InsertStatement::~InsertStatement() { InsertStatement::~InsertStatement() {
free(schema);
free(tableName); free(tableName);
delete select; delete select;
@ -125,9 +135,11 @@ namespace hsql {
ShowStatement::ShowStatement(ShowType type) : ShowStatement::ShowStatement(ShowType type) :
SQLStatement(kStmtShow), SQLStatement(kStmtShow),
type(type), type(type),
schema(nullptr),
name(nullptr) {} name(nullptr) {}
ShowStatement::~ShowStatement() { ShowStatement::~ShowStatement() {
free(schema);
free(name); free(name);
} }

29
src/util/sqlhelper.cpp Normal file → Executable file
View File

@ -33,6 +33,10 @@ namespace hsql {
switch (table->type) { switch (table->type) {
case kTableName: case kTableName:
inprint(table->name, numIndent); inprint(table->name, numIndent);
if(table->schema) {
inprint("Schema", numIndent + 1);
inprint(table->schema, numIndent + 2);
}
break; break;
case kTableSelect: case kTableSelect:
printSelectStatementInfo(table->select, numIndent); printSelectStatementInfo(table->select, numIndent);
@ -87,6 +91,10 @@ namespace hsql {
break; break;
case kExprColumnRef: case kExprColumnRef:
inprint(expr->name, numIndent); inprint(expr->name, numIndent);
if(expr->table) {
inprint("Table:", numIndent+1);
inprint(expr->table, numIndent+2);
}
break; break;
// case kExprTableColumnRef: inprint(expr->table, expr->name, numIndent); break; // case kExprTableColumnRef: inprint(expr->table, expr->name, numIndent); break;
case kExprLiteralFloat: case kExprLiteralFloat:
@ -100,11 +108,24 @@ namespace hsql {
break; break;
case kExprFunctionRef: case kExprFunctionRef:
inprint(expr->name, numIndent); inprint(expr->name, numIndent);
for (Expr* e : *expr->exprList) inprint(e->name, numIndent + 1); for (Expr* e : *expr->exprList) printExpression(e, numIndent + 1);
break; break;
case kExprOperator: case kExprOperator:
printOperatorExpression(expr, numIndent); printOperatorExpression(expr, numIndent);
break; break;
case kExprSelect:
printSelectStatementInfo(expr->select, numIndent);
break;
case kExprParameter:
inprint(expr->ival, numIndent);
break;
case kExprArray:
for (Expr* e : *expr->exprList) printExpression(e, numIndent + 1);
break;
case kExprArrayIndex:
printExpression(expr->expr, numIndent + 1);
inprint(expr->ival, numIndent);
break;
default: default:
std::cerr << "Unrecognized expression type " << expr->type << std::endl; std::cerr << "Unrecognized expression type " << expr->type << std::endl;
return; return;
@ -120,8 +141,10 @@ namespace hsql {
inprint("Fields:", numIndent + 1); inprint("Fields:", numIndent + 1);
for (Expr* expr : *stmt->selectList) printExpression(expr, numIndent + 2); for (Expr* expr : *stmt->selectList) printExpression(expr, numIndent + 2);
inprint("Sources:", numIndent + 1); if (stmt->fromTable != nullptr) {
printTableRefInfo(stmt->fromTable, numIndent + 2); inprint("Sources:", numIndent + 1);
printTableRefInfo(stmt->fromTable, numIndent + 2);
}
if (stmt->whereClause != nullptr) { if (stmt->whereClause != nullptr) {
inprint("Search Conditions:", numIndent + 1); inprint("Search Conditions:", numIndent + 1);