From 69f9fab1979b1733f2bb068c6f38cd744d80cb7a Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Tue, 24 Jan 2006 11:01:38 +0000 Subject: [PATCH] - Synced parser and keyword list. - Added another test case. --- src/interfaces/ecpg/ChangeLog | 5 + src/interfaces/ecpg/preproc/keywords.c | 5 +- src/interfaces/ecpg/preproc/preproc.y | 54 +++++++-- src/interfaces/ecpg/test/Makefile | 10 +- src/interfaces/ecpg/test/test_informix2.pgc | 123 ++++++++++++++++++++ 5 files changed, 185 insertions(+), 12 deletions(-) create mode 100644 src/interfaces/ecpg/test/test_informix2.pgc diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index 6e7a25c6ab..eed803e50e 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -1971,6 +1971,11 @@ Fr Jan 13 17:29:30 CET 2006 Tu Jan 17 18:53:03 CET 2006 - Data transferred binary is now put into the variables verbatim. + +Tu Jan 24 10:59:21 CET 2006 + + - Synced parser and keyword list. + - Added another test case. - Set ecpg library version to 5.2. - Set ecpg version to 4.2.1. diff --git a/src/interfaces/ecpg/preproc/keywords.c b/src/interfaces/ecpg/preproc/keywords.c index 4d1f83da02..08a54262af 100644 --- a/src/interfaces/ecpg/preproc/keywords.c +++ b/src/interfaces/ecpg/preproc/keywords.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.71 2005/12/27 04:00:08 momjian Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.72 2006/01/24 11:01:37 meskes Exp $ * *------------------------------------------------------------------------- */ @@ -158,6 +158,7 @@ static ScanKeyword ScanKeywords[] = { {"header", HEADER_P}, {"hold", HOLD}, {"hour", HOUR_P}, + {"if", IF_P}, {"ilike", ILIKE}, {"immediate", IMMEDIATE}, {"immutable", IMMUTABLE}, @@ -246,6 +247,7 @@ static ScanKeyword ScanKeywords[] = { {"out", OUT_P}, {"outer", OUTER_P}, {"overlaps", OVERLAPS}, + {"owned", OWNED}, {"owner", OWNER}, {"partial", PARTIAL}, {"password", PASSWORD}, @@ -262,6 +264,7 @@ static ScanKeyword ScanKeywords[] = { {"quote", QUOTE}, {"read", READ}, {"real", REAL}, + {"reassign", REASSIGN}, {"recheck", RECHECK}, {"references", REFERENCES}, {"reindex", REINDEX}, diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index 21fbb104ff..c30c715f5f 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.315 2005/12/29 04:53:18 neilc Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.316 2006/01/24 11:01:37 meskes Exp $ */ /* Copyright comment */ %{ @@ -377,7 +377,7 @@ add_additional_variables(char *name, bool insert) HANDLER HAVING HEADER_P HOLD HOUR_P - ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT + IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT INDEX INHERIT INHERITS INITIALLY INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION @@ -397,7 +397,7 @@ add_additional_variables(char *name, bool insert) NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NUMERIC OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR ORDER - OUT_P OUTER_P OVERLAPS OVERLAY OWNER + OUT_P OUTER_P OVERLAPS OVERLAY OWNED OWNER PARTIAL PASSWORD PLACING POSITION PRECISION PRESERVE PREPARE PREPARED PRIMARY @@ -405,7 +405,7 @@ add_additional_variables(char *name, bool insert) QUOTE - READ REAL RECHECK REFERENCES REINDEX RELATIVE_P RELEASE RENAME + READ REAL REASSIGN RECHECK REFERENCES REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE RESET RESTART RESTRICT RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE @@ -520,7 +520,7 @@ add_additional_variables(char *name, bool insert) %type ViewStmt LoadStmt CreatedbStmt createdb_opt_item ExplainableStmt %type createdb_opt_list opt_encoding OptInherit opt_equal %type privilege_list privilege privilege_target -%type opt_grant_grant_option cursor_options +%type opt_grant_grant_option cursor_options DropOwnedStmt %type transaction_mode_list_or_empty transaction_mode_list %type function_with_argtypes_list function_with_argtypes IntConstVar %type DropdbStmt ClusterStmt grantee RevokeStmt Bit DropOpClassStmt @@ -531,7 +531,7 @@ add_additional_variables(char *name, bool insert) %type ConstraintTimeSpec AlterDatabaseSetStmt DropAssertStmt %type select_offset_value ReindexStmt join_type opt_boolean %type join_qual joined_table opclass_item -%type lock_type array_expr_list +%type lock_type array_expr_list ReassignOwnedStmt %type OptConstrFromTable OptTempTableName StringConst array_expr %type constraints_set_mode comment_type %type CreateGroupStmt AlterGroupStmt DropGroupStmt key_delete @@ -698,6 +698,7 @@ stmt: AlterDatabaseStmt { output_statement($1, 0, connection); } | DropCastStmt { output_statement($1, 0, connection); } | DropGroupStmt { output_statement($1, 0, connection); } | DropOpClassStmt { output_statement($1, 0, connection); } + | DropOwnedStmt { output_statement($1, 0, connection); } | DropPLangStmt { output_statement($1, 0, connection); } | DropRoleStmt { output_statement($1, 0, connection); } | DropRuleStmt { output_statement($1, 0, connection); } @@ -718,6 +719,7 @@ stmt: AlterDatabaseStmt { output_statement($1, 0, connection); } | LockStmt { output_statement($1, 0, connection); } | NotifyStmt { output_statement($1, 0, connection); } /* | PrepareStmt { output_statement($1, 0, connection); }*/ + | ReassignOwnedStmt { output_statement($1, 0, connection); } | ReindexStmt { output_statement($1, 0, connection); } | RemoveAggrStmt { output_statement($1, 0, connection); } | RemoveOperStmt { output_statement($1, 0, connection); } @@ -924,6 +926,7 @@ opt_with: WITH { $$ = make_str("with"); } */ OptRoleList: PASSWORD Sconst { $$ = cat2_str(make_str("password"), $2); } + | PASSWORD NULL_P { $$ = make_str("password null"); } | ENCRYPTED PASSWORD Sconst { $$ = cat2_str(make_str("encrypted password"), $3); } | UNENCRYPTED PASSWORD Sconst { $$ = cat2_str(make_str("unencrypted password"), $3); } | SUPERUSER_P { $$ = make_str("superuser"); } @@ -1995,11 +1998,35 @@ DropOpClassStmt: DROP OPERATOR CLASS any_name USING access_method opt_drop_behav * * QUERY: * - * DROP itemtype itemname [, itemname ...] + * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ] + * REASSIGN OWNED BY username [, username ...] TO username + * + *****************************************************************************/ +DropOwnedStmt: + DROP OWNED BY name_list opt_drop_behavior + { + $$ = cat_str(3, make_str("drop owned by"), $4, $5); + } + ; + +ReassignOwnedStmt: + REASSIGN OWNED BY name_list TO name + { + $$ = cat_str(4, make_str("reassign owned by"), $4, make_str("to"), $6); + } + ; + +/***************************************************************************** + * + * QUERY: + * + * DROP itemtype [ IF EXISTS ] itemname [, itemname ...] [ RESTRICT | CASCADE ] * *****************************************************************************/ -DropStmt: DROP drop_type any_name_list opt_drop_behavior +DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior + { $$ = cat_str(5, make_str("drop"), $2, make_str("if exists"), $5, $6); } + | DROP drop_type any_name_list opt_drop_behavior { $$ = cat_str(4, make_str("drop"), $2, $3, $4); } ; @@ -2818,13 +2845,15 @@ alterdb_opt_item: /***************************************************************************** * - * DROP DATABASE + * DROP DATABASE [ IF EXISTS ] * * *****************************************************************************/ DropdbStmt: DROP DATABASE database_name { $$ = cat2_str(make_str("drop database"), $3); } + | DROP DATABASE IF_P EXISTS database_name + { $$ = cat2_str(make_str("drop database if exists"), $5); } ; @@ -3806,6 +3835,8 @@ a_expr: c_expr { $$ = cat2_str($1, make_str("is not unknown")); } | a_expr IS DISTINCT FROM a_expr %prec IS { $$ = cat_str(3, $1, make_str("is distinct from"), $5); } + | a_expr IS NOT DISTINCT FROM a_expr %prec IS + { $$ = cat_str(3, $1, make_str("is not distinct from"), $6); } | a_expr IS OF '(' type_list ')' %prec IS { $$ = cat_str(4, $1, make_str("is of ("), $5, make_str(")")); } | a_expr IS NOT OF '(' type_list ')' %prec IS @@ -3870,6 +3901,8 @@ b_expr: c_expr { $$ = cat2_str($1, $2); } | b_expr IS DISTINCT FROM b_expr %prec IS { $$ = cat_str(3, $1, make_str("is distinct from"), $5); } + | b_expr IS NOT DISTINCT FROM b_expr %prec IS + { $$ = cat_str(3, $1, make_str("is not distinct from"), $6); } | b_expr IS OF '(' b_expr ')' %prec IS { $$ = cat_str(4, $1, make_str("is of ("), $5, make_str(")")); } | b_expr IS NOT OF '(' b_expr ')' %prec IS @@ -6111,6 +6144,7 @@ ECPGunreserved_con: ABORT_P { $$ = make_str("abort"); } | HEADER_P { $$ = make_str("header"); } | HOLD { $$ = make_str("hold"); } /* | HOUR_P { $$ = make_str("hour"); }*/ + | IF_P { $$ = make_str("if"); } | IMMEDIATE { $$ = make_str("immediate"); } | IMMUTABLE { $$ = make_str("immutable"); } | IMPLICIT_P { $$ = make_str("implicit"); } @@ -6159,6 +6193,7 @@ ECPGunreserved_con: ABORT_P { $$ = make_str("abort"); } | OIDS { $$ = make_str("oids"); } | OPERATOR { $$ = make_str("operator"); } | OPTION { $$ = make_str("option"); } + | OWNED { $$ = make_str("owned"); } | OWNER { $$ = make_str("owner"); } | PARTIAL { $$ = make_str("partial"); } | PASSWORD { $$ = make_str("password"); } @@ -6171,6 +6206,7 @@ ECPGunreserved_con: ABORT_P { $$ = make_str("abort"); } | PROCEDURE { $$ = make_str("procedure"); } | QUOTE { $$ = make_str("quote"); } | READ { $$ = make_str("read"); } + | REASSIGN { $$ = make_str("reassign"); } | RECHECK { $$ = make_str("recheck"); } | REINDEX { $$ = make_str("reindex"); } | RELATIVE_P { $$ = make_str("relative"); } diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile index 79ac9049d6..ad14654921 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.50 2005/06/30 07:01:57 neilc Exp $ +# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.51 2006/01/24 11:01:38 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_desc + test_informix2 test_desc ifeq ($(enable_thread_safety), yes) TESTS += test_thread test_thread_implicit endif @@ -24,11 +24,17 @@ all: $(TESTS) test_informix: test_informix.o $(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq $(PTHREAD_LIBS) -o $@ +test_informix2: test_informix2.o + $(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq $(PTHREAD_LIBS) -o $@ + %.c: %.pgc $(ECPG) -o $@ -I$(srcdir) $< test_informix.c: test_informix.pgc $(ECPG) -o $@ -C INFORMIX -r no_indicator $< +test_informix2.c: test_informix2.pgc + $(ECPG) -o $@ -C INFORMIX $< + clean: rm -f $(TESTS) $(TESTS:%=%.o) $(TESTS:%=%.c) log diff --git a/src/interfaces/ecpg/test/test_informix2.pgc b/src/interfaces/ecpg/test/test_informix2.pgc new file mode 100644 index 0000000000..b95ea5076f --- /dev/null +++ b/src/interfaces/ecpg/test/test_informix2.pgc @@ -0,0 +1,123 @@ +#include +#include +#include "sqltypes.h" + +EXEC SQL include sqlca.h; + +/* Check SQLCODE, and produce a "standard error" if it's wrong! */ +static void sql_check(char *fn, char *caller, int ignore) +{ + char errorstring[255]; + + if (SQLCODE == ignore) + return; + else + { + if (SQLCODE != 0) + { + + sprintf(errorstring, "**SQL error %ld doing '%s' in function '%s'. [%s]", + SQLCODE, caller, fn, sqlca.sqlerrm.sqlerrmc); + fprintf(stderr, "%s", errorstring); + printf("%s\n", errorstring); + + /* attempt a ROLLBACK */ + EXEC SQL rollback; + + if (SQLCODE == 0) + { + sprintf(errorstring, "Rollback successful.\n"); + } else { + sprintf(errorstring, "Rollback failed with code %ld.\n", SQLCODE); + } + + fprintf(stderr, "%s", errorstring); + printf("%s\n", errorstring); + + exit(1); + } + } +} + + + +int main(void) +{ + EXEC SQL BEGIN DECLARE SECTION; + int c; + timestamp d; + timestamp maxd; + char dbname[30]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL whenever sqlerror sqlprint; + + strcpy(dbname, "mm"); + EXEC SQL connect to :dbname; + sql_check("main", "connect", 0); + + EXEC SQL create table history (customerid integer, timestamp timestamp without time zone, action_taken char(5), narrative varchar(100)); + sql_check("main", "create", 0); + + EXEC SQL insert into history + (customerid, timestamp, action_taken, narrative) + values(1, now(), 'test', 'test'); + sql_check("main", "insert", 0); + + EXEC SQL select max(timestamp) + into :maxd + from history; + sql_check("main", "select max", 100); + + if (risnull(CDTIMETYPE, (char *) &maxd)) + { + printf("Nothing on the history table\n\n"); + exit(0); + } + + EXEC SQL select customerid, timestamp + into :c, :d + from history + where timestamp = :maxd + limit 1; + sql_check("main", "select", 0); + + printf("Read in customer %d\n", c); + + /* Adding 1 to d adds 1 second. So: + 60 1 minute + 3600 1 hour + 86400 1 day */ + d=d+86400; + c++; + + EXEC SQL insert into history + (customerid, timestamp, action_taken, narrative) + values(:c, :d, 'test', 'test'); + sql_check("main", "update", 0); + + EXEC SQL commit; + + EXEC SQL drop table history; + sql_check("main", "drop", 0); + + EXEC SQL commit; + + EXEC SQL disconnect; + sql_check("main", "disconnect", 0); + + printf("All OK!\n"); + + exit(0); + +/* + Table "public.history" + Column | Type | Modifiers +--------------+-----------------------------+----------- + customerid | integer | not null + timestamp | timestamp without time zone | not null + action_taken | character(5) | not null + narrative | character varying(100) | +*/ + +} -- 2.40.0