Changeset: 381443e4f5d4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=381443e4f5d4
Modified Files:
sql/server/rel_schema.c
sql/server/rel_select.c
sql/server/sql_privileges.c
sql/server/sql_semantic.c
sql/test/miscellaneous/Tests/simple_selects.sql
sql/test/miscellaneous/Tests/simple_selects.stable.err
Branch: Nov2019
Log Message:
If a specified schema is not found, throw the respective error
diffs (truncated from 630 to 300 lines):
diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -197,7 +197,6 @@ mvc_create_table_as_subquery( mvc *sql,
sql_table *t = mvc_create_table(sql, s, tname, tt, 0,
SQL_DECLARED_TABLE, commit_action, -1, 0);
if (as_subquery( sql, t, sq, column_spec, "CREATE TABLE") != 0)
-
return NULL;
return t;
}
@@ -358,9 +357,12 @@ column_constraint_type(mvc *sql, char *n
}
*/
- if (rsname)
- rs = mvc_bind_schema(sql, rsname);
- else
+ if (rsname) {
+ if (!(rs = mvc_bind_schema(sql, rsname))) {
+ (void) sql_error(sql, 02, SQLSTATE(3F000)
"CONSTRAINT FOREIGN KEY: no such schema '%s'", rsname);
+ return res;
+ }
+ } else
rs = cur_schema(sql);
rt = _bind_table(t, ss, rs, rtname);
if (!rt) {
@@ -531,9 +533,13 @@ table_foreign_key(mvc *sql, char *name,
sql_schema *fs;
sql_table *ft;
- if (rsname)
- fs = mvc_bind_schema(sql, rsname);
- else
+
+ if (rsname) {
+ if (!(fs = mvc_bind_schema(sql, rsname))) {
+ (void) sql_error(sql, 02, SQLSTATE(3F000) "CONSTRAINT
FOREIGN KEY: no such schema '%s'", rsname);
+ return SQL_ERR;
+ }
+ } else
fs = ss;
ft = mvc_bind_table(sql, fs, rtname);
/* self referenced table */
@@ -1164,7 +1170,7 @@ rel_create_view(sql_query *query, sql_sc
mvc *sql = query->sql;
char *name = qname_table(qname);
char *sname = qname_schema(qname);
- sql_schema *s = NULL;
+ sql_schema *s = cur_schema(sql);
sql_table *t = NULL;
int instantiate = (sql->emode == m_instantiate || !persistent);
int deps = (sql->emode == m_deps);
@@ -1175,12 +1181,9 @@ rel_create_view(sql_query *query, sql_sc
(void) check; /* Stefan: unused!? */
if (sname && !(s = mvc_bind_schema(sql, sname)))
return sql_error(sql, 02, SQLSTATE(3F000) "CREATE VIEW: no such
schema '%s'", sname);
- if (s == NULL)
- s = cur_schema(sql);
- if (create && (!mvc_schema_privs(sql, s) && !(isTempSchema(s) &&
persistent == SQL_LOCAL_TEMP))) {
+ if (create && (!mvc_schema_privs(sql, s) && !(isTempSchema(s) &&
persistent == SQL_LOCAL_TEMP)))
return sql_error(sql, 02, SQLSTATE(42000) "%s VIEW: access
denied for %s to schema '%s'", base, stack_get_string(sql, "current_user"),
s->base.name);
- }
if (create && (t = mvc_bind_table(sql, s, name)) != NULL) {
if (replace) {
@@ -1302,12 +1305,10 @@ rel_drop_type(mvc *sql, dlist *qname, in
{
char *name = qname_table(qname);
char *sname = qname_schema(qname);
- sql_schema *s = NULL;
+ sql_schema *s = cur_schema(sql);
if (sname && !(s = mvc_bind_schema(sql, sname)))
return sql_error(sql, 02, SQLSTATE(3F000) "DROP TYPE: no such
schema '%s'", sname);
- if (s == NULL)
- s = cur_schema(sql);
if (schema_bind_type(sql, s, name) == NULL) {
return sql_error(sql, 02, SQLSTATE(42S01) "DROP TYPE: type '%s'
does not exist", name);
@@ -1322,12 +1323,10 @@ rel_create_type(mvc *sql, dlist *qname,
{
char *name = qname_table(qname);
char *sname = qname_schema(qname);
- sql_schema *s = NULL;
+ sql_schema *s = cur_schema(sql);
if (sname && !(s = mvc_bind_schema(sql, sname)))
return sql_error(sql, 02, SQLSTATE(3F000) "CREATE TYPE: no such
schema '%s'", sname);
- if (s == NULL)
- s = cur_schema(sql);
if (schema_bind_type(sql, s, name) != NULL) {
return sql_error(sql, 02, SQLSTATE(42S01) "CREATE TYPE: name
'%s' already in use", name);
@@ -1466,16 +1465,14 @@ sql_alter_table(sql_query *query, dlist
mvc *sql = query->sql;
char *sname = qname_schema(qname);
char *tname = qname_table(qname);
- sql_schema *s = NULL;
+ sql_schema *s = cur_schema(sql);
sql_table *t = NULL;
- if (sname && !(s=mvc_bind_schema(sql, sname))) {
- if(if_exists)
+ if (sname && !(s = mvc_bind_schema(sql, sname))) {
+ if (if_exists)
return rel_psm_block(sql->sa, new_exp_list(sql->sa));
return sql_error(sql, 02, SQLSTATE(3F000) "ALTER TABLE: no such
schema '%s'", sname);
}
- if (!s)
- s = cur_schema(sql);
if ((t = mvc_bind_table(sql, s, tname)) == NULL) {
if (mvc_bind_table(sql, mvc_bind_schema(sql, "tmp"), tname) !=
NULL)
@@ -1867,9 +1864,10 @@ rel_grant_func(mvc *sql, sql_schema *cur
sql_schema *s = NULL;
sql_func *func = NULL;
- if (sname)
- s = mvc_bind_schema(sql, sname);
- else
+ if (sname) {
+ if (!(s = mvc_bind_schema(sql, sname)))
+ return sql_error(sql, 02, SQLSTATE(3F000) "GRANT: no
such schema '%s'", sname);
+ } else
s = cur;
func = resolve_func(sql, s, fname, typelist, type, "GRANT", 0);
if (!func)
@@ -1919,9 +1917,9 @@ rel_grant_privs(mvc *sql, sql_schema *cu
char *tname = qname_table(qname);
sql_schema *s = cur;
- if (sname)
- s = mvc_bind_schema(sql, sname);
- if (s && mvc_bind_table(sql, s, tname) != NULL)
+ if (sname && !(s = mvc_bind_schema(sql, sname)))
+ return sql_error(sql, 02, SQLSTATE(3F000) "GRANT: no
such schema '%s'", sname);
+ if (s && mvc_bind_table(sql, s, tname))
token = SQL_TABLE;
}
@@ -2049,12 +2047,12 @@ rel_revoke_func(mvc *sql, sql_schema *cu
char *sname = qname_schema(qname);
char *fname = qname_func(qname);
sql_func *func = NULL;
-
sql_schema *s = NULL;
- if (sname)
- s = mvc_bind_schema(sql, sname);
- else
+ if (sname) {
+ if (sname && !(s = mvc_bind_schema(sql, sname)))
+ return sql_error(sql, 02, SQLSTATE(3F000) "REVOKE: no
such schema '%s'", sname);
+ } else
s = cur;
func = resolve_func(sql, s, fname, typelist, type, "REVOKE", 0);
if (!func)
@@ -2103,9 +2101,9 @@ rel_revoke_privs(mvc *sql, sql_schema *c
char *tname = qname_table(qname);
sql_schema *s = cur;
- if (sname)
- s = mvc_bind_schema(sql, sname);
- if (s && mvc_bind_table(sql, s, tname) != NULL)
+ if (sname && !(s = mvc_bind_schema(sql, sname)))
+ return sql_error(sql, 02, SQLSTATE(3F000) "GRANT: no
such schema '%s'", sname);
+ if (s && mvc_bind_table(sql, s, tname))
token = SQL_TABLE;
}
@@ -2133,7 +2131,7 @@ rel_revoke_privs(mvc *sql, sql_schema *c
static sql_rel *
rel_create_index(mvc *sql, char *iname, idx_type itype, dlist *qname, dlist
*column_list)
{
- sql_schema *s = NULL;
+ sql_schema *s = cur_schema(sql);
sql_table *t, *nt;
sql_rel *r, *res;
sql_exp **updates, *e;
@@ -2144,8 +2142,6 @@ rel_create_index(mvc *sql, char *iname,
if (sname && !(s = mvc_bind_schema(sql, sname)))
return sql_error(sql, 02, SQLSTATE(3F000) "CREATE INDEX: no
such schema '%s'", sname);
- if (!s)
- s = cur_schema(sql);
i = mvc_bind_idx(sql, s, iname);
if (i)
return sql_error(sql, 02, SQLSTATE(42S11) "CREATE INDEX: name
'%s' already in use", iname);
@@ -2236,8 +2232,7 @@ current_or_designated_schema(mvc *sql, c
if (!name)
return cur_schema(sql);
- s = mvc_bind_schema(sql, name);
- if (!s) {
+ if (!(s = mvc_bind_schema(sql, name))) {
sql_error(sql, 02, SQLSTATE(3F000) "COMMENT ON:no such schema:
%s", name);
return NULL;
}
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -678,7 +678,10 @@ rel_named_table_function(sql_query *quer
char *fname = qname_fname(l->data.lval);
char *sname = qname_schema(l->data.lval);
node *en;
- sql_schema *s = sql->session->schema;
+ sql_schema *s = cur_schema(sql);
+
+ if (sname && !(s = mvc_bind_schema(sql, sname)))
+ return sql_error(sql, 02, SQLSTATE(3F000) "SELECT: no such
schema '%s'", sname);
tl = sa_list(sql->sa);
exps = new_exp_list(sql->sa);
@@ -723,8 +726,6 @@ rel_named_table_function(sql_query *quer
}
}
- if (sname)
- s = mvc_bind_schema(sql, sname);
e = find_table_function(sql, s, fname, exps, tl);
if (!e)
return sql_error(sql, 02, SQLSTATE(42000) "SELECT: no such
operator '%s'", fname);
@@ -932,7 +933,7 @@ table_ref(sql_query *query, sql_rel *rel
dlist *name = tableref->data.lval->h->data.lval;
sql_rel *temp_table = NULL;
char *sname = qname_schema(name);
- sql_schema *s = NULL;
+ sql_schema *s = cur_schema(sql);
int allowed = 1;
tname = qname_table(name);
@@ -940,7 +941,7 @@ table_ref(sql_query *query, sql_rel *rel
if (dlist_length(name) > 2)
return sql_error(sql, 02, SQLSTATE(3F000) "SELECT: only
a schema and table name expected");
- if (sname && !(s=mvc_bind_schema(sql,sname)))
+ if (sname && !(s = mvc_bind_schema(sql, sname)))
return sql_error(sql, 02, SQLSTATE(3F000) "SELECT: no
such schema '%s'", sname);
if (!t && !sname) {
t = stack_find_table(sql, tname);
@@ -948,8 +949,6 @@ table_ref(sql_query *query, sql_rel *rel
temp_table = stack_find_rel_view(sql, tname);
}
if (!t && !temp_table) {
- if (!s)
- s = cur_schema(sql);
t = mvc_bind_table(sql, s, tname);
if (!t && !sname) {
s = tmp_schema(sql);
@@ -1529,7 +1528,7 @@ rel_filter(mvc *sql, sql_rel *rel, list
node *n;
sql_exp *L = l->h->data, *R = r->h->data, *e = NULL;
sql_subfunc *f = NULL;
- sql_schema *s = sql->session->schema;
+ sql_schema *s = cur_schema(sql);
list *tl, *exps;
exps = sa_list(sql->sa);
@@ -1546,8 +1545,8 @@ rel_filter(mvc *sql, sql_rel *rel, list
list_append(exps, e);
list_append(tl, exp_subtype(e));
}
- if (sname)
- s = mvc_bind_schema(sql, sname);
+ if (sname && !(s = mvc_bind_schema(sql, sname)))
+ return sql_error(sql, 02, SQLSTATE(3F000) "SELECT: no such
schema '%s'", sname);
/* find filter function */
f = sql_bind_func_(sql->sa, s, filter_op, tl, F_FILT);
@@ -2343,11 +2342,11 @@ rel_logical_value_exp(sql_query *query,
char *fname = qname_fname(filter_op);
char *sname = qname_schema(filter_op);
list *exps, *tl;
- sql_schema *s = sql->session->schema;
+ sql_schema *s = cur_schema(sql);
sql_subtype *obj_type = NULL;
- if (sname)
- s = mvc_bind_schema(sql, sname);
+ if (sname && !(s = mvc_bind_schema(sql, sname)))
+ return sql_error(sql, 02, SQLSTATE(3F000) "SELECT: no
such schema '%s'", sname);
exps = sa_list(sql->sa);
tl = sa_list(sql->sa);
@@ -3538,10 +3537,10 @@ rel_op(mvc *sql, symbol *se, exp_kind ek
dnode *l = se->data.lval->h;
char *fname = qname_fname(l->data.lval);
char *sname = qname_schema(l->data.lval);
- sql_schema *s = sql->session->schema;
-
- if (sname)
- s = mvc_bind_schema(sql, sname);
+ sql_schema *s = cur_schema(sql);
+
+ if (sname && !(s = mvc_bind_schema(sql, sname)))
+ return sql_error(sql, 02, SQLSTATE(3F000) "SELECT: no such
schema '%s'", sname);
return rel_op_(sql, s, fname, ek);
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list