Changeset: f115e71e394f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f115e71e394f
Modified Files:
sql/backends/monet5/sql.mx
sql/server/rel_schema.c
sql/server/rel_select.c
sql/server/rel_sequence.c
sql/server/rel_updates.c
sql/server/sql_privileges.c
sql/server/sql_psm.c
Branch: Dec2011
Log Message:
SQL: Changed and added a bunch of error codes.
I'm using these codes:
3F000 - unknown schema
42S01 - table/view name already exists
42S02 - table/view name not found
42S11 - index name already exists
42S12 - index name not found
42S21 - column name already exists
42S22 - column name not found
42M31 - user/role already exists
42M32 - user/role not found
diffs (truncated from 625 to 300 lines):
diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -1849,9 +1849,9 @@ create_table_or_view( mvc *sql, char *sn
if (mvc_bind_table(sql, s, t->base.name)) {
char *cd = (temp == SQL_DECLARED_TABLE)?"DECLARE":"CREATE";
- return sql_message("40000!%s TABLE: name '%s' already in use",
cd, t->base.name);
+ return sql_message("42S01!%s TABLE: name '%s' already in use",
cd, t->base.name);
} else if (temp != SQL_DECLARED_TABLE && (!schema_privs(sql->role_id,
s) && !(isTempSchema(s) && temp == SQL_LOCAL_TEMP))){
- return sql_message("40000!CREATE TABLE: insufficient privileges
for user '%s' in schema '%s'", stack_get_string(sql, "current_user"),
s->base.name);
+ return sql_message("42000!CREATE TABLE: insufficient privileges
for user '%s' in schema '%s'", stack_get_string(sql, "current_user"),
s->base.name);
}
/* first check default values */
@@ -1916,10 +1916,10 @@ alter_table( mvc *sql, char *sname, sql_
return sql_message("3F000!ALTER TABLE: no such schema '%s'",
sname);
if ((nt = mvc_bind_table(sql, s, t->base.name)) == NULL) {
- return sql_message("40000!ALTER TABLE: no such table '%s'",
t->base.name);
+ return sql_message("42S02!ALTER TABLE: no such table '%s'",
t->base.name);
} else if (!schema_privs(sql->role_id, s) && !(isTempSchema(s) &&
t->persistence == SQL_LOCAL_TEMP)){
- return sql_message("40000!ALTER TABLE: insufficient privileges
for user '%s' in schema '%s'", stack_get_string(sql, "current_user"),
s->base.name);
+ return sql_message("42000!ALTER TABLE: insufficient privileges
for user '%s' in schema '%s'", stack_get_string(sql, "current_user"),
s->base.name);
}
/* First check if all the changes are allowed */
@@ -2041,13 +2041,13 @@ drop_table(mvc *sql, char *sname, char *
t = mvc_bind_table(sql, s, tname);
}
if (!t) {
- return sql_message("40000!DROP TABLE: no such table '%s'",
tname);
+ return sql_message("42S02!DROP TABLE: no such table '%s'",
tname);
} else if (!isTable(t) && !isStream(t) && !isRemote(t)) {
- return sql_message("40000!DROP TABLE: cannot drop VIEW '%s'",
tname);
+ return sql_message("42000!DROP TABLE: cannot drop VIEW '%s'",
tname);
} else if (t->system) {
- return sql_message("40000!DROP TABLE: cannot drop system table
'%s'", tname);
+ return sql_message("42000!DROP TABLE: cannot drop system table
'%s'", tname);
} else if (!schema_privs(sql->role_id, s) && !(isTempSchema(s) &&
t->persistence == SQL_LOCAL_TEMP)){
- return sql_message("40000!DROP TABLE: access denied for %s to
schema ;'%s'", stack_get_string(sql, "current_user"), s->base.name);
+ return sql_message("42000!DROP TABLE: access denied for %s to
schema ;'%s'", stack_get_string(sql, "current_user"), s->base.name);
}
if ( !drop_action && t->keys.set) {
for (n = t->keys.set->h; n; n = n->next) {
@@ -2071,7 +2071,7 @@ drop_table(mvc *sql, char *sname, char *
}
if (!drop_action && mvc_check_dependency(sql, t->base.id,
TABLE_DEPENDENCY, NULL))
- return sql_message("40000!DROP TABLE: unable to drop table %s
(there are database objects which depend on it)\n", t->base.name);
+ return sql_message("42000!DROP TABLE: unable to drop table %s
(there are database objects which depend on it)\n", t->base.name);
mvc_drop_table(sql, s, t, drop_action);
return MAL_SUCCEED;
@@ -2092,15 +2092,15 @@ drop_view(mvc *sql, char *sname, char *t
t = mvc_bind_table(sql, ss, tname);
if (!schema_privs(sql->role_id, ss) && !(isTempSchema(ss) && t &&
t->persistence == SQL_LOCAL_TEMP)){
- return sql_message("40000!DROP VIEW: access denied for %s to
schema '%s'", stack_get_string(sql, "current_user"), ss->base.name);
+ return sql_message("42000!DROP VIEW: access denied for %s to
schema '%s'", stack_get_string(sql, "current_user"), ss->base.name);
} else if (!t) {
- return sql_message("40000!DROP VIEW: unknown view '%s'", tname);
+ return sql_message("42S02!DROP VIEW: unknown view '%s'", tname);
} else if (!isView(t)) {
- return sql_message("40000!DROP VIEW: unable to drop view '%s':
is a table", tname);
+ return sql_message("42000!DROP VIEW: unable to drop view '%s':
is a table", tname);
} else if (t->system) {
- return sql_message("40000!DROP VIEW: cannot drop system view
'%s'", tname);
+ return sql_message("42000!DROP VIEW: cannot drop system view
'%s'", tname);
} else if (! drop_action && mvc_check_dependency(sql, t->base.id,
VIEW_DEPENDENCY, NULL)) {
- return sql_message("40000!DROP VIEW: cannot drop view
'%s', there are database objects which depend on it", t->base.name);
+ return sql_message("42000!DROP VIEW: cannot drop view
'%s', there are database objects which depend on it", t->base.name);
} else {
mvc_drop_table(sql, ss, t, drop_action);
return MAL_SUCCEED;
@@ -2120,9 +2120,9 @@ drop_key( mvc *sql, char *sname, char *k
ss = cur_schema(sql);
if ((key = mvc_bind_key(sql, ss, kname )) == NULL)
- return sql_message("40000!ALTER TABLE: no such constraint
'%s'", kname);
+ return sql_message("42000!ALTER TABLE: no such constraint
'%s'", kname);
if (!drop_action && mvc_check_dependency(sql, key->base.id,
KEY_DEPENDENCY, NULL))
- return sql_message("40000!ALTER TABLE: cannot drop constraint
'%s': there are database objects which depend on it", key->base.name);
+ return sql_message("42000!ALTER TABLE: cannot drop constraint
'%s': there are database objects which depend on it", key->base.name);
mvc_drop_key(sql, ss, key, drop_action);
return MAL_SUCCEED;
}
@@ -2140,11 +2140,11 @@ create_index( mvc *sql, char *iname, int
i = mvc_bind_idx(sql, s, iname);
t = mvc_bind_table(sql, s, tname);
if (i) {
- return sql_message("40000!CREATE INDEX: name '%s' already in
use", iname);
+ return sql_message("42S11!CREATE INDEX: name '%s' already in
use", iname);
} else if (!t) {
- return sql_message("40000!CREATE INDEX: no such table '%s'",
tname);
+ return sql_message("42S02!CREATE INDEX: no such table '%s'",
tname);
} else if (isView(t)) {
- return sql_message("40000!CREATE INDEX: cannot create index on
view '%s'", tname);
+ return sql_message("42S02!CREATE INDEX: cannot create index on
view '%s'", tname);
} else {
int n;
sql_idx *i = mvc_create_idx(sql, t, iname, (idx_type) itype);
@@ -2157,7 +2157,7 @@ create_index( mvc *sql, char *iname, int
sql_column *c = mvc_bind_column(sql, t, cname);
if (!c) {
- return sql_message("40000!CREATE INDEX: no such
column '%s'", cname);
+ return sql_message("42S22!CREATE INDEX: no such
column '%s'", cname);
} else {
mvc_create_ic(sql, i, c);
mvc_create_dependency(sql, c->base.id,
i->base.id, INDEX_DEPENDENCY);
@@ -2177,9 +2177,9 @@ drop_index( mvc *sql, char *sname, char
return sql_message("3F000!DROP INDEX: no such schema '%s'",
sname);
i = mvc_bind_idx(sql, s, iname);
if (!i) {
- return sql_message("40000!DROP INDEX: no such index '%s'",
iname);
+ return sql_message("42S12!DROP INDEX: no such index '%s'",
iname);
} else if (!schema_privs(sql->role_id, s)) {
- return sql_message("40000!DROP INDEX: access denied for %s to
schema ;'%s'", stack_get_string(sql, "current_user"), s->base.name);
+ return sql_message("42000!DROP INDEX: access denied for %s to
schema ;'%s'", stack_get_string(sql, "current_user"), s->base.name);
} else {
mvc_drop_idx(sql, s, i);
}
@@ -2196,9 +2196,9 @@ create_seq( mvc *sql, char *sname, sql_s
if (s == NULL)
s = cur_schema(sql);
if (find_sql_sequence(s, seq->base.name)) {
- return sql_message("40000!CREATE SEQUENCE: name '%s' already in
use", seq->base.name);
+ return sql_message("42000!CREATE SEQUENCE: name '%s' already in
use", seq->base.name);
} else if (!schema_privs(sql->role_id, s)) {
- return sql_message( "40000!CREATE SEQUENCE: insufficient
privileges for '%s' in schema '%s'", stack_get_string(sql, "current_user"),
s->base.name);
+ return sql_message( "42000!CREATE SEQUENCE: insufficient
privileges for '%s' in schema '%s'", stack_get_string(sql, "current_user"),
s->base.name);
}
sql_trans_create_sequence(sql->session->tr, s, seq->base.name,
seq->start, seq->minvalue, seq->maxvalue, seq->increment, seq->cacheinc,
seq->cycle, seq->bedropped);
return NULL;
@@ -2215,9 +2215,9 @@ alter_seq( mvc *sql, char *sname, sql_se
if (s == NULL)
s = cur_schema(sql);
if (!(nseq = find_sql_sequence(s, seq->base.name))) {
- return sql_message( "40000!ALTER SEQUENCE: no such sequence
'%s'", seq->base.name);
+ return sql_message( "42000!ALTER SEQUENCE: no such sequence
'%s'", seq->base.name);
} else if (!schema_privs(sql->role_id, s)) {
- return sql_message( "40000!ALTER SEQUENCE: insufficient
privileges for '%s' in schema '%s'", stack_get_string(sql, "current_user"),
s->base.name);
+ return sql_message( "42000!ALTER SEQUENCE: insufficient
privileges for '%s' in schema '%s'", stack_get_string(sql, "current_user"),
s->base.name);
}
/* first alter the known values */
@@ -2237,7 +2237,7 @@ drop_seq(mvc *sql, char *sname, char *na
sql_sequence *seq = NULL;
if (sname && !(s = mvc_bind_schema(sql, sname)))
- return sql_message("DROP SEQUENCE: no such schema '%s'", sname);
+ return sql_message("3F000!DROP SEQUENCE: no such schema '%s'",
sname);
if (!s)
s = cur_schema(sql);
if (!(seq = find_sql_sequence(s, name))) {
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
@@ -166,7 +166,7 @@ mvc_create_table_as_subquery( mvc *sql,
sql_table *t = mvc_create_table(sql, s, tname, tt, 0,
SQL_DECLARED_TABLE, commit_action, -1);
if ((n = as_subquery( sql, t, sq, column_spec)) != NULL) {
- sql_error(sql, 01, "CREATE TABLE: duplicate column name %s", n);
+ sql_error(sql, 01, "42S21!CREATE TABLE: duplicate column name
%s", n);
return NULL;
}
@@ -303,7 +303,7 @@ column_constraint_type(mvc *sql, char *n
*/
rt = _bind_table(t, ss, cur_schema(sql), rtname);
if (!rt) {
- (void) sql_error(sql, 02, "CONSTRAINT FOREIGN KEY: no
such table table '%s'\n", rtname);
+ (void) sql_error(sql, 02, "42S02!CONSTRAINT FOREIGN
KEY: no such table table '%s'\n", rtname);
return res;
}
if (name && mvc_bind_key(sql, ss, name)) {
@@ -370,7 +370,7 @@ column_option(
char *err = NULL, *r = symbol2string(sql, s->data.sym, &err);
if (!r) {
- (void) sql_error(sql, 02, "incorrect default value
'%s'\n", err?err:"");
+ (void) sql_error(sql, 02, "42000!incorrect default
value '%s'\n", err?err:"");
if (err) _DELETE(err);
return SQL_ERR;
} else {
@@ -437,7 +437,7 @@ table_foreign_key(mvc *sql, char *name,
sql_table *ft = mvc_bind_table(sql, ss, rtname);
if (!ft) {
- sql_error(sql, 02, "CONSTRAINT FOREIGN KEY: no such table
'%s'\n", rtname);
+ sql_error(sql, 02, "42S02!CONSTRAINT FOREIGN KEY: no such table
'%s'\n", rtname);
return SQL_ERR;
} else {
sql_key *rk = NULL;
@@ -448,7 +448,7 @@ table_foreign_key(mvc *sql, char *name,
assert(n->next->next->next->next->type == type_int);
if (name && mvc_bind_key(sql, ss, name)) {
- sql_error(sql, 02, "Create Key failed, key %s allready
exists", name);
+ sql_error(sql, 02, "Create Key failed, key %s already
exists", name);
return SQL_ERR;
}
if (n->next->next->data.lval) { /* find unique referenced key */
@@ -476,7 +476,7 @@ table_foreign_key(mvc *sql, char *name,
sql_column *c = mvc_bind_column(sql, t, nm);
if (!c) {
- sql_error(sql, 02, "CONSTRAINT FOREIGN KEY: no
such column '%s' in table '%s'\n", nm, t->base.name);
+ sql_error(sql, 02, "42S22!CONSTRAINT FOREIGN
KEY: no such column '%s' in table '%s'\n", nm, t->base.name);
return SQL_ERR;
}
mvc_create_fkc(sql, fk, c);
@@ -517,7 +517,7 @@ table_constraint_type(mvc *sql, char *na
sql_column *c = mvc_bind_column(sql, t, nm);
if (!c) {
- sql_error(sql, 02, "CONSTRAINT %s: no such
column '%s' for table '%s'",
+ sql_error(sql, 02, "42S22!CONSTRAINT %s: no
such column '%s' for table '%s'",
kt == pkey ? "PRIMARY KEY" :
"UNIQUE",
nm, t->base.name);
return SQL_ERR;
@@ -583,7 +583,7 @@ create_column(mvc *sql, symbol *s, sql_s
cs = find_sql_column(t, cname);
if (cs) {
- sql_error(sql, 02, "%s TABLE: a column named '%s'
already exists\n", (alter)?"ALTER":"CREATE", cname);
+ sql_error(sql, 02, "42S21!%s TABLE: a column named '%s'
already exists\n", (alter)?"ALTER":"CREATE", cname);
return SQL_ERR;
}
cs = mvc_create_column(sql, t, cname, ctype);
@@ -655,7 +655,7 @@ table_element(mvc *sql, symbol *s, sql_s
dlist *olist = n->next->data.lval;
if (!c) {
- sql_error(sql, 02, "ALTER TABLE: no such column
'%s'\n", cname);
+ sql_error(sql, 02, "42S22!ALTER TABLE: no such column
'%s'\n", cname);
return SQL_ERR;
} else {
return column_options(sql, olist, ss, t, c);
@@ -670,12 +670,12 @@ table_element(mvc *sql, symbol *s, sql_s
sql_column *c = mvc_bind_column(sql, t, cname);
if (!c) {
- sql_error(sql, 02, "ALTER TABLE: no such column
'%s'\n", cname);
+ sql_error(sql, 02, "42S22!ALTER TABLE: no such column
'%s'\n", cname);
return SQL_ERR;
}
r = symbol2string(sql, sym, &err);
if (!r) {
- (void) sql_error(sql, 02, "incorrect default value
'%s'\n", err?err:"");
+ (void) sql_error(sql, 02, "42000!incorrect default
value '%s'\n", err?err:"");
if (err) _DELETE(err);
return SQL_ERR;
}
@@ -692,7 +692,7 @@ table_element(mvc *sql, symbol *s, sql_s
int null = (s->token == SQL_NOT_NULL) ? 0 : 1;
if (!c) {
- sql_error(sql, 02, "ALTER TABLE: no such column
'%s'\n", cname);
+ sql_error(sql, 02, "42S22!ALTER TABLE: no such column
'%s'\n", cname);
return SQL_ERR;
}
mvc_null(sql, c, null);
@@ -702,7 +702,7 @@ table_element(mvc *sql, symbol *s, sql_s
char *cname = s->data.sval;
sql_column *c = mvc_bind_column(sql, t, cname);
if (!c) {
- sql_error(sql, 02, "ALTER TABLE: no such column
'%s'\n", cname);
+ sql_error(sql, 02, "42S22!ALTER TABLE: no such column
'%s'\n", cname);
return SQL_ERR;
}
mvc_drop_default(sql,c);
@@ -716,7 +716,7 @@ table_element(mvc *sql, symbol *s, sql_s
node *n;
if (sname && !(os = mvc_bind_schema(sql, sname))) {
- sql_error(sql, 02, "CREATE TABLE: no such schema '%s'",
sname);
+ sql_error(sql, 02, "3F000!CREATE TABLE: no such schema
'%s'", sname);
return SQL_ERR;
}
if (!os)
@@ -739,23 +739,23 @@ table_element(mvc *sql, symbol *s, sql_s
assert(l->h->next->type == type_int);
if (col == NULL) {
- sql_error(sql, 02, "ALTER TABLE: no such column
'%s'\n", cname);
+ sql_error(sql, 02, "42S22!ALTER TABLE: no such column
'%s'\n", cname);
return SQL_ERR;
}
if (cs_size(&t->columns) <= 1) {
- sql_error(sql, 02, "ALTER TABLE: cannot drop column
'%s': table needs at least one column\n", cname);
+ sql_error(sql, 02, "42000!ALTER TABLE: cannot drop
column '%s': table needs at least one column\n", cname);
return SQL_ERR;
}
if (t->system) {
- sql_error(sql, 02, "ALTER TABLE: cannot drop column
'%s': table is a system table\n", cname);
+ sql_error(sql, 02, "42000!ALTER TABLE: cannot drop
column '%s': table is a system table\n", cname);
return SQL_ERR;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list