Changeset: f40a81af1dc5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f40a81af1dc5
Modified Files:
clients/mapiclient/mhelp.c
monetdb5/modules/mal/wlc.mal
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_cat.c
sql/backends/monet5/sql_statement.c
sql/backends/monet5/sqlcatalog.mal
sql/backends/monet5/wlr.mal
sql/include/sql_relation.h
sql/server/rel_schema.c
sql/server/sql_parser.y
sql/test/pg_regress/Tests/alter_table.stable.err
sql/test/pg_regress/Tests/float8.stable.err.int128
sql/test/pg_regress/Tests/insert.stable.err
Branch: sqlextra
Log Message:
Cleaned IF [NOT] EXISTS clauses handling in the server. Also added IF EXISTS
clause for CREATE VIEWS
diffs (truncated from 708 to 300 lines):
diff --git a/clients/mapiclient/mhelp.c b/clients/mapiclient/mhelp.c
--- a/clients/mapiclient/mhelp.c
+++ b/clients/mapiclient/mhelp.c
@@ -214,7 +214,8 @@ SQLhelp sqlhelp[] = {
NULL},
{"CREATE VIEW",
"",
- "CREATE VIEW qname [ column_list ] AS { query_expression | '('
query_expression ') } [ WITH CHECK OPTION ]",
+ "CREATE VIEW [ IF NOT EXISTS ] qname [ column_list ] AS {
query_expression | '(' query_expression ') }\n"
+ "[ WITH CHECK OPTION ]",
"column_list,query_expression",
NULL},
{"CURRENT_DATE",
diff --git a/monetdb5/modules/mal/wlc.mal b/monetdb5/modules/mal/wlc.mal
--- a/monetdb5/modules/mal/wlc.mal
+++ b/monetdb5/modules/mal/wlc.mal
@@ -95,15 +95,11 @@ pattern drop_seq( sname:str, nme:str, ac
address WLCgeneric
comment "Catalog operation drop_seq";
-pattern create_schema(sname:str, auth:str, action:int)
+pattern create_schema(sname:str, auth:str, ifnotexists:int, action:int)
address WLCgeneric
comment "Catalog operation create_schema";
-pattern drop_schema( sname:str, s:str, action:int, ifexists:int)
-address WLCgeneric
-comment "Catalog operation drop_schema";
-
-pattern drop_schema( sname:str, s:str, action:int)
+pattern drop_schema( sname:str, s:str, ifexists:int, action:int)
address WLCgeneric
comment "Catalog operation drop_schema";
@@ -115,11 +111,7 @@ pattern create_view(sname:str, tname:str
address WLCgeneric
comment "Catalog operation create_view";
-pattern drop_table( sname:str, name:str, action:int , ifexists:int)
-address WLCgeneric
-comment "Catalog operation drop_table";
-
-pattern drop_table( sname:str, name:str, action:int )
+pattern drop_table( sname:str, name:str, action:int, ifexists:int)
address WLCgeneric
comment "Catalog operation drop_table";
@@ -127,11 +119,7 @@ pattern drop_view( sname:str, name:str,
address WLCgeneric
comment "Catalog operation drop_view";
-pattern drop_view( sname:str, name:str, action:int)
-address WLCgeneric
-comment "Catalog operation drop_view";
-
-pattern drop_constraint( sname:str, name:str, action:int)
+pattern drop_constraint( sname:str, name:str, action:int, ifexists:int)
address WLCgeneric
comment "Catalog operation drop_constraint";
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -4726,7 +4726,7 @@ rel2bin_catalog(backend *be, sql_rel *re
mvc *sql = be->mvc;
node *en = rel->exps->h;
stmt *action = exp_bin(be, en->data, NULL, NULL, NULL, NULL, NULL,
NULL);
- stmt *sname = NULL, *name = NULL;
+ stmt *sname = NULL, *name = NULL, *ifexists = NULL;
list *l = sa_list(sql->sa);
(void)refs;
@@ -4737,8 +4737,14 @@ rel2bin_catalog(backend *be, sql_rel *re
} else {
name = stmt_atom_string_nil(be);
}
+ if (en->next && en->next->next) {
+ ifexists = exp_bin(be, en->next->next->data, NULL, NULL, NULL,
NULL, NULL, NULL);
+ } else {
+ ifexists = stmt_atom_int(be, 0);
+ }
append(l, sname);
append(l, name);
+ append(l, ifexists);
append(l, action);
return stmt_catalog(be, rel->flag, stmt_list(be, l));
}
@@ -4749,7 +4755,7 @@ rel2bin_catalog_table(backend *be, sql_r
mvc *sql = be->mvc;
node *en = rel->exps->h;
stmt *action = exp_bin(be, en->data, NULL, NULL, NULL, NULL, NULL,
NULL);
- stmt *table = NULL, *sname, *tname = NULL;
+ stmt *table = NULL, *sname, *tname = NULL, *ifexists = NULL;
list *l = sa_list(sql->sa);
(void)refs;
@@ -4760,13 +4766,22 @@ rel2bin_catalog_table(backend *be, sql_r
tname = exp_bin(be, en->data, NULL, NULL, NULL, NULL, NULL,
NULL);
en = en->next;
}
- if (en)
- table = exp_bin(be, en->data, NULL, NULL, NULL, NULL, NULL,
NULL);
append(l, sname);
assert(tname);
append(l, tname);
- if (rel->flag != DDL_DROP_TABLE && rel->flag !=
DDL_DROP_TABLE_IF_EXISTS && rel->flag != DDL_DROP_VIEW && rel->flag !=
DDL_DROP_VIEW_IF_EXISTS && rel->flag != DDL_DROP_CONSTRAINT)
+ if (rel->flag != DDL_DROP_TABLE && rel->flag != DDL_DROP_VIEW &&
rel->flag != DDL_DROP_CONSTRAINT) {
+ if (en) {
+ table = exp_bin(be, en->data, NULL, NULL, NULL, NULL,
NULL, NULL);
+ }
append(l, table);
+ } else {
+ if (en) {
+ ifexists = exp_bin(be, en->data, NULL, NULL, NULL,
NULL, NULL, NULL);
+ } else {
+ ifexists = stmt_atom_int(be, 0);
+ }
+ append(l, ifexists);
+ }
append(l, action);
return stmt_catalog(be, rel->flag, stmt_list(be, l));
}
diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -812,7 +812,7 @@ str
SQLcreate_schema(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{ mvc *sql = NULL;
str msg;
- str sname = *getArgReference_str(stk, pci, 1);
+ str sname = *getArgReference_str(stk, pci, 1);
str name = SaveArgReference(stk, pci, 2);
int auth_id;
@@ -837,14 +837,11 @@ SQLdrop_schema(Client cntxt, MalBlkPtr m
{ mvc *sql = NULL;
str msg= MAL_SUCCEED;
str sname = *getArgReference_str(stk, pci, 1);
- str notused = *getArgReference_str(stk, pci, 2);
- int action = *getArgReference_int(stk, pci, 3);
- int if_exists = 0; // should become an argument
+ str notused = *getArgReference_str(stk, pci, 2);
+ int if_exists = *getArgReference_int(stk, pci, 3);
+ int action = *getArgReference_int(stk, pci, 4);
sql_schema *s;
- if( pci->argc > 4)
- if_exists = *getArgReference_int(stk, pci, 4);
-
(void) notused;
initcontext();
s = mvc_bind_schema(sql, sname);
@@ -869,7 +866,7 @@ str
SQLcreate_table(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{ mvc *sql = NULL;
str msg;
- str sname = *getArgReference_str(stk, pci, 1);
+ str sname = *getArgReference_str(stk, pci, 1);
str tname = *getArgReference_str(stk, pci, 2);
sql_table *t = *(sql_table **) getArgReference(stk, pci, 3);
int temp = *getArgReference_int(stk, pci, 4);
@@ -883,7 +880,7 @@ str
SQLcreate_view(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{ mvc *sql = NULL;
str msg;
- str sname = *getArgReference_str(stk, pci, 1);
+ str sname = *getArgReference_str(stk, pci, 1);
str vname = *getArgReference_str(stk, pci, 2);
sql_table *t = *(sql_table **) getArgReference(stk, pci, 3);
int temp = *getArgReference_int(stk, pci, 4);
@@ -897,15 +894,12 @@ str
SQLdrop_table(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{ mvc *sql = NULL;
str msg;
- str sname = *getArgReference_str(stk, pci, 1);
+ str sname = *getArgReference_str(stk, pci, 1);
str name = *getArgReference_str(stk, pci, 2);
- int action = *getArgReference_int(stk, pci, 3);
- int if_exists = 0; // should become an argument
+ int if_exists = *getArgReference_int(stk, pci, 3);
+ int action = *getArgReference_int(stk, pci, 4);
initcontext();
- if( pci->argc > 4)
- if_exists = *getArgReference_int(stk, pci, 4);
-
msg = drop_table(sql, sname, name, action, if_exists);
return msg;
}
@@ -914,15 +908,12 @@ str
SQLdrop_view(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{ mvc *sql = NULL;
str msg;
- str sname = *getArgReference_str(stk, pci, 1);
+ str sname = *getArgReference_str(stk, pci, 1);
str name = *getArgReference_str(stk, pci, 2);
- int action = *getArgReference_int(stk, pci, 3);
- int if_exists = 0; // should become an argument
+ int if_exists = *getArgReference_int(stk, pci, 3);
+ int action = *getArgReference_int(stk, pci, 4);
initcontext();
- if( pci->argc > 4)
- if_exists = *getArgReference_int(stk, pci, 4);
-
msg = drop_view(sql, sname, name, action, if_exists);
return msg;
}
@@ -931,13 +922,13 @@ str
SQLdrop_constraint(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{ mvc *sql = NULL;
str msg;
- str sname = *getArgReference_str(stk, pci, 1);
+ str sname = *getArgReference_str(stk, pci, 1);
str name = *getArgReference_str(stk, pci, 2);
- int action = *getArgReference_int(stk, pci, 3);
+ int action = *getArgReference_int(stk, pci, 4);
+ (void) *getArgReference_int(stk, pci, 3); //the if_exists parameter is
also passed but not used
initcontext();
msg = drop_key(sql, sname, name, action);
-
return msg;
}
diff --git a/sql/backends/monet5/sql_statement.c
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -2119,7 +2119,6 @@ stmt_catalog(backend *be, int type, stmt
MalBlkPtr mb = be->mb;
InstrPtr q = NULL;
node *n;
- int if_exists =0;
if (args->nr < 0)
return NULL;
@@ -2130,16 +2129,10 @@ stmt_catalog(backend *be, int type, stmt
case DDL_ALTER_SEQ: q = newStmt(mb, sqlcatalogRef, alter_seqRef);
break;
case DDL_DROP_SEQ: q = newStmt(mb, sqlcatalogRef, drop_seqRef);
break;
case DDL_CREATE_SCHEMA: q = newStmt(mb, sqlcatalogRef,
create_schemaRef); break;
- case DDL_DROP_SCHEMA_IF_EXISTS: if_exists =1;
- /* fall through */
case DDL_DROP_SCHEMA: q = newStmt(mb, sqlcatalogRef, drop_schemaRef);
break;
case DDL_CREATE_TABLE: q = newStmt(mb, sqlcatalogRef,
create_tableRef); break;
case DDL_CREATE_VIEW: q = newStmt(mb, sqlcatalogRef, create_viewRef);
break;
- case DDL_DROP_TABLE_IF_EXISTS: if_exists =1;
- /* fall through */
case DDL_DROP_TABLE: q = newStmt(mb, sqlcatalogRef, drop_tableRef);
break;
- case DDL_DROP_VIEW_IF_EXISTS: if_exists = 1;
- /* fall through */
case DDL_DROP_VIEW: q = newStmt(mb, sqlcatalogRef, drop_viewRef);
break;
case DDL_DROP_CONSTRAINT: q = newStmt(mb, sqlcatalogRef,
drop_constraintRef); break;
case DDL_ALTER_TABLE: q = newStmt(mb, sqlcatalogRef, alter_tableRef);
break;
@@ -2176,9 +2169,6 @@ stmt_catalog(backend *be, int type, stmt
}
if (q) {
stmt *s = stmt_create(be->mvc->sa, st_catalog);
-
- if( if_exists)
- pushInt(mb,q,1);
s->op1 = args;
s->flag = type;
s->q = q;
diff --git a/sql/backends/monet5/sqlcatalog.mal
b/sql/backends/monet5/sqlcatalog.mal
--- a/sql/backends/monet5/sqlcatalog.mal
+++ b/sql/backends/monet5/sqlcatalog.mal
@@ -4,7 +4,7 @@
#
# Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V.
-# All functions eturn a void and this are unsafe, having side effects.
+# All functions return a void and this are unsafe, having side effects.
module sqlcatalog;
pattern create_seq( sname:str, seqname:str, seq:ptr, action:int)
@@ -19,15 +19,11 @@ pattern drop_seq( sname:str, nme:str, ac
address SQLdrop_seq
comment "Catalog operation drop_seq";
-pattern create_schema(sname:str, auth:str, action:int)
+pattern create_schema(sname:str, auth:str, ifnotexists:int, action:int)
address SQLcreate_schema
comment "Catalog operation create_schema";
-pattern drop_schema( sname:str, s:str, action:int, ifexists:int)
-address SQLdrop_schema
-comment "Catalog operation drop_schema";
-
-pattern drop_schema( sname:str, s:str, action:int)
+pattern drop_schema( sname:str, s:str, ifexists:int, action:int)
address SQLdrop_schema
comment "Catalog operation drop_schema";
@@ -39,23 +35,15 @@ pattern create_view(sname:str, vname:str
address SQLcreate_view
comment "Catalog operation create_view";
-pattern drop_table( sname:str, name:str, action:int , ifexists:int)
-address SQLdrop_table
-comment "Catalog operation drop_table";
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list