Changeset: 2c3e9cb8408d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/2c3e9cb8408d
Modified Files:
sql/backends/monet5/sql_cat.c
sql/server/rel_psm.c
sql/storage/store.c
Branch: triggers
Log Message:
trigger without table obj ref wip
diffs (157 lines):
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
@@ -523,19 +523,25 @@ create_trigger(mvc *sql, char *sname, ch
{
sql_trigger *tri = NULL, *other = NULL;
sql_schema *s = NULL;
- sql_table *t;
+ sql_table *t = NULL;
const char *base = replace ? "CREATE OR REPLACE TRIGGER" : "CREATE
TRIGGER";
- if (!(s = mvc_bind_schema(sql, sname)))
- throw(SQL,"sql.create_trigger",SQLSTATE(3F000) "%s: no such
schema '%s'", base, sname);
- if (!mvc_schema_privs(sql, s))
- throw(SQL,"sql.create_trigger",SQLSTATE(42000) "%s: access
denied for %s to schema '%s'", base, get_string_global_var(sql,
"current_user"), s->base.name);
+ if (!strNil(sname) && !strNil(tname)) {
+ if (!(s = mvc_bind_schema(sql, sname)))
+ throw(SQL,"sql.create_trigger",SQLSTATE(3F000) "%s: no
such schema '%s'", base, sname);
+ if (!mvc_schema_privs(sql, s))
+ throw(SQL,"sql.create_trigger",SQLSTATE(42000) "%s:
access denied for %s to schema '%s'", base, get_string_global_var(sql,
"current_user"), s->base.name);
+ if (!(t = mvc_bind_table(sql, s, tname)))
+ throw(SQL,"sql.create_trigger",SQLSTATE(3F000) "%s:
unknown table '%s'", base, tname);
+ if (isView(t))
+ throw(SQL,"sql.create_trigger",SQLSTATE(3F000) "%s:
cannot create trigger on view '%s'", base, tname);
+ } else {
+ if (!(s = mvc_bind_schema(sql, "sys")))
+ throw(SQL,"sql.create_trigger",SQLSTATE(3F000) "%s: no
such schema '%s'", base, sname);
+ }
+
if ((other = mvc_bind_trigger(sql, s, triggername)) && !replace)
throw(SQL,"sql.create_trigger",SQLSTATE(3F000) "%s: name '%s'
already in use", base, triggername);
- if (!(t = mvc_bind_table(sql, s, tname)))
- throw(SQL,"sql.create_trigger",SQLSTATE(3F000) "%s: unknown
table '%s'", base, tname);
- if (isView(t))
- throw(SQL,"sql.create_trigger",SQLSTATE(3F000) "%s: cannot
create trigger on view '%s'", base, tname);
if (replace && other) {
if (other->t->base.id != t->base.id) /* defensive line */
diff --git a/sql/server/rel_psm.c b/sql/server/rel_psm.c
--- a/sql/server/rel_psm.c
+++ b/sql/server/rel_psm.c
@@ -1241,8 +1241,8 @@ create_trigger(sql_query *query, dlist *
mvc *sql = query->sql;
const char *triggerschema = qname_schema(qname);
const char *triggername = qname_schema_object(qname);
- const char *sname = tqname? qname_schema(tqname) : NULL;
- const char *tname = tqname? qname_schema_object(tqname) : NULL;
+ char *sname = tqname? qname_schema(tqname) : NULL;
+ char *tname = tqname? qname_schema_object(tqname) : NULL;
int instantiate = (sql->emode == m_instantiate);
int create = (!instantiate && sql->emode != m_deps), event, orientation;
sql_schema *ss = cur_schema(sql), *old_schema = cur_schema(sql);
@@ -1279,11 +1279,13 @@ create_trigger(sql_query *query, dlist *
if (tname) {
if (!(t = mvc_bind_table(sql, ss, tname)))
return sql_error(sql, ERR_NOTFOUND,
SQLSTATE(42S02) "%s: no such table %s%s%s'%s'", base, sname ? "'":"", sname ?
sname : "", sname ? "'.":"", tname);
+ if (isView(t))
+ return sql_error(sql, 02, SQLSTATE(42000) "%s:
cannot create trigger on view '%s'", base, tname);
+ sname = t->s->base.name;
+ tname = t->base.name;
}
if (!mvc_schema_privs(sql, ss))
return sql_error(sql, 02, SQLSTATE(42000) "%s: access
denied for %s to schema '%s'", base, get_string_global_var(sql,
"current_user"), ss->base.name);
- if (isView(t))
- return sql_error(sql, 02, SQLSTATE(42000) "%s: cannot
create trigger on view '%s'", base, tname);
if (!replace && mvc_bind_trigger(sql, ss, triggername) != NULL)
return sql_error(sql, 02, SQLSTATE(42000) "%s: name
'%s' already in use", base, triggername);
switch (trigger_event->token) {
@@ -1311,6 +1313,9 @@ create_trigger(sql_query *query, dlist *
return sql_error(sql, 02,
SQLSTATE(42000) "%s: old and new names cannot be the same", base);
event = 2;
} break;
+ case SQL_LOGIN:
+ // TODO any checks here?
+ break;
default:
return sql_error(sql, 02, SQLSTATE(42000) "%s:
invalid event: %s", base, token2string(trigger_event->token));
}
@@ -1318,21 +1323,24 @@ create_trigger(sql_query *query, dlist *
assert(triggered_action->h->type == type_int);
orientation = triggered_action->h->data.i_val;
q = query_cleaned(sql->ta, QUERY(sql->scanner));
- return rel_create_trigger(sql, t->s->base.name, t->base.name,
triggername, time, orientation, event, old_name, new_name, condition, q,
replace);
+ return rel_create_trigger(sql, sname, tname, triggername, time,
orientation, event, old_name, new_name, condition, q, replace);
}
if (!instantiate) {
- t = mvc_bind_table(sql, ss, tname);
if (!stack_push_frame(sql, "%OLD-NEW"))
return sql_error(sql, 02, SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- /* we need to add the old and new tables */
- if (new_name && !_stack_push_table(sql, new_name, t)) {
- stack_pop_frame(sql);
- return sql_error(sql, 02, SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- }
- if (old_name && !_stack_push_table(sql, old_name, t)) {
- stack_pop_frame(sql);
- return sql_error(sql, 02, SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ if (tname) {
+ if (!(t = mvc_bind_table(sql, ss, tname)))
+ return sql_error(sql, ERR_NOTFOUND,
SQLSTATE(42S02) "%s: no such table %s%s%s'%s'", base, sname ? "'":"", sname ?
sname : "", sname ? "'.":"", tname);
+ /* we need to add the old and new tables */
+ if (new_name && !_stack_push_table(sql, new_name, t)) {
+ stack_pop_frame(sql);
+ return sql_error(sql, 02, SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ }
+ if (old_name && !_stack_push_table(sql, old_name, t)) {
+ stack_pop_frame(sql);
+ return sql_error(sql, 02, SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ }
}
}
if (condition) {
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -6761,7 +6761,7 @@ sql_trans_create_trigger(sql_trigger **t
const char *condition, const char *statement )
{
sqlstore *store = tr->store;
- sql_schema *syss = find_sql_schema(tr, isGlobal(t)?"sys":"tmp");
+ sql_schema *syss = (t != NULL) ? find_sql_schema(tr, isGlobal(t) ?
"sys":"tmp") : find_sql_schema(tr, "sys");
sql_table *systrigger = find_sql_table(tr, syss, "triggers");
char *strnil = (char*)ATOMnilptr(TYPE_str);
sql_table *dup = NULL;
@@ -6769,7 +6769,7 @@ sql_trans_create_trigger(sql_trigger **t
assert(name);
- if ((res = new_table(tr, t, &dup)))
+ if ( t && (res = new_table(tr, t, &dup)))
return res;
t = dup;
sql_trigger *nt = ZNEW(sql_trigger);
@@ -6787,13 +6787,15 @@ sql_trans_create_trigger(sql_trigger **t
if (condition)
nt->condition =_STRDUP(condition);
nt->statement =_STRDUP(statement);
-
- assert(isGlobal(t));
- if ((res = ol_add(t->triggers, &nt->base)) ||
- (res = os_add(t->s->triggers, tr, nt->base.name,
dup_base(&nt->base))))
- return res;
-
- if ((res = store->table_api.table_insert(tr, systrigger, &nt->base.id,
&nt->base.name, &t->base.id, &nt->time, &nt->orientation,
+ if(t) {
+ assert(isGlobal(t));
+ if ((res = ol_add(t->triggers, &nt->base)) ||
+ (res = os_add(t->s->triggers, tr, nt->base.name,
dup_base(&nt->base))))
+ return res;
+ }
+ oid tid = t? (oid) t->base.id : oid_nil;
+
+ if ((res = store->table_api.table_insert(tr, systrigger, &nt->base.id,
&nt->base.name, &tid, &nt->time, &nt->orientation,
&nt->event,
(nt->old_name)?&nt->old_name:&strnil, (nt->new_name)?&nt->new_name:&strnil,
(nt->condition)?&nt->condition:&strnil, &nt->statement)))
return res;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]