168168 hsql::RowLockWaitPolicy lock_wait_policy_t ;
169169
170170 hsql::ImportExportOptions* import_export_option_t ;
171- hsql::CsvImportExportOptions* csv_import_export_option_t ;
171+ std::pair< hsql::CsvOptionType, char *>* csv_option_t ;
172172
173173 // clang-format off
174174}
293293// ImportType is used for compatibility reasons
294294%type <import_type_t> file_type
295295%type <import_export_option_t> opt_import_export_options import_export_options
296- %type <csv_import_export_option_t> csv_import_export_options
296+ %type <csv_option_t> csv_option
297297
298298%type <str_vec> ident_commalist opt_column_list
299299%type <expr_vec> expr_list select_list opt_extended_literal_list extended_literal_list hint_list opt_hints opt_partition
@@ -505,7 +505,7 @@ import_export_options : import_export_options ',' FORMAT file_type {
505505 }
506506 if ($1 ->csv_options && $4 != kImportCSV && $4 != kImportAuto ) {
507507 delete $1 ;
508- yyerror (&yyloc, result, scanner, " Cannot have CSV options (DELIMITER, NULL, QUOTE) without CSV import type ." );
508+ yyerror (&yyloc, result, scanner, " CSV options (DELIMITER, NULL, QUOTE) are only allowed for CSV files ." );
509509 YYERROR ;
510510 }
511511 $1 ->format = $4 ;
@@ -529,78 +529,83 @@ import_export_options : import_export_options ',' FORMAT file_type {
529529 $$ = new ImportExportOptions{};
530530 $$ ->encoding = $2 ;
531531}
532- | import_export_options ' ,' csv_import_export_options {
532+ | import_export_options ' ,' csv_option {
533533 if ($1 ->format != kImportAuto && $1 ->format != kImportCSV ) {
534534 delete $1 ;
535+ free ($3 ->second);
535536 delete $3 ;
536- yyerror (&yyloc, result, scanner, " Cannot have CSV options (DELIMITER, NULL, QUOTE) without CSV import type ." );
537+ yyerror (&yyloc, result, scanner, " CSV options (DELIMITER, NULL, QUOTE) are only allowed for CSV files ." );
537538 YYERROR ;
538539 }
539540
540- if ($1 ->csv_options) {
541- if ($1 ->csv_options->delimiter && $3 ->delimiter) {
542- delete $1 ;
543- delete $3 ;
544- yyerror (&yyloc, result, scanner, " Delimiter must only be provided once." );
545- YYERROR ;
546- }
547- if ($1 ->csv_options->null && $3 ->null) {
548- delete $1 ;
549- delete $3 ;
550- yyerror (&yyloc, result, scanner, " Null string must only be provided once." );
551- YYERROR ;
552- }
553- if ($1 ->csv_options->quote && $3 ->quote) {
554- delete $1 ;
555- delete $3 ;
556- yyerror (&yyloc, result, scanner, " Quote must only be provided once." );
557- YYERROR ;
558- }
541+ if ($1 ->csv_options == nullptr ) {
542+ $1 ->csv_options = new CsvOptions{};
543+ }
559544
560- if ($3 ->delimiter) {
561- $1 ->csv_options->delimiter = $3 ->delimiter;
562- $3 ->delimiter = nullptr ;
563- }
564- if ($3 ->null) {
565- $1 ->csv_options->null = $3 ->null;
566- $3 ->null = nullptr ;
545+ #define ASSERT_IS_NULLPTR (ptr ) \
546+ if ((ptr) != nullptr ) { \
547+ delete $1 ; \
548+ free ($3 ->second); \
549+ delete $3 ; \
550+ yyerror (&yyloc, result, scanner, " CSV options (DELIMITER, NULL, QUOTE) cannot be provided more than once." ); \
551+ YYERROR ; \
552+ }
567553
568- }
569- if ($3 ->quote) {
570- $1 ->csv_options->quote = $3 ->quote;
571- $3 ->quote = nullptr ;
572- }
573- delete $3 ;
554+ if ($3 ->first == hsql::CsvOptionType::Delimiter) {
555+ ASSERT_IS_NULLPTR ($1 ->csv_options->delimiter);
556+ $$ ->csv_options->delimiter = $3 ->second;
557+ } else if ($3 ->first == hsql::CsvOptionType::Null) {
558+ ASSERT_IS_NULLPTR ($1 ->csv_options->null);
559+ $$ ->csv_options->null = $3 ->second;
560+ } else if ($3 ->first == hsql::CsvOptionType::Quote) {
561+ ASSERT_IS_NULLPTR ($1 ->csv_options->quote);
562+ $$ ->csv_options->quote = $3 ->second;
574563 } else {
575- $1 ->csv_options = $3 ;
564+ delete $1 ;
565+ free ($3 ->second);
566+ delete $3 ;
567+ yyerror (&yyloc, result, scanner, " Unknown CSV option." );
568+ YYERROR ;
576569 }
577570
571+ delete $3 ;
578572 $$ = $1 ;
579573}
580- | csv_import_export_options {
574+ | csv_option {
581575 $$ = new ImportExportOptions{};
582- $$ ->csv_options = $1 ;
576+ $$ ->csv_options = new CsvOptions{};
577+
578+ if ($1 ->first == hsql::CsvOptionType::Delimiter) {
579+ $$ ->csv_options->delimiter = $1 ->second;
580+ } else if ($1 ->first == hsql::CsvOptionType::Null) {
581+ $$ ->csv_options->null = $1 ->second;
582+ } else if ($1 ->first == hsql::CsvOptionType::Quote) {
583+ $$ ->csv_options->quote = $1 ->second;
584+ } else {
585+ free ($1 ->second);
586+ delete $1 ;
587+ delete $$ ;
588+ yyerror (&yyloc, result, scanner, " Unknown CSV option." );
589+ YYERROR ;
590+ }
591+
592+ delete $1 ;
583593}
584594
585- csv_import_export_options : IDENTIFIER STRING {
586- $$ = new CsvImportExportOptions{};
595+ csv_option : IDENTIFIER STRING {
587596 if (strcasecmp($1 , " DELIMITER" ) == 0 ) {
588- $$ ->delimiter = $2 ;
597+ $$ = new std::pair(hsql::CsvOptionType::Delimiter, $2 ) ;
589598 } else if (strcasecmp($1 , " QUOTE" ) == 0 ) {
590- $$ ->quote = $2 ;
599+ $$ = new std::pair(hsql::CsvOptionType::Quote, $2 ) ;
591600 } else {
592- delete $$ ;
593601 free ($1 );
594602 free ($2 );
595- yyerror (&yyloc, result, scanner, " Unknown identifier when parsing CSV options ." );
603+ yyerror (&yyloc, result, scanner, " Unknown CSV option ." );
596604 YYERROR ;
597605 }
598606 free ($1 );
599607}
600- | NULL STRING {
601- $$ = new CsvImportExportOptions{};
602- $$ ->null = $2 ;
603- }
608+ | NULL STRING { $$ = new std::pair(hsql::CsvOptionType::Null, $2 ); }
604609
605610/* *****************************
606611 * Export Statement
0 commit comments