Commit e3740d2c authored by Michael Meskes's avatar Michael Meskes

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.
parent 115e5dd5
...@@ -1982,6 +1982,17 @@ Sa Feb 4 21:35:03 CET 2006 ...@@ -1982,6 +1982,17 @@ Sa Feb 4 21:35:03 CET 2006
- Added C bit fields to ecpg parser. - Added C bit fields to ecpg parser.
- Added some default rules to lexer. - Added some default rules to lexer.
- Added log output to prepare statement. - 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 library version to 5.2.
- Set ecpg version to 4.2.1. - Set ecpg version to 4.2.1.
/* $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. */ /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */ /* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
...@@ -418,7 +418,7 @@ main(int argc, char *const argv[]) ...@@ -418,7 +418,7 @@ main(int argc, char *const argv[])
fprintf(yyout, "/* End of automatic include section */\n"); fprintf(yyout, "/* End of automatic include section */\n");
} }
fprintf(yyout, "#line 1 \"%s\"\n", input_filename); output_line_number();
/* and parse the source */ /* and parse the source */
yyparse(); yyparse();
......
...@@ -2,19 +2,22 @@ ...@@ -2,19 +2,22 @@
#include "extern.h" #include "extern.h"
static void ouput_escaped_str(char *cmd); static void output_escaped_str(char *cmd);
void void
output_line_number(void) output_line_number(void)
{ {
if (input_filename) char *line = hashline_number();
fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename);
/* output_escaped_str(line); */
fprintf(yyout, "%s", line);
free(line);
} }
void void
output_simple_statement(char *stmt) output_simple_statement(char *stmt)
{ {
ouput_escaped_str(stmt); output_escaped_str(stmt);
output_line_number(); output_line_number();
free(stmt); free(stmt);
} }
...@@ -83,7 +86,8 @@ whenever_action(int mode) ...@@ -83,7 +86,8 @@ whenever_action(int mode)
char * char *
hashline_number(void) 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)); char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename));
...@@ -99,7 +103,7 @@ void ...@@ -99,7 +103,7 @@ void
output_statement(char *stmt, int mode, char *con) output_statement(char *stmt, int mode, char *con)
{ {
fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, \"", compat, force_indicator, con ? con : "NULL"); fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, \"", compat, force_indicator, con ? con : "NULL");
ouput_escaped_str(stmt); output_escaped_str(stmt);
fputs("\", ", yyout); fputs("\", ", yyout);
/* dump variables to C file */ /* dump variables to C file */
...@@ -118,7 +122,7 @@ output_statement(char *stmt, int mode, char *con) ...@@ -118,7 +122,7 @@ output_statement(char *stmt, int mode, char *con)
static void static void
ouput_escaped_str(char *str) output_escaped_str(char *str)
{ {
int i, len = strlen(str); int i, len = strlen(str);
...@@ -128,7 +132,8 @@ ouput_escaped_str(char *str) ...@@ -128,7 +132,8 @@ ouput_escaped_str(char *str)
if (str[i] == '"') if (str[i] == '"')
fputs("\\\"", yyout); fputs("\\\"", yyout);
else if (str[i] == '\n') else if (str[i] == '\n')
fputs("\\n\\\n", yyout); //fputs("\\n\\\n", yyout);
fputs("\\\n", yyout);
else else
fputc(str[i], yyout); fputc(str[i], yyout);
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * 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_] ...@@ -152,7 +152,7 @@ dolq_start [A-Za-z\200-\377_]
dolq_cont [A-Za-z\200-\377_0-9] dolq_cont [A-Za-z\200-\377_0-9]
dolqdelim \$({dolq_start}{dolq_cont}*)?\$ dolqdelim \$({dolq_start}{dolq_cont}*)?\$
dolqfailed \${dolq_start}{dolq_cont}* dolqfailed \${dolq_start}{dolq_cont}*
dolqinside [^$']+ dolqinside [^$]+
/* Double quote /* Double quote
* Allows embedded spaces and other special characters into identifiers. * Allows embedded spaces and other special characters into identifiers.
...@@ -437,7 +437,7 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -437,7 +437,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
addlit(yytext, yyleng); addlit(yytext, yyleng);
} }
<xq>{quotecontinue} { /* ignore */ } <xq>{quotecontinue} { /* ignore */ }
<xq>. { <xq>{other} {
/* This is only needed for \ just before EOF */ /* This is only needed for \ just before EOF */
addlitchar(yytext[0]); addlitchar(yytext[0]);
} }
...@@ -453,14 +453,16 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -453,14 +453,16 @@ cppline {space}*#(.*\\{space})*.*{newline}
dolqstart = mm_strdup(yytext); dolqstart = mm_strdup(yytext);
BEGIN(xdolq); BEGIN(xdolq);
startlit(); startlit();
addlit(yytext, yyleng);
} }
<xdolq>{dolqdelim} { <xdolq>{dolqdelim} {
if (strcmp(yytext, dolqstart) == 0) if (strcmp(yytext, dolqstart) == 0)
{ {
addlit(yytext, yyleng);
free(dolqstart); free(dolqstart);
BEGIN(SQL); BEGIN(SQL);
yylval.str = mm_strdup(literalbuf); yylval.str = mm_strdup(literalbuf);
return SCONST; return DOLCONST;
} }
else else
{ {
...@@ -475,15 +477,11 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -475,15 +477,11 @@ cppline {space}*#(.*\\{space})*.*{newline}
} }
<xdolq>{dolqinside} { addlit(yytext, yyleng); } <xdolq>{dolqinside} { addlit(yytext, yyleng); }
<xdolq>{dolqfailed} { addlit(yytext, yyleng); } <xdolq>{dolqfailed} { addlit(yytext, yyleng); }
<xdolq>. { <xdolq>{other} {
/* $$ is implemented as a single-quoted string, so double it? */
if (yytext[0] == '\'')
addlitchar(yytext[0]);
/* single quote or dollar sign */ /* single quote or dollar sign */
addlitchar(yytext[0]); addlitchar(yytext[0]);
} }
<xdolq><<EOF>> { yyerror("unterminated dollar-quoted string"); } <xdolq><<EOF>> { yyerror("unterminated dollar-quoted string"); }
<SQL>{xdstart} { <SQL>{xdstart} {
state_before = YYSTATE; state_before = YYSTATE;
BEGIN(xd); BEGIN(xd);
...@@ -626,7 +624,7 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -626,7 +624,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
yylval.str = mm_strdup(yytext); yylval.str = mm_strdup(yytext);
return IP; return IP;
} }
{decimal} { <C,SQL>{decimal} {
yylval.str = mm_strdup(yytext); yylval.str = mm_strdup(yytext);
return FCONST; return FCONST;
} }
...@@ -1037,7 +1035,6 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -1037,7 +1035,6 @@ cppline {space}*#(.*\\{space})*.*{newline}
if (strcmp(old, ptr->old) == 0) if (strcmp(old, ptr->old) == 0)
{ {
free(ptr->new); free(ptr->new);
/* ptr->new = mm_strdup(scanstr(literalbuf));*/
ptr->new = mm_strdup(literalbuf); ptr->new = mm_strdup(literalbuf);
} }
} }
......
/* $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 */ /* Copyright comment */
%{ %{
...@@ -433,7 +433,7 @@ add_additional_variables(char *name, bool insert) ...@@ -433,7 +433,7 @@ add_additional_variables(char *name, bool insert)
%token UNIONJOIN %token UNIONJOIN
/* Special token types, not actually keywords - see the "lex" file */ /* Special token types, not actually keywords - see the "lex" file */
%token <str> IDENT SCONST Op CSTRING CVARIABLE CPP_LINE IP BCONST XCONST %token <str> IDENT SCONST Op CSTRING CVARIABLE CPP_LINE IP BCONST XCONST DOLCONST
%token <ival> ICONST PARAM %token <ival> ICONST PARAM
%token <dval> FCONST %token <dval> FCONST
...@@ -4383,6 +4383,10 @@ Sconst: SCONST ...@@ -4383,6 +4383,10 @@ Sconst: SCONST
$$[strlen($1)+2]='\0'; $$[strlen($1)+2]='\0';
free($1); free($1);
} }
| DOLCONST
{
$$ = $1;
}
; ;
PosIntConst: Iconst { $$ = $1; } PosIntConst: Iconst { $$ = $1; }
...@@ -4740,9 +4744,9 @@ single_var_declaration: storage_declaration ...@@ -4740,9 +4744,9 @@ single_var_declaration: storage_declaration
actual_startline[struct_level] = hashline_number(); 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 | var_type
{ {
...@@ -4753,9 +4757,9 @@ single_var_declaration: storage_declaration ...@@ -4753,9 +4757,9 @@ single_var_declaration: storage_declaration
actual_startline[struct_level] = hashline_number(); 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 ';' | struct_union_type_with_symbol ';'
{ {
...@@ -4875,9 +4879,9 @@ var_declaration: storage_declaration ...@@ -4875,9 +4879,9 @@ var_declaration: storage_declaration
actual_startline[struct_level] = hashline_number(); 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 | var_type
{ {
...@@ -4888,9 +4892,9 @@ var_declaration: storage_declaration ...@@ -4888,9 +4892,9 @@ var_declaration: storage_declaration
actual_startline[struct_level] = hashline_number(); 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 ';' | struct_union_type_with_symbol ';'
{ {
...@@ -5266,7 +5270,7 @@ variable_list: variable ...@@ -5266,7 +5270,7 @@ variable_list: variable
{ $$ = cat_str(3, $1, make_str(","), $3); } { $$ = 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; struct ECPGtype * type;
char *dimension = $3.index1; /* dimension of array */ char *dimension = $3.index1; /* dimension of array */
...@@ -5284,7 +5288,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer ...@@ -5284,7 +5288,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer
else 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); 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; break;
case ECPGt_varchar: case ECPGt_varchar:
...@@ -5302,9 +5306,9 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer ...@@ -5302,9 +5306,9 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer
mmerror(PARSE_ERROR, ET_ERROR, "pointer to varchar are not implemented"); mmerror(PARSE_ERROR, ET_ERROR, "pointer to varchar are not implemented");
if (strcmp(dimension, "0") == 0) 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 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; break;
case ECPGt_char: case ECPGt_char:
...@@ -5314,7 +5318,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer ...@@ -5314,7 +5318,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer
else else
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); 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; break;
default: default:
...@@ -5323,7 +5327,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer ...@@ -5323,7 +5327,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer
else else
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1")), dimension); 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; break;
} }
...@@ -5824,7 +5828,7 @@ ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action ...@@ -5824,7 +5828,7 @@ ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action
{ {
when_warn.code = $<action>3.code; when_warn.code = $<action>3.code;
when_warn.command = $<action>3.command; when_warn.command = $<action>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("; */"));
} }
; ;
...@@ -6535,7 +6539,6 @@ c_thing: c_anything { $$ = $1; } ...@@ -6535,7 +6539,6 @@ c_thing: c_anything { $$ = $1; }
| ')' { $$ = make_str(")"); } | ')' { $$ = make_str(")"); }
| ',' { $$ = make_str(","); } | ',' { $$ = make_str(","); }
| ';' { $$ = make_str(";"); } | ';' { $$ = make_str(";"); }
| ':' { $$ = make_str(":"); }
; ;
c_anything: IDENT { $$ = $1; } c_anything: IDENT { $$ = $1; }
...@@ -6594,6 +6597,7 @@ c_anything: IDENT { $$ = $1; } ...@@ -6594,6 +6597,7 @@ c_anything: IDENT { $$ = $1; }
| '[' { $$ = make_str("["); } | '[' { $$ = make_str("["); }
| ']' { $$ = make_str("]"); } | ']' { $$ = make_str("]"); }
| '=' { $$ = make_str("="); } | '=' { $$ = make_str("="); }
| ':' { $$ = make_str(":"); }
; ;
%% %%
......
# $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 subdir = src/interfaces/ecpg/test
top_builddir = ../../../.. top_builddir = ../../../..
...@@ -11,7 +11,7 @@ ECPG = ../preproc/ecpg -I$(srcdir)/../include ...@@ -11,7 +11,7 @@ ECPG = ../preproc/ecpg -I$(srcdir)/../include
TESTS = test1 test2 test3 test4 test5 perftest dyntest dyntest2 test_notice \ TESTS = test1 test2 test3 test4 test5 perftest dyntest dyntest2 test_notice \
test_code100 test_init testdynalloc num_test dt_test test_informix \ 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) ifeq ($(enable_thread_safety), yes)
TESTS += test_thread test_thread_implicit TESTS += test_thread test_thread_implicit
endif endif
......
...@@ -15,7 +15,7 @@ print_result(long sec, long usec, char *text) ...@@ -15,7 +15,7 @@ print_result(long sec, long usec, char *text)
sec--; sec--;
usec+=1000000; 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; exec sql vacuum;
sleep(1); sleep(1);
} }
......
...@@ -42,6 +42,9 @@ exec sql ifdef NAMELEN; ...@@ -42,6 +42,9 @@ exec sql ifdef NAMELEN;
int amount; int amount;
char letter; char letter;
} name_letter[AMOUNT]; } name_letter[AMOUNT];
#if 0
int not_used;
#endif
exec sql endif; exec sql endif;
struct ind_struct struct ind_struct
{ {
......
...@@ -56,7 +56,10 @@ main (void) ...@@ -56,7 +56,10 @@ main (void)
exit (sqlca.sqlcode); 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) if (sqlca.sqlcode)
{ {
printf ("select error = %ld\n", sqlca.sqlcode); printf ("select error = %ld\n", sqlca.sqlcode);
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment