From 9d1d258eec8ced685f0951b1b9992f0a2d8e1004 Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Fri, 5 Aug 2022 00:14:06 +0000 Subject: [PATCH] Fix a bug of EXEC SQL INCLUDE (#23, #24, #25) --- ocesql/ocesql.h | 7 + ocesql/parser.c | 6 +- ocesql/parser.y | 6 +- ocesql/ppout.c | 51 +++--- ocesql/scanner.c | 242 +++++++++++++++------------- ocesql/scanner.l | 32 +++- tests/Makefile.am | 3 +- tests/Makefile.in | 3 +- tests/basic.src/declare-bind-var.at | 2 +- tests/misc.at | 3 +- tests/misc.src/include.at | 219 +++++++++++++++++++++++++ tests/misc.src/long-sql.at | 2 +- 12 files changed, 430 insertions(+), 146 deletions(-) create mode 100644 tests/misc.src/include.at diff --git a/ocesql/ocesql.h b/ocesql/ocesql.h index 3147a90..dc6d19a 100644 --- a/ocesql/ocesql.h +++ b/ocesql/ocesql.h @@ -96,6 +96,11 @@ enum oc_usage{ #define INC_START_MARK ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" #define INC__END__MARK "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" + +#define PERIOD_DEFAULT 0 +#define PERIOD_FORCE_ON 1 +#define PERIOD_FORCE_OFF 2 + struct filename { char *source; char *translate; @@ -205,6 +210,8 @@ extern char *errorfilename; extern int flag_external; extern char *filenameID; +extern int config_period; + extern struct cb_sql_list * cb_add_text_list (struct cb_sql_list *list, struct cb_sql_list *targetlist); extern struct cb_sql_list * diff --git a/ocesql/parser.c b/ocesql/parser.c index ab176a1..dd1aade 100644 --- a/ocesql/parser.c +++ b/ocesql/parser.c @@ -2350,7 +2350,11 @@ put_exec_list() l->startLine = startlineno; l->endLine = endlineno; - l->period = period; + if(config_period == PERIOD_FORCE_ON || (config_period == PERIOD_DEFAULT && period != 0)) { + l->period = 1; + } else { + l->period = 0; + } l->host_list = host_reference_list; l->hostreferenceCount =hostreferenceCount; l->res_host_list = res_host_reference_list; diff --git a/ocesql/parser.y b/ocesql/parser.y index 06b6ee9..8d7acdc 100644 --- a/ocesql/parser.y +++ b/ocesql/parser.y @@ -505,7 +505,11 @@ put_exec_list() l->startLine = startlineno; l->endLine = endlineno; - l->period = period; + if(config_period == PERIOD_FORCE_ON || (config_period == PERIOD_DEFAULT && period != 0)) { + l->period = 1; + } else { + l->period = 0; + } l->host_list = host_reference_list; l->hostreferenceCount =hostreferenceCount; l->res_host_list = res_host_reference_list; diff --git a/ocesql/ppout.c b/ocesql/ppout.c index 28c942c..58ed096 100644 --- a/ocesql/ppout.c +++ b/ocesql/ppout.c @@ -202,10 +202,11 @@ void ppoutputendcall(struct cb_exec_list *list){ return ; memset(buff, 0, sizeof(buff)); - if( list->period) + if(config_period == PERIOD_FORCE_ON || (config_period == PERIOD_DEFAULT && list->period)) { com_sprintf(buff,sizeof(buff), "OCESQL%5sEND-CALL.\n", " "); - else + } else { com_sprintf(buff,sizeof(buff), "OCESQL%5sEND-CALL\n", " "); + } fputs(buff, outfile); return ; @@ -1880,15 +1881,10 @@ void ppbuff_incfile(struct cb_exec_list *list){ incf = fopen_or_die(filename, "r"); - memset(incmsg, 0, 256); - sprintf(incmsg, "%s incfile start:%s", INC_START_MARK, filename); - com_strcpy(out,sizeof(out),incmsg); - outwrite(); - while(1){ memset(incf_buff, 0, BUFFSIZE + 1); - fgets(incf_buff, BUFFSIZE, incf); - if(feof(incf)) break; + char* result = fgets(incf_buff, BUFFSIZE, incf); + if(result == NULL) break; if(strlen(incf_buff) > MAX_LINESIZE){ memset(buff, 0, sizeof(buff)); @@ -1896,21 +1892,19 @@ void ppbuff_incfile(struct cb_exec_list *list){ printerrormsg("", lineNUM, buff); } + int len = strlen(incf_buff); + if(len > 0 && incf_buff[len - 1] == '\n') { + if(len > 1 && incf_buff[len - 2] == '\r') { + incf_buff[len - 2] = '\0'; + } else { + incf_buff[len - 1] = '\0'; + } + } com_strcpy(out,sizeof(out),"OCESQL"); com_strcat(out,sizeof(out), incf_buff + strlen("OCESQL")); - retcode = strlen(incf_buff); - len2 = strlen("OCESQL"); - if(retcode > len2){ - out[retcode-1] = '\0'; - } outwrite(); } - memset(incmsg, 0, 256); - sprintf(incmsg, "%s incfile end:%s",INC__END__MARK , filename); - com_strcpy(out,sizeof(out),incmsg); - outwrite(); - return; } return; @@ -1939,8 +1933,11 @@ void ppoutput(char *ppin,char *ppout,struct cb_exec_list *head){ EOFFLG = 0; if (readfile && outfile){ - for(;EOFflg != 1;){ + while(1){ com_readline(readfile, inbuff, &lineNUM, &EOFflg); + if(EOFflg) { + break; + } if(strstr(inbuff, INC_START_MARK) != NULL || strstr(inbuff, INC__END__MARK) != NULL){ continue; @@ -2026,8 +2023,13 @@ void ppoutput_incfile(char *ppin,char *ppout,struct cb_exec_list *head){ EOFFLG = 0; if (readfile && outfile){ - for(;EOFflg != 1;){ + int after_first_read = 0; + while(EOFflg != 1){ + if(after_first_read) { + fwrite (outbuff ,len, 1 , outfile); + } com_readline(readfile, inbuff, &lineNUM, &EOFflg); + after_first_read = 1; if(head){ if (l->startLine<= lineNUM && l->endLine>=lineNUM){ if (strcmp(l->commandName, "INCFILE") == 0){ @@ -2042,7 +2044,6 @@ void ppoutput_incfile(char *ppin,char *ppout,struct cb_exec_list *head){ outbuff = inbuff; len = strlen(outbuff); - fwrite (outbuff ,len, 1 , outfile ); if (EOFflg == 1){ fputc('\n',outfile); @@ -2051,7 +2052,9 @@ void ppoutput_incfile(char *ppin,char *ppout,struct cb_exec_list *head){ else{ if(lineNUM - l->endLine == 1){ if(strcmp(l->commandName,"INCFILE")==0){ + fprintf(outfile, "ocesql* start_include period=%s\n", l->period ? "true" : "false"); ppbuff_incfile(l); + fprintf(outfile, "ocesql* end_include\n"); } if (l->next != NULL) l = l->next; @@ -2068,18 +2071,14 @@ void ppoutput_incfile(char *ppin,char *ppout,struct cb_exec_list *head){ } outbuff = inbuff; len = strlen(outbuff); - fwrite (outbuff ,len, 1 , outfile ); }else{ outbuff = inbuff; len = strlen(outbuff); - fwrite (outbuff ,len, 1 , outfile ); - } } }else{ outbuff = inbuff; len = strlen(outbuff); - fwrite (outbuff ,len, 1 , outfile); } } } diff --git a/ocesql/scanner.c b/ocesql/scanner.c index c2b5413..c1efa41 100644 --- a/ocesql/scanner.c +++ b/ocesql/scanner.c @@ -2235,6 +2235,7 @@ int hostlineno = 0; int includelinenum = 0; int includeflag = 0; int period = 0; +int config_period = PERIOD_DEFAULT; int conn_use_other_db = 0; int command_putother = 0; struct cb_exec_list *exec_list = NULL; @@ -2263,7 +2264,7 @@ yyinput (char *buf, int max_size); -#line 2267 "scanner.c" +#line 2268 "scanner.c" #define INITIAL 0 #define PICTURE_STATE 1 @@ -2499,11 +2500,11 @@ YY_DECL } { -#line 92 "scanner.l" +#line 93 "scanner.l" -#line 2507 "scanner.c" +#line 2508 "scanner.c" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -2568,7 +2569,7 @@ YY_DECL case 1: YY_RULE_SETUP -#line 95 "scanner.l" +#line 96 "scanner.l" { BEGIN ESQL_FUNC_STATE; @@ -2593,7 +2594,7 @@ YY_RULE_SETUP case 2: YY_RULE_SETUP -#line 117 "scanner.l" +#line 118 "scanner.l" { BEGIN ESQL_STATE; flag_insqlstring = 1; @@ -2612,7 +2613,7 @@ YY_RULE_SETUP YY_BREAK case 3: YY_RULE_SETUP -#line 133 "scanner.l" +#line 134 "scanner.l" { BEGIN ESQL_STATE; flag_insqlstring = 1; @@ -2630,7 +2631,7 @@ YY_RULE_SETUP YY_BREAK case 4: YY_RULE_SETUP -#line 148 "scanner.l" +#line 149 "scanner.l" { BEGIN ESQL_STATE; flag_insqlstring = 1; @@ -2648,7 +2649,7 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 163 "scanner.l" +#line 164 "scanner.l" { BEGIN ESQL_STATE; @@ -2658,7 +2659,7 @@ YY_RULE_SETUP YY_BREAK case 6: YY_RULE_SETUP -#line 170 "scanner.l" +#line 171 "scanner.l" { BEGIN ESQL_STATE; flag_insqlstring = 1; @@ -2676,7 +2677,7 @@ YY_RULE_SETUP YY_BREAK case 7: YY_RULE_SETUP -#line 185 "scanner.l" +#line 186 "scanner.l" { BEGIN ESQL_STATE; flag_insqlstring = 1; @@ -2694,7 +2695,7 @@ YY_RULE_SETUP YY_BREAK case 8: YY_RULE_SETUP -#line 200 "scanner.l" +#line 201 "scanner.l" { BEGIN ESQL_STATE; @@ -2703,7 +2704,7 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 206 "scanner.l" +#line 207 "scanner.l" { BEGIN ESQL_STATE; @@ -2713,7 +2714,7 @@ YY_RULE_SETUP YY_BREAK case 10: YY_RULE_SETUP -#line 213 "scanner.l" +#line 214 "scanner.l" { BEGIN ESQL_STATE; @@ -2723,7 +2724,7 @@ YY_RULE_SETUP YY_BREAK case 11: YY_RULE_SETUP -#line 220 "scanner.l" +#line 221 "scanner.l" { BEGIN ESQL_STATE; @@ -2733,7 +2734,7 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 227 "scanner.l" +#line 228 "scanner.l" { BEGIN ESQL_STATE; @@ -2743,7 +2744,7 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 234 "scanner.l" +#line 235 "scanner.l" { BEGIN ESQL_STATE; @@ -2753,7 +2754,7 @@ YY_RULE_SETUP YY_BREAK case 14: YY_RULE_SETUP -#line 241 "scanner.l" +#line 242 "scanner.l" { BEGIN ESQL_STATE; @@ -2763,7 +2764,7 @@ YY_RULE_SETUP YY_BREAK case 15: YY_RULE_SETUP -#line 248 "scanner.l" +#line 249 "scanner.l" { BEGIN ESQL_STATE; @@ -2773,7 +2774,7 @@ YY_RULE_SETUP YY_BREAK case 16: YY_RULE_SETUP -#line 255 "scanner.l" +#line 256 "scanner.l" { BEGIN ESQL_STATE; @@ -2783,7 +2784,7 @@ YY_RULE_SETUP YY_BREAK case 17: YY_RULE_SETUP -#line 262 "scanner.l" +#line 263 "scanner.l" { BEGIN ESQL_STATE; @@ -2793,7 +2794,7 @@ YY_RULE_SETUP YY_BREAK case 18: YY_RULE_SETUP -#line 269 "scanner.l" +#line 270 "scanner.l" { BEGIN ESQL_STATE; @@ -2803,7 +2804,7 @@ YY_RULE_SETUP YY_BREAK case 19: YY_RULE_SETUP -#line 276 "scanner.l" +#line 277 "scanner.l" { BEGIN ESQL_STATE; @@ -2813,7 +2814,7 @@ YY_RULE_SETUP YY_BREAK case 20: YY_RULE_SETUP -#line 283 "scanner.l" +#line 284 "scanner.l" { BEGIN ESQL_STATE; @@ -2823,7 +2824,7 @@ YY_RULE_SETUP YY_BREAK case 21: YY_RULE_SETUP -#line 290 "scanner.l" +#line 291 "scanner.l" { BEGIN ESQL_STATE; @@ -2833,7 +2834,7 @@ YY_RULE_SETUP YY_BREAK case 22: YY_RULE_SETUP -#line 297 "scanner.l" +#line 298 "scanner.l" { if(flag_insqlstring || conn_use_other_db){ yylval.s = com_strdup (yytext); @@ -2847,7 +2848,7 @@ YY_RULE_SETUP YY_BREAK case 23: YY_RULE_SETUP -#line 308 "scanner.l" +#line 309 "scanner.l" { BEGIN ESQL_STATE; yylval.s = com_strdup (yytext); @@ -2866,7 +2867,7 @@ YY_RULE_SETUP case 24: YY_RULE_SETUP -#line 324 "scanner.l" +#line 325 "scanner.l" { yylval.s = com_strdup (yytext + 1); hostlineno = yylineno - includelinenum; @@ -2879,7 +2880,7 @@ YY_RULE_SETUP case 25: YY_RULE_SETUP -#line 334 "scanner.l" +#line 335 "scanner.l" { yylval.s = com_strdup (yytext); return TOKEN; @@ -2888,20 +2889,20 @@ YY_RULE_SETUP case 26: /* rule 26 can match eol */ YY_RULE_SETUP -#line 338 "scanner.l" +#line 339 "scanner.l" { } YY_BREAK case 27: /* rule 27 can match eol */ YY_RULE_SETUP -#line 342 "scanner.l" +#line 343 "scanner.l" { ECHO; } YY_BREAK case 28: YY_RULE_SETUP -#line 345 "scanner.l" +#line 346 "scanner.l" { if(flag_insqlstring || conn_use_other_db){ yylval.s = com_strdup (yytext); @@ -2915,7 +2916,7 @@ YY_RULE_SETUP YY_BREAK case 29: YY_RULE_SETUP -#line 356 "scanner.l" +#line 357 "scanner.l" { if(flag_insqlstring){ yylval.s = com_strdup (yytext); @@ -2935,7 +2936,7 @@ YY_RULE_SETUP YY_BREAK case 30: YY_RULE_SETUP -#line 373 "scanner.l" +#line 374 "scanner.l" { if(flag_insqlstring){ yylval.s = com_strdup (yytext); @@ -2951,7 +2952,7 @@ YY_RULE_SETUP YY_BREAK case 31: YY_RULE_SETUP -#line 386 "scanner.l" +#line 387 "scanner.l" { if(flag_insqlstring){ yylval.s = com_strdup (yytext); @@ -2962,7 +2963,7 @@ YY_RULE_SETUP YY_BREAK case 32: YY_RULE_SETUP -#line 394 "scanner.l" +#line 395 "scanner.l" { if(flag_insqlstring){ yylval.s = com_strdup (yytext); @@ -2973,7 +2974,7 @@ YY_RULE_SETUP YY_BREAK case 33: YY_RULE_SETUP -#line 402 "scanner.l" +#line 403 "scanner.l" { if(flag_insqlstring){ yylval.s = com_strdup (yytext); @@ -2984,7 +2985,7 @@ YY_RULE_SETUP YY_BREAK case 34: YY_RULE_SETUP -#line 410 "scanner.l" +#line 411 "scanner.l" { if(flag_insqlstring){ yylval.s = com_strdup (yytext); @@ -2995,7 +2996,7 @@ YY_RULE_SETUP YY_BREAK case 35: YY_RULE_SETUP -#line 418 "scanner.l" +#line 419 "scanner.l" { if(flag_insqlstring && !flag_selectcommand){ yylval.s = com_strdup (yytext); @@ -3008,7 +3009,7 @@ YY_RULE_SETUP case 36: /* rule 36 can match eol */ YY_RULE_SETUP -#line 427 "scanner.l" +#line 428 "scanner.l" { yy_push_state(WHERE_CURRENT_OF); return WHERECURRENTOF; @@ -3016,7 +3017,7 @@ YY_RULE_SETUP YY_BREAK case 37: YY_RULE_SETUP -#line 432 "scanner.l" +#line 433 "scanner.l" { yylval.s = com_strdup (yytext); return TOKEN; @@ -3024,7 +3025,7 @@ YY_RULE_SETUP YY_BREAK case 38: YY_RULE_SETUP -#line 437 "scanner.l" +#line 438 "scanner.l" { yylval.s = com_strdup (yytext + 1); hostlineno = yylineno - includelinenum; @@ -3035,7 +3036,7 @@ YY_RULE_SETUP case 39: /* rule 39 can match eol */ YY_RULE_SETUP -#line 444 "scanner.l" +#line 445 "scanner.l" { flag_insqlstring = 0; flag_selectcommand = 0; @@ -3047,7 +3048,7 @@ YY_RULE_SETUP YY_BREAK case 40: YY_RULE_SETUP -#line 453 "scanner.l" +#line 454 "scanner.l" { flag_insqlstring = 0; flag_selectcommand = 0; @@ -3058,7 +3059,7 @@ YY_RULE_SETUP YY_BREAK case 41: YY_RULE_SETUP -#line 461 "scanner.l" +#line 462 "scanner.l" { yylval.s = com_strdup (yytext); return TOKEN; @@ -3066,7 +3067,7 @@ YY_RULE_SETUP YY_BREAK case 42: YY_RULE_SETUP -#line 466 "scanner.l" +#line 467 "scanner.l" { yylval.s = com_strdup (yytext); return TOKEN; @@ -3074,7 +3075,7 @@ YY_RULE_SETUP YY_BREAK case 43: YY_RULE_SETUP -#line 471 "scanner.l" +#line 472 "scanner.l" { yylval.s = com_strdup (yytext); return TOKEN; @@ -3085,12 +3086,12 @@ YY_RULE_SETUP case 44: /* rule 44 can match eol */ YY_RULE_SETUP -#line 478 "scanner.l" +#line 479 "scanner.l" { } YY_BREAK case 45: YY_RULE_SETUP -#line 480 "scanner.l" +#line 481 "scanner.l" { yylval.s = com_strdup (yytext); yy_pop_state(); @@ -3100,7 +3101,7 @@ YY_RULE_SETUP case 46: YY_RULE_SETUP -#line 487 "scanner.l" +#line 488 "scanner.l" { period = 0; startlineno = yylineno; @@ -3124,12 +3125,12 @@ YY_RULE_SETUP case 47: /* rule 47 can match eol */ YY_RULE_SETUP -#line 506 "scanner.l" +#line 507 "scanner.l" { } YY_BREAK case 48: YY_RULE_SETUP -#line 507 "scanner.l" +#line 508 "scanner.l" { memset(commandname,0,sizeof(commandname)); com_strcpy(commandname,sizeof(commandname),"INCLUDE"); @@ -3138,7 +3139,7 @@ YY_RULE_SETUP YY_BREAK case 49: YY_RULE_SETUP -#line 512 "scanner.l" +#line 513 "scanner.l" { endlineno = yylineno; yy_pop_state(); @@ -3147,7 +3148,7 @@ YY_RULE_SETUP YY_BREAK case 50: YY_RULE_SETUP -#line 517 "scanner.l" +#line 518 "scanner.l" { memset(commandname,0,sizeof(commandname)); com_strcpy(commandname,sizeof(commandname),"INCFILE"); @@ -3159,7 +3160,7 @@ YY_RULE_SETUP case 51: /* rule 51 can match eol */ YY_RULE_SETUP -#line 524 "scanner.l" +#line 525 "scanner.l" { period = 1; endlineno = yylineno; @@ -3170,7 +3171,7 @@ YY_RULE_SETUP case 52: YY_RULE_SETUP -#line 532 "scanner.l" +#line 533 "scanner.l" { BEGIN WORKING_STATE; startlineno = yylineno; @@ -3196,7 +3197,7 @@ YY_RULE_SETUP case 53: YY_RULE_SETUP -#line 555 "scanner.l" +#line 556 "scanner.l" { startlineno = yylineno; endlineno = yylineno; @@ -3220,7 +3221,7 @@ YY_RULE_SETUP YY_BREAK case 54: YY_RULE_SETUP -#line 575 "scanner.l" +#line 576 "scanner.l" { startlineno = yylineno; endlineno = yylineno; @@ -3245,49 +3246,49 @@ YY_RULE_SETUP case 55: /* rule 55 can match eol */ YY_RULE_SETUP -#line 596 "scanner.l" +#line 597 "scanner.l" {} YY_BREAK case 56: /* rule 56 can match eol */ YY_RULE_SETUP -#line 597 "scanner.l" +#line 598 "scanner.l" {} YY_BREAK case 57: /* rule 57 can match eol */ YY_RULE_SETUP -#line 598 "scanner.l" +#line 599 "scanner.l" {} YY_BREAK case 58: /* rule 58 can match eol */ YY_RULE_SETUP -#line 599 "scanner.l" +#line 600 "scanner.l" {} YY_BREAK case 59: /* rule 59 can match eol */ YY_RULE_SETUP -#line 601 "scanner.l" +#line 602 "scanner.l" {} YY_BREAK case 60: -#line 604 "scanner.l" -case 61: #line 605 "scanner.l" -case 62: +case 61: #line 606 "scanner.l" -case 63: +case 62: #line 607 "scanner.l" -case 64: +case 63: #line 608 "scanner.l" -case 65: +case 64: #line 609 "scanner.l" +case 65: +#line 610 "scanner.l" case 66: /* rule 66 can match eol */ YY_RULE_SETUP -#line 609 "scanner.l" +#line 610 "scanner.l" { startlineno = yylineno; endlineno = yylineno; @@ -3311,17 +3312,17 @@ YY_RULE_SETUP } YY_BREAK case 67: -#line 631 "scanner.l" +#line 632 "scanner.l" case 68: YY_RULE_SETUP -#line 631 "scanner.l" +#line 632 "scanner.l" { BEGIN PICTURE_STATE; } YY_BREAK case 69: YY_RULE_SETUP -#line 635 "scanner.l" +#line 636 "scanner.l" { yylval.ld = atol(yytext); return NUMERIC; @@ -3329,78 +3330,78 @@ YY_RULE_SETUP YY_BREAK case 70: YY_RULE_SETUP -#line 640 "scanner.l" +#line 641 "scanner.l" {return OCCURS;} YY_BREAK case 71: YY_RULE_SETUP -#line 641 "scanner.l" +#line 642 "scanner.l" {return USAGE;} YY_BREAK case 72: YY_RULE_SETUP -#line 642 "scanner.l" +#line 643 "scanner.l" { return COMP_1; } YY_BREAK case 73: YY_RULE_SETUP -#line 645 "scanner.l" +#line 646 "scanner.l" { return COMP_2; } YY_BREAK case 74: YY_RULE_SETUP -#line 648 "scanner.l" +#line 649 "scanner.l" { return COMP_3; } YY_BREAK case 75: YY_RULE_SETUP -#line 652 "scanner.l" +#line 653 "scanner.l" { return SIGN ;} YY_BREAK case 76: YY_RULE_SETUP -#line 653 "scanner.l" +#line 654 "scanner.l" { return LEADING;} YY_BREAK case 77: YY_RULE_SETUP -#line 654 "scanner.l" +#line 655 "scanner.l" { return SEPARATE; } YY_BREAK case 78: YY_RULE_SETUP -#line 655 "scanner.l" +#line 656 "scanner.l" { return TRAILING; } YY_BREAK case 79: YY_RULE_SETUP -#line 656 "scanner.l" +#line 657 "scanner.l" { return EXTERNAL;} YY_BREAK case 80: YY_RULE_SETUP -#line 657 "scanner.l" +#line 658 "scanner.l" { return IS;} YY_BREAK case 81: YY_RULE_SETUP -#line 658 "scanner.l" +#line 659 "scanner.l" { return ARE;} YY_BREAK case 82: YY_RULE_SETUP -#line 659 "scanner.l" +#line 660 "scanner.l" { return VALUE;} YY_BREAK case 83: YY_RULE_SETUP -#line 660 "scanner.l" +#line 661 "scanner.l" { startlineno = yylineno; endlineno = yylineno; @@ -3424,23 +3425,23 @@ YY_RULE_SETUP YY_BREAK case 84: YY_RULE_SETUP -#line 680 "scanner.l" +#line 681 "scanner.l" { return TIMES;} YY_BREAK case 85: YY_RULE_SETUP -#line 681 "scanner.l" +#line 682 "scanner.l" { return ALL ;} YY_BREAK case 86: /* rule 86 can match eol */ YY_RULE_SETUP -#line 682 "scanner.l" +#line 683 "scanner.l" { return CONST;} YY_BREAK case 87: YY_RULE_SETUP -#line 683 "scanner.l" +#line 684 "scanner.l" { yylval.s = com_strdup(yytext); return WORD; @@ -3448,32 +3449,32 @@ YY_RULE_SETUP YY_BREAK case 88: YY_RULE_SETUP -#line 687 "scanner.l" +#line 688 "scanner.l" { return '.';} YY_BREAK case 89: /* rule 89 can match eol */ YY_RULE_SETUP -#line 688 "scanner.l" +#line 689 "scanner.l" { } YY_BREAK case 90: YY_RULE_SETUP -#line 690 "scanner.l" +#line 691 "scanner.l" {} YY_BREAK case 91: YY_RULE_SETUP -#line 695 "scanner.l" +#line 696 "scanner.l" { /* ignore */ } YY_BREAK case 92: YY_RULE_SETUP -#line 698 "scanner.l" +#line 699 "scanner.l" { yylval.s = com_strdup(yytext); @@ -3485,20 +3486,20 @@ YY_RULE_SETUP case 93: /* rule 93 can match eol */ YY_RULE_SETUP -#line 707 "scanner.l" +#line 708 "scanner.l" { } YY_BREAK case 94: /* rule 94 can match eol */ YY_RULE_SETUP -#line 709 "scanner.l" +#line 710 "scanner.l" { } YY_BREAK case 95: YY_RULE_SETUP -#line 714 "scanner.l" +#line 715 "scanner.l" { //Ignore @@ -3506,7 +3507,7 @@ YY_RULE_SETUP YY_BREAK case 96: YY_RULE_SETUP -#line 719 "scanner.l" +#line 720 "scanner.l" {} YY_BREAK case YY_STATE_EOF(INITIAL): @@ -3518,7 +3519,7 @@ case YY_STATE_EOF(ESQL_SELECT_STATE): case YY_STATE_EOF(ESQL_STATE): case YY_STATE_EOF(ESQL_DBNAME_STATE): case YY_STATE_EOF(WHERE_CURRENT_OF): -#line 722 "scanner.l" +#line 723 "scanner.l" { yyterminate (); @@ -3526,10 +3527,10 @@ case YY_STATE_EOF(WHERE_CURRENT_OF): YY_BREAK case 97: YY_RULE_SETUP -#line 727 "scanner.l" +#line 728 "scanner.l" ECHO; YY_BREAK -#line 3533 "scanner.c" +#line 3534 "scanner.c" case YY_END_OF_BUFFER: { @@ -4586,9 +4587,29 @@ void yyfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 727 "scanner.l" - - +#line 728 "scanner.l" + + + +int parse_include_config(char* inbuff) { + if(strstr(inbuff, "ocesql* start_include period=true")) { + includeflag = 1; + includelinenum++; + config_period = PERIOD_FORCE_ON; + return 1; + } else if(strstr(inbuff, "ocesql* start_include period=false")) { + includeflag = 1; + includelinenum++; + config_period = PERIOD_FORCE_OFF; + return 1; + } else if(strstr(inbuff, "ocesql* end_include")) { + includeflag = 0; + config_period = PERIOD_DEFAULT; + return 1; + } else { + return 0; + } +} static int yyinput(char *buff,int max_size) @@ -4606,7 +4627,7 @@ yyinput(char *buff,int max_size) includelinenum++; /* ignore line */ com_strcpy(buff,max_size,"\n"); - return strlen(buff); + return strlen(buff); } if(includeflag){ includelinenum++; @@ -4615,10 +4636,13 @@ yyinput(char *buff,int max_size) includeflag = 0; /* ignore line */ com_strcpy(buff,max_size,"\n"); - return strlen(buff); + return strlen(buff); + } + if(parse_include_config(buff)) { + /* ignore line */ + com_strcpy(buff,max_size,"\n"); + return strlen(buff); } - - bp = buff + 7; diff --git a/ocesql/scanner.l b/ocesql/scanner.l index d5be5f7..d8b400d 100644 --- a/ocesql/scanner.l +++ b/ocesql/scanner.l @@ -41,6 +41,7 @@ int hostlineno = 0; int includelinenum = 0; int includeflag = 0; int period = 0; +int config_period = PERIOD_DEFAULT; int conn_use_other_db = 0; int command_putother = 0; struct cb_exec_list *exec_list = NULL; @@ -726,6 +727,26 @@ INT_CONSTANT {digit}+ %% +int parse_include_config(char* inbuff) { + if(strstr(inbuff, "ocesql* start_include period=true")) { + includeflag = 1; + includelinenum++; + config_period = PERIOD_FORCE_ON; + return 1; + } else if(strstr(inbuff, "ocesql* start_include period=false")) { + includeflag = 1; + includelinenum++; + config_period = PERIOD_FORCE_OFF; + return 1; + } else if(strstr(inbuff, "ocesql* end_include")) { + includeflag = 0; + config_period = PERIOD_DEFAULT; + return 1; + } else { + return 0; + } +} + static int yyinput(char *buff,int max_size) { @@ -742,7 +763,7 @@ yyinput(char *buff,int max_size) includelinenum++; /* ignore line */ com_strcpy(buff,max_size,"\n"); - return strlen(buff); + return strlen(buff); } if(includeflag){ includelinenum++; @@ -751,10 +772,13 @@ yyinput(char *buff,int max_size) includeflag = 0; /* ignore line */ com_strcpy(buff,max_size,"\n"); - return strlen(buff); + return strlen(buff); + } + if(parse_include_config(buff)) { + /* ignore line */ + com_strcpy(buff,max_size,"\n"); + return strlen(buff); } - - bp = buff + 7; diff --git a/tests/Makefile.am b/tests/Makefile.am index 7fa944a..51cc9d1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -34,7 +34,8 @@ sqlca_DEPENDENCIES = \ sqlca.src/prepare-execute.at misc_DEPENDENCIES = \ - misc.src/long-sql.at + misc.src/long-sql.at \ + misc.src/include.at EXTRA_DIST = $(srcdir)/package.m4 \ $(TESTS) \ diff --git a/tests/Makefile.in b/tests/Makefile.in index eb38488..d86f366 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -485,7 +485,8 @@ sqlca_DEPENDENCIES = \ sqlca.src/prepare-execute.at misc_DEPENDENCIES = \ - misc.src/long-sql.at + misc.src/long-sql.at \ + misc.src/include.at EXTRA_DIST = $(srcdir)/package.m4 \ $(TESTS) \ diff --git a/tests/basic.src/declare-bind-var.at b/tests/basic.src/declare-bind-var.at index bfe35fc..d9a6845 100644 --- a/tests/basic.src/declare-bind-var.at +++ b/tests/basic.src/declare-bind-var.at @@ -338,7 +338,7 @@ AT_DATA([prog.cbl], [ AT_CHECK([ocesql prog.cbl prog.cob > /dev/null]) AT_CHECK([${EMBED_DB_INFO} prog.cob]) -AT_CHECK([cobj -I ../../ prog.cob]) +AT_CHECK([${COMPILE} -I ../../ prog.cob]) AT_CHECK([java prog], [0], [0005 MIYAGI GORO -200 0006 FUKUSHIMA RIKURO 150 diff --git a/tests/misc.at b/tests/misc.at index 6aa6e48..003b553 100644 --- a/tests/misc.at +++ b/tests/misc.at @@ -1,5 +1,6 @@ -AT_INIT(basic test) +AT_INIT(misc) AT_TESTED([ocesql]) m4_include([long-sql.at]) +m4_include([include.at]) diff --git a/tests/misc.src/include.at b/tests/misc.src/include.at new file mode 100644 index 0000000..583b9ad --- /dev/null +++ b/tests/misc.src/include.at @@ -0,0 +1,219 @@ +AT_SETUP([include]) + +AT_DATA([TEST-DATA], [ + 01 TEST-DATA. + 03 FILLER PIC X(28) VALUE "0001北海 太郎 0400". + 03 FILLER PIC X(28) VALUE "0002青森 次郎 0350". + 03 FILLER PIC X(28) VALUE "0003秋田 三郎 0300". + 03 FILLER PIC X(28) VALUE "0004岩手 四郎 025p". + 03 FILLER PIC X(28) VALUE "0005宮城 五郎 020p". + 03 FILLER PIC X(28) VALUE "0006福島 六郎 0150". + 03 FILLER PIC X(28) VALUE "0007栃木 七郎 010p". + 03 FILLER PIC X(28) VALUE "0008茨城 八郎 0050". + 03 FILLER PIC X(28) VALUE "0009群馬 九郎 020p". + 03 FILLER PIC X(28) VALUE "0010埼玉 十郎 0350". +]) + +AT_DATA([TEST-DATA-R], [ + 01 TEST-DATA-R REDEFINES TEST-DATA. + 03 TEST-TBL OCCURS 10. + 05 TEST-NO PIC S9(04). + 05 TEST-NAME PIC X(20). + 05 TEST-SALARY PIC S9(04). +]) + +AT_DATA([DECLARE-SECTION], [ + 01 DBNAME PIC X(30) VALUE SPACE. + 01 USERNAME PIC X(30) VALUE SPACE. + 01 PASSWD PIC X(10) VALUE SPACE. + 01 EMP-REC-VARS. + 03 EMP-NO PIC S9(04) VALUE ZERO. + 03 EMP-NAME PIC X(20) . + 03 EMP-SALARY PIC S9(04) VALUE ZERO. +]) + +AT_DATA([EXEC-SELECT], [ + EXEC SQL + SELECT * INTO :READ-TBL FROM EMP WHERE EMP_NO > 4 + END-EXEC. +]) + +AT_DATA([exec-create-table], [ + EXEC SQL + CREATE TABLE EMP + ( + EMP_NO NUMERIC(4,0) NOT NULL, + EMP_NAME CHAR(20), + EMP_SALARY NUMERIC(4,0), + CONSTRAINT IEMP_0 PRIMARY KEY (EMP_NO) + ) + END-EXEC. +]) + +AT_DATA([exec-connect], [ + EXEC SQL + CONNECT :USERNAME IDENTIFIED BY :PASSWD USING :DBNAME + END-EXEC. +]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + ****************************************************************** + PROGRAM-ID. prog. + ****************************************************************** + DATA DIVISION. + ****************************************************************** + WORKING-STORAGE SECTION. + + EXEC SQL INCLUDE TEST-DATA END-EXEC. + + EXEC SQL INCLUDE TEST-DATA-R END-EXEC. + + 01 IDX PIC 9(02). + 01 LOG-COUNT PIC 9999 VALUE 1. + + 01 READ-DATA. + 03 READ-TBL OCCURS 10. + 05 READ-NO PIC S9(04). + 05 READ-NAME PIC X(20) . + 05 READ-SALARY PIC S9(04). + + EXEC SQL BEGIN DECLARE SECTION END-EXEC. + EXEC SQL INCLUDE DECLARE-SECTION END-EXEC. + EXEC SQL END DECLARE SECTION END-EXEC. + + EXEC SQL INCLUDE SQLCA END-EXEC. + ****************************************************************** + PROCEDURE DIVISION. + ****************************************************************** + MAIN-RTN. + + PERFORM SETUP-DB. + + * SHOW RESULT + + EXEC SQL INCLUDE EXEC-SELECT END-EXEC. + + PERFORM OUTPUT-RETURN-CODE-TEST. + + MOVE 1 TO IDX. + PERFORM UNTIL IDX > 6 + DISPLAY READ-NO(IDX) ", " + READ-NAME(IDX) ", " + READ-SALARY(IDX) + ADD 1 TO IDX + END-PERFORM. + + PERFORM CLEANUP-DB. + + * END + STOP RUN. + + ****************************************************************** + SETUP-DB. + ****************************************************************** + + * SERVER + MOVE "<|DB_NAME|>@<|DB_HOST|>:<|DB_PORT|>" + TO DBNAME. + MOVE "<|DB_USER|>" + TO USERNAME. + MOVE "<|DB_PASSWORD|>" + TO PASSWD. + + EXEC SQL INCLUDE exec-connect END-EXEC. + + IF 1 < 0 + EXEC SQL INCLUDE exec-connect END-EXEC + END-IF. + + EXEC SQL + DROP TABLE IF EXISTS EMP + END-EXEC. + + EXEC SQL INCLUDE + exec-create-table + END-EXEC. + + * INSERT ROWS USING HOST VARIABLE + PERFORM VARYING IDX FROM 1 BY 1 UNTIL IDX > 10 + MOVE TEST-NO(IDX) TO EMP-NO + MOVE TEST-NAME(IDX) TO EMP-NAME + MOVE TEST-SALARY(IDX) TO EMP-SALARY + EXEC SQL + INSERT INTO EMP VALUES + (:EMP-NO,:EMP-NAME,:EMP-SALARY) + END-EXEC + END-PERFORM. + + * COMMIT + EXEC SQL + COMMIT WORK + END-EXEC. + + ****************************************************************** + CLEANUP-DB. + ****************************************************************** + EXEC SQL + CLOSE C1 + END-EXEC. + + EXEC SQL + DROP TABLE IF EXISTS EMP + END-EXEC. + + EXEC SQL + DISCONNECT ALL + END-EXEC. + + ****************************************************************** + OUTPUT-RETURN-CODE-TEST. + ****************************************************************** + IF SQLCODE = ZERO + THEN + + DISPLAY LOG-COUNT " success test_return_code" + + ELSE + DISPLAY LOG-COUNT " fail test_return_code " + NO ADVANCING + DISPLAY "SQLCODE=" SQLCODE " ERRCODE=" SQLSTATE " " + NO ADVANCING + EVALUATE SQLCODE + WHEN +10 + DISPLAY "Record_not_found" + WHEN -01 + DISPLAY "Connection_falied" + WHEN -20 + DISPLAY "Internal_error" + WHEN -30 + DISPLAY "PostgreSQL_error" NO ADVANCING + DISPLAY SQLERRMC + *> TO RESTART TRANSACTION, DO ROLLBACK. + EXEC SQL + ROLLBACK + END-EXEC + WHEN OTHER + DISPLAY "Undefined_error" NO ADVANCING + DISPLAY SQLERRMC + END-EVALUATE. + + ADD 1 TO LOG-COUNT. + ****************************************************************** + + +]) +AT_CHECK([ocesql prog.cbl prog.cob | tee out.txt > /dev/null]) +AT_CHECK([${EMBED_DB_INFO} prog.cob]) +AT_CHECK([${COMPILE_MODULE} prog.cob]) +AT_CHECK([${RUN_MODULE} prog], [0], +[0001 success test_return_code ++0005, 宮城 五郎 , -0200 ++0006, 福島 六郎 , +0150 ++0007, 栃木 七郎 , -0100 ++0008, 茨城 八郎 , +0050 ++0009, 群馬 九郎 , -0200 ++0010, 埼玉 十郎 , +0350 +]) + +AT_CLEANUP diff --git a/tests/misc.src/long-sql.at b/tests/misc.src/long-sql.at index 7e30bfc..cea56c9 100644 --- a/tests/misc.src/long-sql.at +++ b/tests/misc.src/long-sql.at @@ -1,4 +1,4 @@ -AT_SETUP([select statement test]) +AT_SETUP([long sql]) AT_DATA([prog.cbl], [ IDENTIFICATION DIVISION.