Changeset: 5db83f0ffeec for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5db83f0ffeec
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: linear-hashing
Log Message:
Merged with Nov2019
diffs (truncated from 619 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
@@ -192,7 +192,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;
}
@@ -352,9 +351,12 @@ column_constraint_type(mvc *sql, const c
}
*/
- 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) {
@@ -526,9 +528,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 */
@@ -1140,7 +1146,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);
@@ -1151,12 +1157,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) {
@@ -1277,12 +1280,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);
@@ -1297,12 +1298,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);
@@ -1441,16 +1440,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)
@@ -1842,9 +1839,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)
@@ -1894,9 +1892,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;
}
@@ -2024,12 +2022,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)
@@ -2078,9 +2076,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;
}
@@ -2108,7 +2106,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;
@@ -2119,8 +2117,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);
@@ -2211,8 +2207,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
@@ -609,7 +609,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);
@@ -654,8 +657,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);
@@ -869,7 +870,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);
@@ -877,7 +878,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);
@@ -885,8 +886,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);
@@ -1507,7 +1506,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);
@@ -1524,8 +1523,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);
@@ -2124,11 +2123,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);
@@ -2705,10 +2704,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