-/* $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 */
%{
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
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
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
%type <str> ViewStmt LoadStmt CreatedbStmt createdb_opt_item ExplainableStmt
%type <str> createdb_opt_list opt_encoding OptInherit opt_equal
%type <str> privilege_list privilege privilege_target
-%type <str> opt_grant_grant_option cursor_options
+%type <str> opt_grant_grant_option cursor_options DropOwnedStmt
%type <str> transaction_mode_list_or_empty transaction_mode_list
%type <str> function_with_argtypes_list function_with_argtypes IntConstVar
%type <str> DropdbStmt ClusterStmt grantee RevokeStmt Bit DropOpClassStmt
%type <str> ConstraintTimeSpec AlterDatabaseSetStmt DropAssertStmt
%type <str> select_offset_value ReindexStmt join_type opt_boolean
%type <str> join_qual joined_table opclass_item
-%type <str> lock_type array_expr_list
+%type <str> lock_type array_expr_list ReassignOwnedStmt
%type <str> OptConstrFromTable OptTempTableName StringConst array_expr
%type <str> constraints_set_mode comment_type
%type <str> CreateGroupStmt AlterGroupStmt DropGroupStmt key_delete
| 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); }
| 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); }
*/
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"); }
*
* 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); }
;
/*****************************************************************************
*
- * 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); }
;
{ $$ = 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
{ $$ = 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
| 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"); }
| 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"); }
| 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"); }
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#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) |
+*/
+
+}