From 13b78a2400efe11ae3929b43992d261ed20b5305 Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Fri, 22 Dec 2000 12:43:14 +0000 Subject: [PATCH] - Fixed bug in a connect statement using varchars. - Synced parser. --- src/interfaces/ecpg/ChangeLog | 5 ++ src/interfaces/ecpg/preproc/preproc.y | 73 +++++++++++++++++---------- src/interfaces/ecpg/test/Makefile | 2 +- src/interfaces/ecpg/test/test4.pgc | 4 +- 4 files changed, 55 insertions(+), 29 deletions(-) diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index f16ca0175b..d6906f2b6f 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -1029,5 +1029,10 @@ Mon Dec 18 12:27:52 CET 2000 - Synced gram.y and preproc.y. - Synced keyword.c. - Added several small patches from Christof. + +Fri Dec 22 13:33:31 CET 2000 + + - Fixed bug in a connect statement using varchars. + - Synced gram.y and preproc.y. - Set ecpg version to 2.8.0. - Set library version to 3.2.0. diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index a29dd22948..2312d0ccc7 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -313,7 +313,7 @@ make_name(void) %type index_list func_index index_elem opt_class access_method_clause %type index_opt_unique IndexStmt func_return ConstInterval %type func_args_list func_args opt_with ProcedureStmt def_arg -%type def_elem def_list definition def_name def_type DefineStmt +%type def_elem def_list definition DefineStmt %type opt_instead event event_object RuleActionList opt_using %type RuleActionStmtOrEmpty RuleActionMulti func_as reindex_type %type RuleStmt opt_column opt_name oper_argtypes sysid_clause @@ -1335,7 +1335,7 @@ OptSeqElem: CACHE IntConst *****************************************************************************/ CreatePLangStmt: CREATE PLangTrusted opt_procedural LANGUAGE StringConst - HANDLER def_name LANCOMPILER StringConst + HANDLER func_name LANCOMPILER StringConst { $$ = cat_str(9, make_str("create"), $2, $3, make_str("language"), $5, make_str("handler"), $7, make_str("langcompiler"), $9); } @@ -1482,23 +1482,20 @@ DropTrigStmt: DROP TRIGGER name ON relation_name * *****************************************************************************/ -DefineStmt: CREATE def_type def_name definition - { - $$ = cat_str(3, make_str("create"), $2, $3, $4); - } - ; - -def_type: OPERATOR { $$ = make_str("operator"); } - | TYPE_P { $$ = make_str("type"); } - | AGGREGATE { $$ = make_str("aggregate"); } +DefineStmt: CREATE AGGREGATE func_name definition + { + $$ = cat_str(3, make_str("create aggregate"), $3, $4); + } + | CREATE OPERATOR all_Op definition + { + $$ = cat_str(3, make_str("create operator"), $3, $4); + } + | CREATE TYPE_P name definition + { + $$ = cat_str(3, make_str("create type"), $3, $4); + } ; -def_name: PROCEDURE { $$ = make_str("procedure"); } - | JOIN { $$ = make_str("join"); } - | all_Op { $$ = $1; } - | ColId { $$ = $1; } - ; - definition: '(' def_list ')' { $$ = cat_str(3, make_str("("), $2, make_str(")")); } ; @@ -1506,17 +1503,13 @@ def_list: def_elem { $$ = $1; } | def_list ',' def_elem { $$ = cat_str(3, $1, make_str(","), $3); } ; -def_elem: def_name '=' def_arg { +def_elem: ColLabel '=' def_arg { $$ = cat_str(3, $1, make_str("="), $3); } - | def_name + | ColLabel { $$ = $1; } - | DEFAULT '=' def_arg - { - $$ = cat2_str(make_str("default ="), $3); - } ; def_arg: func_return { $$ = $1; } @@ -1977,7 +1970,7 @@ RemoveFuncStmt: DROP FUNCTION func_name func_args } ; -RemoveAggrStmt: DROP AGGREGATE name aggr_argtype +RemoveAggrStmt: DROP AGGREGATE func_name aggr_argtype { $$ = cat_str(3, make_str("drop aggregate"), $3, $4); } @@ -3964,8 +3957,20 @@ connection_target: database_name opt_server opt_port { if ($1[0] == '\"') $$ = $1; - else if (strcmp($1, "?") == 0) - $$ = mm_strdup(argsinsert->variable->name); + else if (strcmp($1, "?") == 0) /* variable */ + { + enum ECPGttype typ = argsinsert->variable->type->typ; + + /* if array see what's inside */ + if (typ == ECPGt_array) + typ = argsinsert->variable->type->u.element->typ; + + /* handle varchars */ + if (typ == ECPGt_varchar) + $$ = make2_str(mm_strdup(argsinsert->variable->name), make_str(".arr")); + else + $$ = mm_strdup(argsinsert->variable->name); + } else $$ = make3_str(make_str("\""), $1, make_str("\"")); } @@ -4040,6 +4045,20 @@ user_name: UserId { | StringConst { if ($1[0] == '\"') $$ = $1; + else if (strcmp($1, "?") == 0) /* variable */ + { + enum ECPGttype typ = argsinsert->variable->type->typ; + + /* if array see what's inside */ + if (typ == ECPGt_array) + typ = argsinsert->variable->type->u.element->typ; + + /* handle varchars */ + if (typ == ECPGt_varchar) + $$ = make2_str(mm_strdup(argsinsert->variable->name), make_str(".arr")); + else + $$ = mm_strdup(argsinsert->variable->name); + } else $$ = make3_str(make_str("\""), $1, make_str("\"")); } @@ -5033,6 +5052,7 @@ TokenId: ABSOLUTE { $$ = make_str("absolute"); } | PRIOR { $$ = make_str("prior"); } | PRIVILEGES { $$ = make_str("privileges"); } | PROCEDURAL { $$ = make_str("procedural"); } + | PROCEDURE { $$ = make_str("procedure"); } | READ { $$ = make_str("read"); } | REINDEX { $$ = make_str("reindex"); } | RELATIVE { $$ = make_str("relative"); } @@ -5180,7 +5200,6 @@ ECPGColLabel: ECPGColId { $$ = $1; } | POSITION { $$ = make_str("position"); } | PRECISION { $$ = make_str("precision"); } | PRIMARY { $$ = make_str("primary"); } - | PROCEDURE { $$ = make_str("procedure"); } | PUBLIC { $$ = make_str("public"); } | REFERENCES { $$ = make_str("references"); } | RESET { $$ = make_str("reset"); } diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile index b2bffa168e..2ddbb185e0 100644 --- a/src/interfaces/ecpg/test/Makefile +++ b/src/interfaces/ecpg/test/Makefile @@ -23,4 +23,4 @@ test_init: test_init.c $(ECPG) $? clean: - rm -f test1 test2 test3 test4 perftest *.c log dyntest dyntest2 test_notice test_code100 + rm -f test1 test2 test3 test4 perftest *.c log dyntest dyntest2 test_notice test_code100 test_init diff --git a/src/interfaces/ecpg/test/test4.pgc b/src/interfaces/ecpg/test/test4.pgc index a45abc1ae6..2979ead7f1 100644 --- a/src/interfaces/ecpg/test/test4.pgc +++ b/src/interfaces/ecpg/test/test4.pgc @@ -15,6 +15,7 @@ EXEC SQL BEGIN DECLARE SECTION; char *t = "uvwxyz1234"; double f; bool b = true; + varchar database[3]; EXEC SQL END DECLARE SECTION; FILE *dbgs; @@ -23,7 +24,8 @@ EXEC SQL END DECLARE SECTION; if ((dbgs = fopen("log", "w")) != NULL) ECPGdebug(1, dbgs); - EXEC SQL CONNECT TO mm; + strcpy(database.arr, "mm"); + EXEC SQL CONNECT TO :database; EXEC SQL SET AUTOCOMMIT = ON; -- 2.40.0