Skip to content

Commit 69f9fab

Browse files
author
Michael Meskes
committed
- Synced parser and keyword list.
- Added another test case.
1 parent 7ccaf13 commit 69f9fab

File tree

5 files changed

+185
-12
lines changed

5 files changed

+185
-12
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,11 @@ Fr Jan 13 17:29:30 CET 2006
19711971
Tu Jan 17 18:53:03 CET 2006
19721972

19731973
- Data transferred binary is now put into the variables verbatim.
1974+
1975+
Tu Jan 24 10:59:21 CET 2006
1976+
1977+
- Synced parser and keyword list.
1978+
- Added another test case.
19741979
- Set ecpg library version to 5.2.
19751980
- Set ecpg version to 4.2.1.
19761981

src/interfaces/ecpg/preproc/keywords.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.71 2005/12/27 04:00:08 momjian Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.72 2006/01/24 11:01:37 meskes Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -158,6 +158,7 @@ static ScanKeyword ScanKeywords[] = {
158158
{"header", HEADER_P},
159159
{"hold", HOLD},
160160
{"hour", HOUR_P},
161+
{"if", IF_P},
161162
{"ilike", ILIKE},
162163
{"immediate", IMMEDIATE},
163164
{"immutable", IMMUTABLE},
@@ -246,6 +247,7 @@ static ScanKeyword ScanKeywords[] = {
246247
{"out", OUT_P},
247248
{"outer", OUTER_P},
248249
{"overlaps", OVERLAPS},
250+
{"owned", OWNED},
249251
{"owner", OWNER},
250252
{"partial", PARTIAL},
251253
{"password", PASSWORD},
@@ -262,6 +264,7 @@ static ScanKeyword ScanKeywords[] = {
262264
{"quote", QUOTE},
263265
{"read", READ},
264266
{"real", REAL},
267+
{"reassign", REASSIGN},
265268
{"recheck", RECHECK},
266269
{"references", REFERENCES},
267270
{"reindex", REINDEX},

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.315 2005/12/29 04:53:18 neilc Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.316 2006/01/24 11:01:37 meskes Exp $ */
22

33
/* Copyright comment */
44
%{
@@ -377,7 +377,7 @@ add_additional_variables(char *name, bool insert)
377377

378378
HANDLER HAVING HEADER_P HOLD HOUR_P
379379

380-
ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT
380+
IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT
381381
INDEX INHERIT INHERITS INITIALLY INNER_P INOUT INPUT_P
382382
INSENSITIVE INSERT INSTEAD INT_P INTEGER INTERSECT
383383
INTERVAL INTO INVOKER IS ISNULL ISOLATION
@@ -397,15 +397,15 @@ add_additional_variables(char *name, bool insert)
397397
NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NUMERIC
398398

399399
OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR ORDER
400-
OUT_P OUTER_P OVERLAPS OVERLAY OWNER
400+
OUT_P OUTER_P OVERLAPS OVERLAY OWNED OWNER
401401

402402
PARTIAL PASSWORD PLACING POSITION
403403
PRECISION PRESERVE PREPARE PREPARED PRIMARY
404404
PRIOR PRIVILEGES PROCEDURAL PROCEDURE
405405

406406
QUOTE
407407

408-
READ REAL RECHECK REFERENCES REINDEX RELATIVE_P RELEASE RENAME
408+
READ REAL REASSIGN RECHECK REFERENCES REINDEX RELATIVE_P RELEASE RENAME
409409
REPEATABLE REPLACE RESET RESTART RESTRICT RETURNS REVOKE RIGHT
410410
ROLE ROLLBACK ROW ROWS RULE
411411

@@ -520,7 +520,7 @@ add_additional_variables(char *name, bool insert)
520520
%type <str> ViewStmt LoadStmt CreatedbStmt createdb_opt_item ExplainableStmt
521521
%type <str> createdb_opt_list opt_encoding OptInherit opt_equal
522522
%type <str> privilege_list privilege privilege_target
523-
%type <str> opt_grant_grant_option cursor_options
523+
%type <str> opt_grant_grant_option cursor_options DropOwnedStmt
524524
%type <str> transaction_mode_list_or_empty transaction_mode_list
525525
%type <str> function_with_argtypes_list function_with_argtypes IntConstVar
526526
%type <str> DropdbStmt ClusterStmt grantee RevokeStmt Bit DropOpClassStmt
@@ -531,7 +531,7 @@ add_additional_variables(char *name, bool insert)
531531
%type <str> ConstraintTimeSpec AlterDatabaseSetStmt DropAssertStmt
532532
%type <str> select_offset_value ReindexStmt join_type opt_boolean
533533
%type <str> join_qual joined_table opclass_item
534-
%type <str> lock_type array_expr_list
534+
%type <str> lock_type array_expr_list ReassignOwnedStmt
535535
%type <str> OptConstrFromTable OptTempTableName StringConst array_expr
536536
%type <str> constraints_set_mode comment_type
537537
%type <str> CreateGroupStmt AlterGroupStmt DropGroupStmt key_delete
@@ -698,6 +698,7 @@ stmt: AlterDatabaseStmt { output_statement($1, 0, connection); }
698698
| DropCastStmt { output_statement($1, 0, connection); }
699699
| DropGroupStmt { output_statement($1, 0, connection); }
700700
| DropOpClassStmt { output_statement($1, 0, connection); }
701+
| DropOwnedStmt { output_statement($1, 0, connection); }
701702
| DropPLangStmt { output_statement($1, 0, connection); }
702703
| DropRoleStmt { output_statement($1, 0, connection); }
703704
| DropRuleStmt { output_statement($1, 0, connection); }
@@ -718,6 +719,7 @@ stmt: AlterDatabaseStmt { output_statement($1, 0, connection); }
718719
| LockStmt { output_statement($1, 0, connection); }
719720
| NotifyStmt { output_statement($1, 0, connection); }
720721
/* | PrepareStmt { output_statement($1, 0, connection); }*/
722+
| ReassignOwnedStmt { output_statement($1, 0, connection); }
721723
| ReindexStmt { output_statement($1, 0, connection); }
722724
| RemoveAggrStmt { output_statement($1, 0, connection); }
723725
| RemoveOperStmt { output_statement($1, 0, connection); }
@@ -924,6 +926,7 @@ opt_with: WITH { $$ = make_str("with"); }
924926
*/
925927
OptRoleList:
926928
PASSWORD Sconst { $$ = cat2_str(make_str("password"), $2); }
929+
| PASSWORD NULL_P { $$ = make_str("password null"); }
927930
| ENCRYPTED PASSWORD Sconst { $$ = cat2_str(make_str("encrypted password"), $3); }
928931
| UNENCRYPTED PASSWORD Sconst { $$ = cat2_str(make_str("unencrypted password"), $3); }
929932
| SUPERUSER_P { $$ = make_str("superuser"); }
@@ -1995,11 +1998,35 @@ DropOpClassStmt: DROP OPERATOR CLASS any_name USING access_method opt_drop_behav
19951998
*
19961999
* QUERY:
19972000
*
1998-
* DROP itemtype itemname [, itemname ...]
2001+
* DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
2002+
* REASSIGN OWNED BY username [, username ...] TO username
2003+
*
2004+
*****************************************************************************/
2005+
DropOwnedStmt:
2006+
DROP OWNED BY name_list opt_drop_behavior
2007+
{
2008+
$$ = cat_str(3, make_str("drop owned by"), $4, $5);
2009+
}
2010+
;
2011+
2012+
ReassignOwnedStmt:
2013+
REASSIGN OWNED BY name_list TO name
2014+
{
2015+
$$ = cat_str(4, make_str("reassign owned by"), $4, make_str("to"), $6);
2016+
}
2017+
;
2018+
2019+
/*****************************************************************************
2020+
*
2021+
* QUERY:
2022+
*
2023+
* DROP itemtype [ IF EXISTS ] itemname [, itemname ...] [ RESTRICT | CASCADE ]
19992024
*
20002025
*****************************************************************************/
20012026

2002-
DropStmt: DROP drop_type any_name_list opt_drop_behavior
2027+
DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
2028+
{ $$ = cat_str(5, make_str("drop"), $2, make_str("if exists"), $5, $6); }
2029+
| DROP drop_type any_name_list opt_drop_behavior
20032030
{ $$ = cat_str(4, make_str("drop"), $2, $3, $4); }
20042031
;
20052032

@@ -2818,13 +2845,15 @@ alterdb_opt_item:
28182845

28192846
/*****************************************************************************
28202847
*
2821-
* DROP DATABASE
2848+
* DROP DATABASE [ IF EXISTS ]
28222849
*
28232850
*
28242851
*****************************************************************************/
28252852

28262853
DropdbStmt: DROP DATABASE database_name
28272854
{ $$ = cat2_str(make_str("drop database"), $3); }
2855+
| DROP DATABASE IF_P EXISTS database_name
2856+
{ $$ = cat2_str(make_str("drop database if exists"), $5); }
28282857
;
28292858

28302859

@@ -3806,6 +3835,8 @@ a_expr: c_expr
38063835
{ $$ = cat2_str($1, make_str("is not unknown")); }
38073836
| a_expr IS DISTINCT FROM a_expr %prec IS
38083837
{ $$ = cat_str(3, $1, make_str("is distinct from"), $5); }
3838+
| a_expr IS NOT DISTINCT FROM a_expr %prec IS
3839+
{ $$ = cat_str(3, $1, make_str("is not distinct from"), $6); }
38093840
| a_expr IS OF '(' type_list ')' %prec IS
38103841
{ $$ = cat_str(4, $1, make_str("is of ("), $5, make_str(")")); }
38113842
| a_expr IS NOT OF '(' type_list ')' %prec IS
@@ -3870,6 +3901,8 @@ b_expr: c_expr
38703901
{ $$ = cat2_str($1, $2); }
38713902
| b_expr IS DISTINCT FROM b_expr %prec IS
38723903
{ $$ = cat_str(3, $1, make_str("is distinct from"), $5); }
3904+
| b_expr IS NOT DISTINCT FROM b_expr %prec IS
3905+
{ $$ = cat_str(3, $1, make_str("is not distinct from"), $6); }
38733906
| b_expr IS OF '(' b_expr ')' %prec IS
38743907
{ $$ = cat_str(4, $1, make_str("is of ("), $5, make_str(")")); }
38753908
| b_expr IS NOT OF '(' b_expr ')' %prec IS
@@ -6111,6 +6144,7 @@ ECPGunreserved_con: ABORT_P { $$ = make_str("abort"); }
61116144
| HEADER_P { $$ = make_str("header"); }
61126145
| HOLD { $$ = make_str("hold"); }
61136146
/* | HOUR_P { $$ = make_str("hour"); }*/
6147+
| IF_P { $$ = make_str("if"); }
61146148
| IMMEDIATE { $$ = make_str("immediate"); }
61156149
| IMMUTABLE { $$ = make_str("immutable"); }
61166150
| IMPLICIT_P { $$ = make_str("implicit"); }
@@ -6159,6 +6193,7 @@ ECPGunreserved_con: ABORT_P { $$ = make_str("abort"); }
61596193
| OIDS { $$ = make_str("oids"); }
61606194
| OPERATOR { $$ = make_str("operator"); }
61616195
| OPTION { $$ = make_str("option"); }
6196+
| OWNED { $$ = make_str("owned"); }
61626197
| OWNER { $$ = make_str("owner"); }
61636198
| PARTIAL { $$ = make_str("partial"); }
61646199
| PASSWORD { $$ = make_str("password"); }
@@ -6171,6 +6206,7 @@ ECPGunreserved_con: ABORT_P { $$ = make_str("abort"); }
61716206
| PROCEDURE { $$ = make_str("procedure"); }
61726207
| QUOTE { $$ = make_str("quote"); }
61736208
| READ { $$ = make_str("read"); }
6209+
| REASSIGN { $$ = make_str("reassign"); }
61746210
| RECHECK { $$ = make_str("recheck"); }
61756211
| REINDEX { $$ = make_str("reindex"); }
61766212
| RELATIVE_P { $$ = make_str("relative"); }

src/interfaces/ecpg/test/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.50 2005/06/30 07:01:57 neilc Exp $
1+
# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.51 2006/01/24 11:01:38 meskes Exp $
22

33
subdir = src/interfaces/ecpg/test
44
top_builddir = ../../../..
@@ -11,7 +11,7 @@ ECPG = ../preproc/ecpg -I$(srcdir)/../include
1111

1212
TESTS = test1 test2 test3 test4 test5 perftest dyntest dyntest2 test_notice \
1313
test_code100 test_init testdynalloc num_test dt_test test_informix \
14-
test_desc
14+
test_informix2 test_desc
1515
ifeq ($(enable_thread_safety), yes)
1616
TESTS += test_thread test_thread_implicit
1717
endif
@@ -24,11 +24,17 @@ all: $(TESTS)
2424
test_informix: test_informix.o
2525
$(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq $(PTHREAD_LIBS) -o $@
2626

27+
test_informix2: test_informix2.o
28+
$(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq $(PTHREAD_LIBS) -o $@
29+
2730
%.c: %.pgc
2831
$(ECPG) -o $@ -I$(srcdir) $<
2932

3033
test_informix.c: test_informix.pgc
3134
$(ECPG) -o $@ -C INFORMIX -r no_indicator $<
3235

36+
test_informix2.c: test_informix2.pgc
37+
$(ECPG) -o $@ -C INFORMIX $<
38+
3339
clean:
3440
rm -f $(TESTS) $(TESTS:%=%.o) $(TESTS:%=%.c) log
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "sqltypes.h"
4+
5+
EXEC SQL include sqlca.h;
6+
7+
/* Check SQLCODE, and produce a "standard error" if it's wrong! */
8+
static void sql_check(char *fn, char *caller, int ignore)
9+
{
10+
char errorstring[255];
11+
12+
if (SQLCODE == ignore)
13+
return;
14+
else
15+
{
16+
if (SQLCODE != 0)
17+
{
18+
19+
sprintf(errorstring, "**SQL error %ld doing '%s' in function '%s'. [%s]",
20+
SQLCODE, caller, fn, sqlca.sqlerrm.sqlerrmc);
21+
fprintf(stderr, "%s", errorstring);
22+
printf("%s\n", errorstring);
23+
24+
/* attempt a ROLLBACK */
25+
EXEC SQL rollback;
26+
27+
if (SQLCODE == 0)
28+
{
29+
sprintf(errorstring, "Rollback successful.\n");
30+
} else {
31+
sprintf(errorstring, "Rollback failed with code %ld.\n", SQLCODE);
32+
}
33+
34+
fprintf(stderr, "%s", errorstring);
35+
printf("%s\n", errorstring);
36+
37+
exit(1);
38+
}
39+
}
40+
}
41+
42+
43+
44+
int main(void)
45+
{
46+
EXEC SQL BEGIN DECLARE SECTION;
47+
int c;
48+
timestamp d;
49+
timestamp maxd;
50+
char dbname[30];
51+
EXEC SQL END DECLARE SECTION;
52+
53+
EXEC SQL whenever sqlerror sqlprint;
54+
55+
strcpy(dbname, "mm");
56+
EXEC SQL connect to :dbname;
57+
sql_check("main", "connect", 0);
58+
59+
EXEC SQL create table history (customerid integer, timestamp timestamp without time zone, action_taken char(5), narrative varchar(100));
60+
sql_check("main", "create", 0);
61+
62+
EXEC SQL insert into history
63+
(customerid, timestamp, action_taken, narrative)
64+
values(1, now(), 'test', 'test');
65+
sql_check("main", "insert", 0);
66+
67+
EXEC SQL select max(timestamp)
68+
into :maxd
69+
from history;
70+
sql_check("main", "select max", 100);
71+
72+
if (risnull(CDTIMETYPE, (char *) &maxd))
73+
{
74+
printf("Nothing on the history table\n\n");
75+
exit(0);
76+
}
77+
78+
EXEC SQL select customerid, timestamp
79+
into :c, :d
80+
from history
81+
where timestamp = :maxd
82+
limit 1;
83+
sql_check("main", "select", 0);
84+
85+
printf("Read in customer %d\n", c);
86+
87+
/* Adding 1 to d adds 1 second. So:
88+
60 1 minute
89+
3600 1 hour
90+
86400 1 day */
91+
d=d+86400;
92+
c++;
93+
94+
EXEC SQL insert into history
95+
(customerid, timestamp, action_taken, narrative)
96+
values(:c, :d, 'test', 'test');
97+
sql_check("main", "update", 0);
98+
99+
EXEC SQL commit;
100+
101+
EXEC SQL drop table history;
102+
sql_check("main", "drop", 0);
103+
104+
EXEC SQL commit;
105+
106+
EXEC SQL disconnect;
107+
sql_check("main", "disconnect", 0);
108+
109+
printf("All OK!\n");
110+
111+
exit(0);
112+
113+
/*
114+
Table "public.history"
115+
Column | Type | Modifiers
116+
--------------+-----------------------------+-----------
117+
customerid | integer | not null
118+
timestamp | timestamp without time zone | not null
119+
action_taken | character(5) | not null
120+
narrative | character varying(100) |
121+
*/
122+
123+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy