From: Michael Meskes Date: Wed, 8 Feb 2006 09:10:05 +0000 (+0000) Subject: Added just another test case. X-Git-Tag: REL8_2_BETA1~1484 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e3740d2c59915b6fd78b2b8aaf63b290a14423c6;p=postgresql Added just another test case. Fixed missing continuation line character. Do not translate $-quoting. Bit field notation belongs to a variable not a variable list. Output of line number only done by one function. --- diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index 6f447bc979..0bc5d78fa7 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -1982,6 +1982,17 @@ Sa Feb 4 21:35:03 CET 2006 - Added C bit fields to ecpg parser. - Added some default rules to lexer. - Added log output to prepare statement. + +Mo Feb 6 21:21:19 CET 2006 + + - Added just another test case. + - Fixed missing continuation line character. + - Do not translate $-quoting. + +Tu Feb 7 18:48:14 CET 2006 + + - Bit field notation belongs to a variable not a variable list. + - Output of line number only done by one function. - Set ecpg library version to 5.2. - Set ecpg version to 4.2.1. diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 41625fa758..c06075ad5f 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.93 2005/10/15 02:49:47 momjian Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.94 2006/02/08 09:10:04 meskes Exp $ */ /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */ /* (C) Michael Meskes Feb 5th, 1998 */ @@ -418,7 +418,7 @@ main(int argc, char *const argv[]) fprintf(yyout, "/* End of automatic include section */\n"); } - fprintf(yyout, "#line 1 \"%s\"\n", input_filename); + output_line_number(); /* and parse the source */ yyparse(); diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c index 2af7fdcaeb..8e434e18f3 100644 --- a/src/interfaces/ecpg/preproc/output.c +++ b/src/interfaces/ecpg/preproc/output.c @@ -2,19 +2,22 @@ #include "extern.h" -static void ouput_escaped_str(char *cmd); +static void output_escaped_str(char *cmd); void output_line_number(void) { - if (input_filename) - fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename); + char *line = hashline_number(); + + /* output_escaped_str(line); */ + fprintf(yyout, "%s", line); + free(line); } void output_simple_statement(char *stmt) { - ouput_escaped_str(stmt); + output_escaped_str(stmt); output_line_number(); free(stmt); } @@ -83,7 +86,8 @@ whenever_action(int mode) char * hashline_number(void) { - if (input_filename) + /* do not print line numbers if we are in debug mode */ + if (input_filename && !yydebug) { char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename)); @@ -99,7 +103,7 @@ void output_statement(char *stmt, int mode, char *con) { fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, \"", compat, force_indicator, con ? con : "NULL"); - ouput_escaped_str(stmt); + output_escaped_str(stmt); fputs("\", ", yyout); /* dump variables to C file */ @@ -118,7 +122,7 @@ output_statement(char *stmt, int mode, char *con) static void -ouput_escaped_str(char *str) +output_escaped_str(char *str) { int i, len = strlen(str); @@ -128,7 +132,8 @@ ouput_escaped_str(char *str) if (str[i] == '"') fputs("\\\"", yyout); else if (str[i] == '\n') - fputs("\\n\\\n", yyout); + //fputs("\\n\\\n", yyout); + fputs("\\\n", yyout); else fputc(str[i], yyout); } diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l index d89bbad978..223e108e26 100644 --- a/src/interfaces/ecpg/preproc/pgc.l +++ b/src/interfaces/ecpg/preproc/pgc.l @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.142 2006/02/04 20:54:42 meskes Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.143 2006/02/08 09:10:04 meskes Exp $ * *------------------------------------------------------------------------- */ @@ -152,7 +152,7 @@ dolq_start [A-Za-z\200-\377_] dolq_cont [A-Za-z\200-\377_0-9] dolqdelim \$({dolq_start}{dolq_cont}*)?\$ dolqfailed \${dolq_start}{dolq_cont}* -dolqinside [^$']+ +dolqinside [^$]+ /* Double quote * Allows embedded spaces and other special characters into identifiers. @@ -437,7 +437,7 @@ cppline {space}*#(.*\\{space})*.*{newline} addlit(yytext, yyleng); } {quotecontinue} { /* ignore */ } -. { +{other} { /* This is only needed for \ just before EOF */ addlitchar(yytext[0]); } @@ -453,14 +453,16 @@ cppline {space}*#(.*\\{space})*.*{newline} dolqstart = mm_strdup(yytext); BEGIN(xdolq); startlit(); + addlit(yytext, yyleng); } {dolqdelim} { if (strcmp(yytext, dolqstart) == 0) { + addlit(yytext, yyleng); free(dolqstart); BEGIN(SQL); yylval.str = mm_strdup(literalbuf); - return SCONST; + return DOLCONST; } else { @@ -475,15 +477,11 @@ cppline {space}*#(.*\\{space})*.*{newline} } {dolqinside} { addlit(yytext, yyleng); } {dolqfailed} { addlit(yytext, yyleng); } -. { - /* $$ is implemented as a single-quoted string, so double it? */ - if (yytext[0] == '\'') - addlitchar(yytext[0]); +{other} { /* single quote or dollar sign */ addlitchar(yytext[0]); } -<> { yyerror("unterminated dollar-quoted string"); } - +<> { yyerror("unterminated dollar-quoted string"); } {xdstart} { state_before = YYSTATE; BEGIN(xd); @@ -625,8 +623,8 @@ cppline {space}*#(.*\\{space})*.*{newline} {ip} { yylval.str = mm_strdup(yytext); return IP; - } -{decimal} { + } +{decimal} { yylval.str = mm_strdup(yytext); return FCONST; } @@ -797,7 +795,7 @@ cppline {space}*#(.*\\{space})*.*{newline} "-" { return('-'); } "(" { return('('); } ")" { return(')'); } -{space} { ECHO; } +{space} { ECHO; } \{ { return('{'); } \} { return('}'); } \[ { return('['); } @@ -1037,7 +1035,6 @@ cppline {space}*#(.*\\{space})*.*{newline} if (strcmp(old, ptr->old) == 0) { free(ptr->new); - /* ptr->new = mm_strdup(scanstr(literalbuf));*/ ptr->new = mm_strdup(literalbuf); } } diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index 63b18a1ae8..4c07d4218c 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.319 2006/02/04 20:54:42 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.320 2006/02/08 09:10:04 meskes Exp $ */ /* Copyright comment */ %{ @@ -433,7 +433,7 @@ add_additional_variables(char *name, bool insert) %token UNIONJOIN /* Special token types, not actually keywords - see the "lex" file */ -%token IDENT SCONST Op CSTRING CVARIABLE CPP_LINE IP BCONST XCONST +%token IDENT SCONST Op CSTRING CVARIABLE CPP_LINE IP BCONST XCONST DOLCONST %token ICONST PARAM %token FCONST @@ -1519,7 +1519,7 @@ ColConstraintElem: NOT NULL_P * there is no parsing conflict. */ ConstraintAttr: DEFERRABLE { $$ = make_str("deferrable"); } - | NOT DEFERRABLE { $$ = make_str("not deferrable"); } + | NOT DEFERRABLE { $$ = make_str("not deferrable"); } | INITIALLY DEFERRED { $$ = make_str("initially deferred"); } | INITIALLY IMMEDIATE { $$ = make_str("initially immediate"); } ; @@ -4383,7 +4383,11 @@ Sconst: SCONST $$[strlen($1)+2]='\0'; free($1); } - ; + | DOLCONST + { + $$ = $1; + } + ; PosIntConst: Iconst { $$ = $1; } | civar { $$ = $1; } @@ -4740,9 +4744,9 @@ single_var_declaration: storage_declaration actual_startline[struct_level] = hashline_number(); } - variable_list opt_bit_field';' + variable_list ';' { - $$ = cat_str(6, actual_startline[struct_level], $1, $2.type_str, $4, $5, make_str(";\n")); + $$ = cat_str(5, actual_startline[struct_level], $1, $2.type_str, $4, make_str(";\n")); } | var_type { @@ -4753,9 +4757,9 @@ single_var_declaration: storage_declaration actual_startline[struct_level] = hashline_number(); } - variable_list opt_bit_field';' + variable_list ';' { - $$ = cat_str(5, actual_startline[struct_level], $1.type_str, $3, $4, make_str(";\n")); + $$ = cat_str(4, actual_startline[struct_level], $1.type_str, $3, make_str(";\n")); } | struct_union_type_with_symbol ';' { @@ -4799,10 +4803,10 @@ var_type_declarations: /*EMPTY*/ { $$ = EMPTY; } ; vt_declarations: var_declaration { $$ = $1; } - | type_declaration { $$ = $1; } + | type_declaration { $$ = $1; } | vt_declarations var_declaration { $$ = cat2_str($1, $2); } | vt_declarations type_declaration { $$ = cat2_str($1, $2); } - | vt_declarations CPP_LINE { $$ = cat2_str($1, $2); } + | vt_declarations CPP_LINE { $$ = cat2_str($1, $2); } ; variable_declarations: var_declaration { $$ = $1; } @@ -4875,9 +4879,9 @@ var_declaration: storage_declaration actual_startline[struct_level] = hashline_number(); } - variable_list opt_bit_field';' + variable_list ';' { - $$ = cat_str(6, actual_startline[struct_level], $1, $2.type_str, $4, $5, make_str(";\n")); + $$ = cat_str(5, actual_startline[struct_level], $1, $2.type_str, $4, make_str(";\n")); } | var_type { @@ -4888,9 +4892,9 @@ var_declaration: storage_declaration actual_startline[struct_level] = hashline_number(); } - variable_list opt_bit_field';' + variable_list ';' { - $$ = cat_str(5, actual_startline[struct_level], $1.type_str, $3, $4, make_str(";\n")); + $$ = cat_str(4, actual_startline[struct_level], $1.type_str, $3, make_str(";\n")); } | struct_union_type_with_symbol ';' { @@ -5266,7 +5270,7 @@ variable_list: variable { $$ = cat_str(3, $1, make_str(","), $3); } ; -variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer +variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initializer { struct ECPGtype * type; char *dimension = $3.index1; /* dimension of array */ @@ -5284,7 +5288,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer else type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_sizeof), dimension); - $$ = cat_str(4, $1, mm_strdup($2), $3.str, $4); + $$ = cat_str(5, $1, mm_strdup($2), $3.str, $4, $5); break; case ECPGt_varchar: @@ -5302,9 +5306,9 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer mmerror(PARSE_ERROR, ET_ERROR, "pointer to varchar are not implemented"); if (strcmp(dimension, "0") == 0) - $$ = cat_str(6, make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } *"), mm_strdup($2), $4); + $$ = cat_str(7, make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } *"), mm_strdup($2), $4, $5); else - $$ = cat_str(7, make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4); + $$ = cat_str(8, make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4, $5); break; case ECPGt_char: @@ -5314,7 +5318,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer else type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); - $$ = cat_str(4, $1, mm_strdup($2), $3.str, $4); + $$ = cat_str(5, $1, mm_strdup($2), $3.str, $4, $5); break; default: @@ -5323,7 +5327,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer else type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1")), dimension); - $$ = cat_str(4, $1, mm_strdup($2), $3.str, $4); + $$ = cat_str(5, $1, mm_strdup($2), $3.str, $4, $5); break; } @@ -5824,7 +5828,7 @@ ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action { when_warn.code = $3.code; when_warn.command = $3.command; - $$ = cat_str(3, make_str("/* exec sql whenever sql_warning "), $3.str, make_str("; */\n")); + $$ = cat_str(3, make_str("/* exec sql whenever sql_warning "), $3.str, make_str("; */")); } ; @@ -6517,7 +6521,7 @@ c_stuff_item: c_anything { $$ = $1; } { $$ = cat_str(3, make_str("("), $2, make_str(")")); } ; -c_stuff: c_stuff_item { $$ = $1; } +c_stuff: c_stuff_item { $$ = $1; } | c_stuff c_stuff_item { $$ = cat2_str($1, $2); } ; @@ -6530,15 +6534,14 @@ c_term: c_stuff { $$ = $1; } | '{' c_list '}' { $$ = cat_str(3, make_str("{"), $2, make_str("}")); } ; -c_thing: c_anything { $$ = $1; } - | '(' { $$ = make_str("("); } - | ')' { $$ = make_str(")"); } - | ',' { $$ = make_str(","); } - | ';' { $$ = make_str(";"); } - | ':' { $$ = make_str(":"); } +c_thing: c_anything { $$ = $1; } + | '(' { $$ = make_str("("); } + | ')' { $$ = make_str(")"); } + | ',' { $$ = make_str(","); } + | ';' { $$ = make_str(";"); } ; -c_anything: IDENT { $$ = $1; } +c_anything: IDENT { $$ = $1; } | CSTRING { $$ = make3_str(make_str("\""), $1, make_str("\"")); } | Iconst { $$ = $1; } | Fconst { $$ = $1; } @@ -6551,28 +6554,28 @@ c_anything: IDENT { $$ = $1; } | NULL_P { $$ = make_str("NULL"); } | S_ADD { $$ = make_str("+="); } | S_AND { $$ = make_str("&&"); } - | S_ANYTHING { $$ = make_name(); } + | S_ANYTHING { $$ = make_name(); } | S_AUTO { $$ = make_str("auto"); } | S_CONST { $$ = make_str("const"); } | S_DEC { $$ = make_str("--"); } | S_DIV { $$ = make_str("/="); } - | S_DOTPOINT { $$ = make_str(".*"); } + | S_DOTPOINT { $$ = make_str(".*"); } | S_EQUAL { $$ = make_str("=="); } | S_EXTERN { $$ = make_str("extern"); } | S_INC { $$ = make_str("++"); } | S_LSHIFT { $$ = make_str("<<"); } | S_MEMBER { $$ = make_str("->"); } - | S_MEMPOINT { $$ = make_str("->*"); } + | S_MEMPOINT { $$ = make_str("->*"); } | S_MOD { $$ = make_str("%="); } | S_MUL { $$ = make_str("*="); } | S_NEQUAL { $$ = make_str("!="); } | S_OR { $$ = make_str("||"); } - | S_REGISTER { $$ = make_str("register"); } + | S_REGISTER { $$ = make_str("register"); } | S_RSHIFT { $$ = make_str(">>"); } | S_STATIC { $$ = make_str("static"); } | S_SUB { $$ = make_str("-="); } | S_TYPEDEF { $$ = make_str("typedef"); } - | S_VOLATILE { $$ = make_str("volatile"); } + | S_VOLATILE { $$ = make_str("volatile"); } | SQL_BOOL { $$ = make_str("bool"); } | SQL_ENUM { $$ = make_str("enum"); } | HOUR_P { $$ = make_str("hour"); } @@ -6582,9 +6585,9 @@ c_anything: IDENT { $$ = $1; } | MONTH_P { $$ = make_str("month"); } | SECOND_P { $$ = make_str("second"); } | SQL_SHORT { $$ = make_str("short"); } - | SQL_SIGNED { $$ = make_str("signed"); } - | SQL_STRUCT { $$ = make_str("struct"); } - | SQL_UNSIGNED { $$ = make_str("unsigned"); } + | SQL_SIGNED { $$ = make_str("signed"); } + | SQL_STRUCT { $$ = make_str("struct"); } + | SQL_UNSIGNED { $$ = make_str("unsigned"); } | YEAR_P { $$ = make_str("year"); } | CHAR_P { $$ = make_str("char"); } | FLOAT_P { $$ = make_str("float"); } @@ -6594,6 +6597,7 @@ c_anything: IDENT { $$ = $1; } | '[' { $$ = make_str("["); } | ']' { $$ = make_str("]"); } | '=' { $$ = make_str("="); } + | ':' { $$ = make_str(":"); } ; %% diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile index b1f51eeae8..c88f43896c 100644 --- a/src/interfaces/ecpg/test/Makefile +++ b/src/interfaces/ecpg/test/Makefile @@ -1,4 +1,4 @@ -# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.52 2006/02/04 20:54:44 meskes Exp $ +# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.53 2006/02/08 09:10:05 meskes Exp $ subdir = src/interfaces/ecpg/test top_builddir = ../../../.. @@ -11,7 +11,7 @@ ECPG = ../preproc/ecpg -I$(srcdir)/../include TESTS = test1 test2 test3 test4 test5 perftest dyntest dyntest2 test_notice \ test_code100 test_init testdynalloc num_test dt_test test_informix \ - test_informix2 test_desc + test_informix2 test_desc test_func ifeq ($(enable_thread_safety), yes) TESTS += test_thread test_thread_implicit endif diff --git a/src/interfaces/ecpg/test/perftest.pgc b/src/interfaces/ecpg/test/perftest.pgc index 0c5b1478aa..7fb22588c8 100644 --- a/src/interfaces/ecpg/test/perftest.pgc +++ b/src/interfaces/ecpg/test/perftest.pgc @@ -15,7 +15,7 @@ print_result(long sec, long usec, char *text) sec--; usec+=1000000; } - printf("I needed %ld seconds and %ld microseconds for the %s test.\n", sec, usec, text); + printf("%ld seconds and %ld microseconds for test %s\n", sec, usec, text); exec sql vacuum; sleep(1); } diff --git a/src/interfaces/ecpg/test/test1.pgc b/src/interfaces/ecpg/test/test1.pgc index 9f784ac799..91124bbdc2 100644 --- a/src/interfaces/ecpg/test/test1.pgc +++ b/src/interfaces/ecpg/test/test1.pgc @@ -42,6 +42,9 @@ exec sql ifdef NAMELEN; int amount; char letter; } name_letter[AMOUNT]; +#if 0 + int not_used; +#endif exec sql endif; struct ind_struct { diff --git a/src/interfaces/ecpg/test/test5.pgc b/src/interfaces/ecpg/test/test5.pgc index 08fcef3e0e..841b0e379f 100644 --- a/src/interfaces/ecpg/test/test5.pgc +++ b/src/interfaces/ecpg/test/test5.pgc @@ -56,7 +56,10 @@ main (void) exit (sqlca.sqlcode); } - EXEC SQL select name, accs, byte into:empl.name,:empl.accs,:empl.byte from empl where idnum =:empl.idnum; + EXEC SQL select name, accs, byte + into :empl.name, :empl.accs, :empl.byte + from empl + where idnum =:empl.idnum; if (sqlca.sqlcode) { printf ("select error = %ld\n", sqlca.sqlcode); diff --git a/src/interfaces/ecpg/test/test_func.pgc b/src/interfaces/ecpg/test/test_func.pgc new file mode 100644 index 0000000000..466512a35b --- /dev/null +++ b/src/interfaces/ecpg/test/test_func.pgc @@ -0,0 +1,45 @@ +#include +#include +#include + +int main(int argc, char* argv[]) { + FILE *dbgs; + + if ((dbgs = fopen("log", "w")) != NULL) + ECPGdebug(1, dbgs); + EXEC SQL CONNECT TO mm; + + EXEC SQL SET AUTOCOMMIT TO ON; + EXEC SQL WHENEVER SQLWARNING SQLPRINT; + EXEC SQL WHENEVER SQLERROR SQLPRINT; + + EXEC SQL CREATE TABLE My_Table ( Item1 int, Item2 text ); + + EXEC SQL CREATE FUNCTION My_Table_Check() RETURNS trigger + AS $test$ + BEGIN + RAISE NOTICE 'TG_NAME=%, TG WHEN=%', TG_NAME, TG_WHEN; + RETURN NEW; + END; $test$ + LANGUAGE 'plpgsql'; + + EXEC SQL CREATE TRIGGER My_Table_Check_Trigger + BEFORE INSERT + ON My_Table + FOR EACH ROW + EXECUTE PROCEDURE My_Table_Check(); + + EXEC SQL INSERT INTO My_Table VALUES (1234, 'Some random text'); + EXEC SQL INSERT INTO My_Table VALUES (5678, 'The Quick Brown'); + + EXEC SQL DROP TRIGGER My_Table_Check_Trigger ON My_Table; + EXEC SQL DROP FUNCTION My_Table_Check(); + EXEC SQL DROP TABLE My_Table; + + EXEC SQL DISCONNECT ALL; + if (dbgs != NULL) + fclose(dbgs); + + + return 0; +}