|
36 | 36 | // Specify code that is included in the generated .h and .c files |
37 | 37 | // clang-format off |
38 | 38 | %code requires { |
39 | | - // clang-format on |
40 | | - // %code requires block |
| 39 | +// %code requires block |
41 | 40 |
|
42 | 41 | #include "../SQLParserResult.h" |
43 | 42 | #include "../sql/statements.h" |
|
64 | 63 | // %defines "bison_parser.h" |
65 | 64 |
|
66 | 65 | // Tell bison to create a reentrant parser |
67 | | -// clang-format off |
68 | 66 | %define api.pure full |
69 | 67 |
|
70 | 68 | // Prefix the parser |
|
164 | 162 | *********************************/ |
165 | 163 | // clang-format off |
166 | 164 | %destructor { } <fval> <ival> <bval> <join_type> <order_type> <datetime_field> <column_type_t> <column_constraint_t> <import_type_t> <column_constraint_set> <lock_mode_t> <lock_wait_policy_t> |
167 | | - %destructor { free( ($$.name) ); free( ($$.schema) ); } <table_name> |
168 | 165 | %destructor { |
169 | | - if (($$) != nullptr) { |
| 166 | + free( ($$.name) ); |
| 167 | + free( ($$.schema) ); |
| 168 | + } <table_name> |
| 169 | + %destructor { |
| 170 | + if ($$) { |
170 | 171 | for (auto ptr : *($$)) { |
171 | 172 | free(ptr); |
172 | 173 | } |
|
175 | 176 | } <str_vec> |
176 | 177 | %destructor { free( ($$) ); } <sval> |
177 | 178 | %destructor { |
178 | | - if (($$) != nullptr) { |
| 179 | + if ($$) { |
179 | 180 | for (auto ptr : *($$)) { |
180 | 181 | delete ptr; |
181 | 182 | } |
@@ -317,7 +318,7 @@ input : statement_list opt_semicolon { |
317 | 318 |
|
318 | 319 | unsigned param_id = 0; |
319 | 320 | for (void* param : yyloc.param_list) { |
320 | | - if (param != nullptr) { |
| 321 | + if (param) { |
321 | 322 | Expr* expr = (Expr*)param; |
322 | 323 | expr->ival = param_id; |
323 | 324 | result->addParameter(expr); |
@@ -433,11 +434,12 @@ import_statement : IMPORT FROM file_type FILE file_path INTO table_name { |
433 | 434 | $$->schema = $7.schema; |
434 | 435 | $$->tableName = $7.name; |
435 | 436 | } |
436 | | -| COPY table_name FROM file_path opt_file_type { |
| 437 | +| COPY table_name FROM file_path opt_file_type opt_where { |
437 | 438 | $$ = new ImportStatement($5); |
438 | 439 | $$->filePath = $4; |
439 | 440 | $$->schema = $2.schema; |
440 | 441 | $$->tableName = $2.name; |
| 442 | + $$->whereClause = $6; |
441 | 443 | }; |
442 | 444 |
|
443 | 445 | file_type : IDENTIFIER { |
@@ -472,6 +474,11 @@ export_statement : COPY table_name TO file_path opt_file_type { |
472 | 474 | $$->filePath = $4; |
473 | 475 | $$->schema = $2.schema; |
474 | 476 | $$->tableName = $2.name; |
| 477 | +} |
| 478 | +| COPY select_with_paren TO file_path opt_file_type { |
| 479 | + $$ = new ExportStatement($5); |
| 480 | + $$->filePath = $4; |
| 481 | + $$->select = $2; |
475 | 482 | }; |
476 | 483 |
|
477 | 484 | /****************************** |
@@ -778,12 +785,12 @@ select_no_paren : select_clause opt_order opt_limit opt_locking_clause { |
778 | 785 | $$->order = $2; |
779 | 786 |
|
780 | 787 | // Limit could have been set by TOP. |
781 | | - if ($3 != nullptr) { |
| 788 | + if ($3) { |
782 | 789 | delete $$->limit; |
783 | 790 | $$->limit = $3; |
784 | 791 | } |
785 | 792 |
|
786 | | - if ($4 != nullptr) { |
| 793 | + if ($4) { |
787 | 794 | $$->lockings = $4; |
788 | 795 | } |
789 | 796 | } |
@@ -1233,11 +1240,19 @@ join_clause : table_ref_atomic NATURAL JOIN nonjoin_table_ref_atomic { |
1233 | 1240 | $$->join->left = $1; |
1234 | 1241 | $$->join->right = $4; |
1235 | 1242 | auto left_col = Expr::makeColumnRef(strdup($7->name)); |
1236 | | - if ($7->alias != nullptr) left_col->alias = strdup($7->alias); |
1237 | | - if ($1->getName() != nullptr) left_col->table = strdup($1->getName()); |
| 1243 | + if ($7->alias) { |
| 1244 | + left_col->alias = strdup($7->alias); |
| 1245 | + } |
| 1246 | + if ($1->getName()) { |
| 1247 | + left_col->table = strdup($1->getName()); |
| 1248 | + } |
1238 | 1249 | auto right_col = Expr::makeColumnRef(strdup($7->name)); |
1239 | | - if ($7->alias != nullptr) right_col->alias = strdup($7->alias); |
1240 | | - if ($4->getName() != nullptr) right_col->table = strdup($4->getName()); |
| 1250 | + if ($7->alias) { |
| 1251 | + right_col->alias = strdup($7->alias); |
| 1252 | + } |
| 1253 | + if ($4->getName()) { |
| 1254 | + right_col->table = strdup($4->getName()); |
| 1255 | + } |
1241 | 1256 | $$->join->condition = Expr::makeOpBinary(left_col, kOpEquals, right_col); |
1242 | 1257 | delete $7; |
1243 | 1258 | }; |
|
0 commit comments