Added insert multiple rows

This commit is contained in:
Jan Mühlig 2020-10-22 10:45:03 +02:00
parent c2f5ba9857
commit 46a54548fe
8 changed files with 3666 additions and 3528 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* A Bison parser, made by GNU Bison 3.6.4. */ /* A Bison parser, made by GNU Bison 3.5.1. */
/* Bison interface for Yacc-like parsers in C /* Bison interface for Yacc-like parsers in C
@ -31,9 +31,8 @@
This special exception was added by the Free Software Foundation in This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */ version 2.2 of Bison. */
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, /* Undocumented macros, especially those whose name start with YY_,
especially those whose name start with YY_ or yy_. They are are private implementation details. Do not rely on them. */
private implementation details that can be changed or removed. */
#ifndef YY_HSQL_BISON_PARSER_H_INCLUDED #ifndef YY_HSQL_BISON_PARSER_H_INCLUDED
# define YY_HSQL_BISON_PARSER_H_INCLUDED # define YY_HSQL_BISON_PARSER_H_INCLUDED
@ -77,168 +76,166 @@ extern int hsql_debug;
} \ } \
} }
#line 81 "bison_parser.h" #line 80 "bison_parser.h"
/* Token kinds. */ /* Token type. */
#ifndef HSQL_TOKENTYPE #ifndef HSQL_TOKENTYPE
# define HSQL_TOKENTYPE # define HSQL_TOKENTYPE
enum hsql_tokentype enum hsql_tokentype
{ {
SQL_HSQL_EMPTY = -2, SQL_IDENTIFIER = 258,
SQL_YYEOF = 0, /* "end of file" */ SQL_STRING = 259,
SQL_HSQL_error = 256, /* error */ SQL_FLOATVAL = 260,
SQL_HSQL_UNDEF = 257, /* "invalid token" */ SQL_INTVAL = 261,
SQL_IDENTIFIER = 258, /* IDENTIFIER */ SQL_DEALLOCATE = 262,
SQL_STRING = 259, /* STRING */ SQL_PARAMETERS = 263,
SQL_FLOATVAL = 260, /* FLOATVAL */ SQL_INTERSECT = 264,
SQL_INTVAL = 261, /* INTVAL */ SQL_TEMPORARY = 265,
SQL_DEALLOCATE = 262, /* DEALLOCATE */ SQL_TIMESTAMP = 266,
SQL_PARAMETERS = 263, /* PARAMETERS */ SQL_DISTINCT = 267,
SQL_INTERSECT = 264, /* INTERSECT */ SQL_NVARCHAR = 268,
SQL_TEMPORARY = 265, /* TEMPORARY */ SQL_RESTRICT = 269,
SQL_TIMESTAMP = 266, /* TIMESTAMP */ SQL_TRUNCATE = 270,
SQL_DISTINCT = 267, /* DISTINCT */ SQL_ANALYZE = 271,
SQL_NVARCHAR = 268, /* NVARCHAR */ SQL_BETWEEN = 272,
SQL_RESTRICT = 269, /* RESTRICT */ SQL_CASCADE = 273,
SQL_TRUNCATE = 270, /* TRUNCATE */ SQL_COLUMNS = 274,
SQL_ANALYZE = 271, /* ANALYZE */ SQL_CONTROL = 275,
SQL_BETWEEN = 272, /* BETWEEN */ SQL_DEFAULT = 276,
SQL_CASCADE = 273, /* CASCADE */ SQL_EXECUTE = 277,
SQL_COLUMNS = 274, /* COLUMNS */ SQL_EXPLAIN = 278,
SQL_CONTROL = 275, /* CONTROL */ SQL_INTEGER = 279,
SQL_DEFAULT = 276, /* DEFAULT */ SQL_NATURAL = 280,
SQL_EXECUTE = 277, /* EXECUTE */ SQL_PREPARE = 281,
SQL_EXPLAIN = 278, /* EXPLAIN */ SQL_PRIMARY = 282,
SQL_INTEGER = 279, /* INTEGER */ SQL_SCHEMAS = 283,
SQL_NATURAL = 280, /* NATURAL */ SQL_SPATIAL = 284,
SQL_PREPARE = 281, /* PREPARE */ SQL_VARCHAR = 285,
SQL_PRIMARY = 282, /* PRIMARY */ SQL_VIRTUAL = 286,
SQL_SCHEMAS = 283, /* SCHEMAS */ SQL_DESCRIBE = 287,
SQL_SPATIAL = 284, /* SPATIAL */ SQL_BEFORE = 288,
SQL_VARCHAR = 285, /* VARCHAR */ SQL_COLUMN = 289,
SQL_VIRTUAL = 286, /* VIRTUAL */ SQL_CREATE = 290,
SQL_DESCRIBE = 287, /* DESCRIBE */ SQL_DELETE = 291,
SQL_BEFORE = 288, /* BEFORE */ SQL_DIRECT = 292,
SQL_COLUMN = 289, /* COLUMN */ SQL_DOUBLE = 293,
SQL_CREATE = 290, /* CREATE */ SQL_ESCAPE = 294,
SQL_DELETE = 291, /* DELETE */ SQL_EXCEPT = 295,
SQL_DIRECT = 292, /* DIRECT */ SQL_EXISTS = 296,
SQL_DOUBLE = 293, /* DOUBLE */ SQL_EXTRACT = 297,
SQL_ESCAPE = 294, /* ESCAPE */ SQL_CAST = 298,
SQL_EXCEPT = 295, /* EXCEPT */ SQL_FORMAT = 299,
SQL_EXISTS = 296, /* EXISTS */ SQL_GLOBAL = 300,
SQL_EXTRACT = 297, /* EXTRACT */ SQL_HAVING = 301,
SQL_CAST = 298, /* CAST */ SQL_IMPORT = 302,
SQL_FORMAT = 299, /* FORMAT */ SQL_INSERT = 303,
SQL_GLOBAL = 300, /* GLOBAL */ SQL_ISNULL = 304,
SQL_HAVING = 301, /* HAVING */ SQL_OFFSET = 305,
SQL_IMPORT = 302, /* IMPORT */ SQL_RENAME = 306,
SQL_INSERT = 303, /* INSERT */ SQL_SCHEMA = 307,
SQL_ISNULL = 304, /* ISNULL */ SQL_SELECT = 308,
SQL_OFFSET = 305, /* OFFSET */ SQL_SORTED = 309,
SQL_RENAME = 306, /* RENAME */ SQL_TABLES = 310,
SQL_SCHEMA = 307, /* SCHEMA */ SQL_UNIQUE = 311,
SQL_SELECT = 308, /* SELECT */ SQL_UNLOAD = 312,
SQL_SORTED = 309, /* SORTED */ SQL_UPDATE = 313,
SQL_TABLES = 310, /* TABLES */ SQL_VALUES = 314,
SQL_UNIQUE = 311, /* UNIQUE */ SQL_AFTER = 315,
SQL_UNLOAD = 312, /* UNLOAD */ SQL_ALTER = 316,
SQL_UPDATE = 313, /* UPDATE */ SQL_CROSS = 317,
SQL_VALUES = 314, /* VALUES */ SQL_DELTA = 318,
SQL_AFTER = 315, /* AFTER */ SQL_FLOAT = 319,
SQL_ALTER = 316, /* ALTER */ SQL_GROUP = 320,
SQL_CROSS = 317, /* CROSS */ SQL_INDEX = 321,
SQL_DELTA = 318, /* DELTA */ SQL_INNER = 322,
SQL_FLOAT = 319, /* FLOAT */ SQL_LIMIT = 323,
SQL_GROUP = 320, /* GROUP */ SQL_LOCAL = 324,
SQL_INDEX = 321, /* INDEX */ SQL_MERGE = 325,
SQL_INNER = 322, /* INNER */ SQL_MINUS = 326,
SQL_LIMIT = 323, /* LIMIT */ SQL_ORDER = 327,
SQL_LOCAL = 324, /* LOCAL */ SQL_OUTER = 328,
SQL_MERGE = 325, /* MERGE */ SQL_RIGHT = 329,
SQL_MINUS = 326, /* MINUS */ SQL_TABLE = 330,
SQL_ORDER = 327, /* ORDER */ SQL_UNION = 331,
SQL_OUTER = 328, /* OUTER */ SQL_USING = 332,
SQL_RIGHT = 329, /* RIGHT */ SQL_WHERE = 333,
SQL_TABLE = 330, /* TABLE */ SQL_CALL = 334,
SQL_UNION = 331, /* UNION */ SQL_CASE = 335,
SQL_USING = 332, /* USING */ SQL_CHAR = 336,
SQL_WHERE = 333, /* WHERE */ SQL_COPY = 337,
SQL_CALL = 334, /* CALL */ SQL_DATE = 338,
SQL_CASE = 335, /* CASE */ SQL_DATETIME = 339,
SQL_CHAR = 336, /* CHAR */ SQL_DESC = 340,
SQL_COPY = 337, /* COPY */ SQL_DROP = 341,
SQL_DATE = 338, /* DATE */ SQL_ELSE = 342,
SQL_DATETIME = 339, /* DATETIME */ SQL_FILE = 343,
SQL_DESC = 340, /* DESC */ SQL_FROM = 344,
SQL_DROP = 341, /* DROP */ SQL_FULL = 345,
SQL_ELSE = 342, /* ELSE */ SQL_HASH = 346,
SQL_FILE = 343, /* FILE */ SQL_HINT = 347,
SQL_FROM = 344, /* FROM */ SQL_INTO = 348,
SQL_FULL = 345, /* FULL */ SQL_JOIN = 349,
SQL_HASH = 346, /* HASH */ SQL_LEFT = 350,
SQL_HINT = 347, /* HINT */ SQL_LIKE = 351,
SQL_INTO = 348, /* INTO */ SQL_LOAD = 352,
SQL_JOIN = 349, /* JOIN */ SQL_LONG = 353,
SQL_LEFT = 350, /* LEFT */ SQL_NULL = 354,
SQL_LIKE = 351, /* LIKE */ SQL_PLAN = 355,
SQL_LOAD = 352, /* LOAD */ SQL_SHOW = 356,
SQL_LONG = 353, /* LONG */ SQL_TEXT = 357,
SQL_NULL = 354, /* NULL */ SQL_THEN = 358,
SQL_PLAN = 355, /* PLAN */ SQL_TIME = 359,
SQL_SHOW = 356, /* SHOW */ SQL_VIEW = 360,
SQL_TEXT = 357, /* TEXT */ SQL_WHEN = 361,
SQL_THEN = 358, /* THEN */ SQL_WITH = 362,
SQL_TIME = 359, /* TIME */ SQL_ADD = 363,
SQL_VIEW = 360, /* VIEW */ SQL_ALL = 364,
SQL_WHEN = 361, /* WHEN */ SQL_AND = 365,
SQL_WITH = 362, /* WITH */ SQL_ASC = 366,
SQL_ADD = 363, /* ADD */ SQL_END = 367,
SQL_ALL = 364, /* ALL */ SQL_FOR = 368,
SQL_AND = 365, /* AND */ SQL_INT = 369,
SQL_ASC = 366, /* ASC */ SQL_KEY = 370,
SQL_END = 367, /* END */ SQL_NOT = 371,
SQL_FOR = 368, /* FOR */ SQL_OFF = 372,
SQL_INT = 369, /* INT */ SQL_SET = 373,
SQL_KEY = 370, /* KEY */ SQL_TOP = 374,
SQL_NOT = 371, /* NOT */ SQL_AS = 375,
SQL_OFF = 372, /* OFF */ SQL_BY = 376,
SQL_SET = 373, /* SET */ SQL_IF = 377,
SQL_TOP = 374, /* TOP */ SQL_IN = 378,
SQL_AS = 375, /* AS */ SQL_IS = 379,
SQL_BY = 376, /* BY */ SQL_OF = 380,
SQL_IF = 377, /* IF */ SQL_ON = 381,
SQL_IN = 378, /* IN */ SQL_OR = 382,
SQL_IS = 379, /* IS */ SQL_TO = 383,
SQL_OF = 380, /* OF */ SQL_ARRAY = 384,
SQL_ON = 381, /* ON */ SQL_CONCAT = 385,
SQL_OR = 382, /* OR */ SQL_ILIKE = 386,
SQL_TO = 383, /* TO */ SQL_SECOND = 387,
SQL_ARRAY = 384, /* ARRAY */ SQL_MINUTE = 388,
SQL_CONCAT = 385, /* CONCAT */ SQL_HOUR = 389,
SQL_ILIKE = 386, /* ILIKE */ SQL_DAY = 390,
SQL_SECOND = 387, /* SECOND */ SQL_MONTH = 391,
SQL_MINUTE = 388, /* MINUTE */ SQL_YEAR = 392,
SQL_HOUR = 389, /* HOUR */ SQL_TRUE = 393,
SQL_DAY = 390, /* DAY */ SQL_FALSE = 394,
SQL_MONTH = 391, /* MONTH */ SQL_TRANSACTION = 395,
SQL_YEAR = 392, /* YEAR */ SQL_BEGIN = 396,
SQL_TRUE = 393, /* TRUE */ SQL_COMMIT = 397,
SQL_FALSE = 394, /* FALSE */ SQL_ROLLBACK = 398,
SQL_TRANSACTION = 395, /* TRANSACTION */ SQL_BTREE = 399,
SQL_BEGIN = 396, /* BEGIN */ SQL_HASHTABLE = 400,
SQL_COMMIT = 397, /* COMMIT */ SQL_SKIPLIST = 401,
SQL_ROLLBACK = 398, /* ROLLBACK */ SQL_EQUALS = 402,
SQL_EQUALS = 399, /* EQUALS */ SQL_NOTEQUALS = 403,
SQL_NOTEQUALS = 400, /* NOTEQUALS */ SQL_LESS = 404,
SQL_LESS = 401, /* LESS */ SQL_GREATER = 405,
SQL_GREATER = 402, /* GREATER */ SQL_LESSEQ = 406,
SQL_LESSEQ = 403, /* LESSEQ */ SQL_GREATEREQ = 407,
SQL_GREATEREQ = 404, /* GREATEREQ */ SQL_NOTNULL = 408,
SQL_NOTNULL = 405, /* NOTNULL */ SQL_UMINUS = 409
SQL_UMINUS = 406 /* UMINUS */
}; };
typedef enum hsql_tokentype hsql_token_kind_t;
#endif #endif
/* Value type. */ /* Value type. */
@ -277,6 +274,7 @@ union HSQL_STYPE
hsql::LimitDescription* limit; hsql::LimitDescription* limit;
hsql::ColumnDefinition* column_t; hsql::ColumnDefinition* column_t;
hsql::ColumnType column_type_t; hsql::ColumnType column_type_t;
hsql::IndexDataStructureType index_data_structure_type_t;
hsql::ImportType import_type_t; hsql::ImportType import_type_t;
hsql::GroupByDescription* group_t; hsql::GroupByDescription* group_t;
hsql::UpdateClause* update_t; hsql::UpdateClause* update_t;
@ -290,10 +288,11 @@ union HSQL_STYPE
std::vector<hsql::ColumnDefinition*>* column_vec; std::vector<hsql::ColumnDefinition*>* column_vec;
std::vector<hsql::UpdateClause*>* update_vec; std::vector<hsql::UpdateClause*>* update_vec;
std::vector<hsql::Expr*>* expr_vec; std::vector<hsql::Expr*>* expr_vec;
std::vector<std::vector<hsql::Expr*>*>* expr_vec_vec;
std::vector<hsql::OrderDescription*>* order_vec; std::vector<hsql::OrderDescription*>* order_vec;
std::vector<hsql::WithDescription*>* with_description_vec; std::vector<hsql::WithDescription*>* with_description_vec;
#line 297 "bison_parser.h" #line 296 "bison_parser.h"
}; };
typedef union HSQL_STYPE HSQL_STYPE; typedef union HSQL_STYPE HSQL_STYPE;

View File

@ -137,6 +137,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
std::vector<hsql::ColumnDefinition*>* column_vec; std::vector<hsql::ColumnDefinition*>* column_vec;
std::vector<hsql::UpdateClause*>* update_vec; std::vector<hsql::UpdateClause*>* update_vec;
std::vector<hsql::Expr*>* expr_vec; std::vector<hsql::Expr*>* expr_vec;
std::vector<std::vector<hsql::Expr*>*>* expr_vec_vec;
std::vector<hsql::OrderDescription*>* order_vec; std::vector<hsql::OrderDescription*>* order_vec;
std::vector<hsql::WithDescription*>* with_description_vec; std::vector<hsql::WithDescription*>* with_description_vec;
} }
@ -145,7 +146,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
/********************************* /*********************************
** Destructor symbols ** Destructor symbols
*********************************/ *********************************/
%destructor { } <fval> <ival> <uval> <bval> <order_type> <datetime_field> <column_type_t> <import_type_t> %destructor { } <fval> <ival> <uval> <bval> <order_type> <datetime_field> <column_type_t> <import_type_t> <index_data_structure_type_t>
%destructor { free( ($$.name) ); free( ($$.schema) ); } <table_name> %destructor { free( ($$.name) ); free( ($$.schema) ); } <table_name>
%destructor { free( ($$) ); } <sval> %destructor { free( ($$) ); } <sval>
%destructor { %destructor {
@ -155,7 +156,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
} }
} }
delete ($$); delete ($$);
} <str_vec> <table_vec> <column_vec> <update_vec> <expr_vec> <order_vec> <stmt_vec> } <str_vec> <table_vec> <column_vec> <update_vec> <expr_vec> <order_vec> <stmt_vec> <expr_vec_vec>
%destructor { delete ($$); } <*> %destructor { delete ($$); } <*>
@ -231,12 +232,13 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
%type <import_type_t> opt_file_type file_type %type <import_type_t> opt_file_type file_type
%type <str_vec> ident_commalist opt_column_list %type <str_vec> ident_commalist opt_column_list
%type <expr_vec> expr_list select_list opt_literal_list literal_list hint_list opt_hints %type <expr_vec> expr_list select_list opt_literal_list literal_list hint_list opt_hints insert_list
%type <table_vec> table_ref_commalist %type <table_vec> table_ref_commalist
%type <order_vec> opt_order order_list %type <order_vec> opt_order order_list
%type <with_description_vec> opt_with_clause with_clause with_description_list %type <with_description_vec> opt_with_clause with_clause with_description_list
%type <update_vec> update_clause_commalist %type <update_vec> update_clause_commalist
%type <column_vec> column_def_commalist %type <column_vec> column_def_commalist
%type <expr_vec_vec> insert_list_list
/****************************** /******************************
** Token Precedence and Associativity ** Token Precedence and Associativity
@ -655,12 +657,12 @@ truncate_statement:
* INSERT INTO employees SELECT * FROM stundents * INSERT INTO employees SELECT * FROM stundents
******************************/ ******************************/
insert_statement: insert_statement:
INSERT INTO table_name opt_column_list VALUES '(' literal_list ')' { INSERT INTO table_name opt_column_list VALUES insert_list_list {
$$ = new InsertStatement(kInsertValues); $$ = new InsertStatement(kInsertValues);
$$->schema = $3.schema; $$->schema = $3.schema;
$$->tableName = $3.name; $$->tableName = $3.name;
$$->columns = $4; $$->columns = $4;
$$->values = $7; $$->values = $6;
} }
| 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);
@ -677,6 +679,15 @@ opt_column_list:
| /* empty */ { $$ = nullptr; } | /* empty */ { $$ = nullptr; }
; ;
insert_list:
'(' literal_list ')' { $$ = $2; }
;
insert_list_list:
insert_list { $$ = new std::vector<std::vector<Expr*>*> (); $$->push_back($1); }
| insert_list ',' insert_list_list { $$ = $3; $$->push_back($1); }
;
/****************************** /******************************
* Update Statement * Update Statement

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,9 @@
#define hsql_HEADER_H 1 #define hsql_HEADER_H 1
#define hsql_IN_HEADER 1 #define hsql_IN_HEADER 1
#line 5 "flex_lexer.h" #line 6 "flex_lexer.h"
#line 7 "flex_lexer.h" #line 8 "flex_lexer.h"
#define YY_INT_ALIGNED short int #define YY_INT_ALIGNED short int
@ -730,9 +730,9 @@ extern int yylex \
#undef yyTABLES_NAME #undef yyTABLES_NAME
#endif #endif
#line 242 "flex_lexer.l" #line 245 "flex_lexer.l"
#line 736 "flex_lexer.h" #line 737 "flex_lexer.h"
#undef hsql_IN_HEADER #undef hsql_IN_HEADER
#endif /* hsql_HEADER_H */ #endif /* hsql_HEADER_H */

View File

@ -20,7 +20,7 @@ namespace hsql {
char* schema; char* schema;
char* tableName; char* tableName;
std::vector<char*>* columns; std::vector<char*>* columns;
std::vector<Expr*>* values; std::vector<std::vector<Expr*>*>* values;
SelectStatement* select; SelectStatement* select;
}; };

View File

@ -226,12 +226,12 @@ namespace hsql {
delete columns; delete columns;
} }
if (values != nullptr) { //if (values != nullptr) {
for (Expr* expr : *values) { // for (Expr* expr : *values) {
delete expr; // delete expr;
} // }
delete values; // delete values;
} //}
} }
// ShowStatament // ShowStatament

View File

@ -300,8 +300,10 @@ namespace hsql {
switch (stmt->type) { switch (stmt->type) {
case kInsertValues: case kInsertValues:
inprint("Values", numIndent + 1); inprint("Values", numIndent + 1);
for (Expr* expr : *stmt->values) { for (auto* values : *stmt->values) {
printExpression(expr, numIndent + 2); for (Expr* expr : *values) {
printExpression(expr, numIndent + 2);
}
} }
break; break;
case kInsertSelect: case kInsertSelect: