Update of /cvsroot/monetdb/sql/src/server
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv20477

Modified Files:
      Tag: SQL_2-18
        sql_updates.mx 
Log Message:
Remove the control for cascade triggers. The recursive triggers are user 
responsability and not ours.

Some improvements to the UPDATE/DELETE cascade code. 



Index: sql_updates.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_updates.mx,v
retrieving revision 1.123
retrieving revision 1.123.2.1
diff -u -d -r1.123 -r1.123.2.1
--- sql_updates.mx      23 May 2007 22:05:59 -0000      1.123
+++ sql_updates.mx      8 Jun 2007 11:58:21 -0000       1.123.2.1
@@ -439,9 +439,7 @@
                int *trigger_id = NEW(int);
                *trigger_id = trigger->base.id;
 
-               if (trigger->event == 0 && 
-                  (!sql->called_triggers || 
-                   !list_find_id(sql->called_triggers, *trigger_id))) {
+               if (trigger->event == 0) { 
                        scope *scp = scope_open(NULL);
                        stmt *s = NULL;
                        char *n = trigger->new_name;
@@ -449,8 +447,6 @@
                        /* add name for the 'inserted' to the scope */
                        if (!n) n = "new"; 
        
-                       list_append(sql->called_triggers, trigger_id);
-       
                        scope_add_inserted(scp, inserts, t, n);
                        s = scope_sqlparse(sql, scp, trigger->statement, 
m_execute);
 
@@ -744,22 +740,32 @@
                sql_kc *fc = m->data;
                stmt *upd = NULL;
 
-               if (action == ACT_SET_DEFAULT)
-                       upd = stmt_atom(atom_general(&fc->c->type, fc->c->def, 
0));
-               else
-                       if(action == ACT_SET_NULL)
+               if (action == ACT_SET_DEFAULT) {
+                       if (fc->c->def) {
+                               stmt *sq;
+                               char buf[BUFSIZ];
+                                                
+                               snprintf(buf, BUFSIZ, "select %s;", fc->c->def);
+                               sq = scope_sqlparse(sql, NULL, buf, sql->mode);
+                                                
+                               if (!sq || sq->type != st_list || 
list_length(sq->op1.lval) != 1) {
+                                       cleanup_stmts(new_updates, len);
+                                       return NULL;
+                               }
+                               upd = stmt_dup(sq->op1.lval->h->data);
+                       }  else 
                                upd = stmt_atom(atom_general(&fc->c->type, 
NULL, 0));
+               } else
+                       upd = stmt_atom(atom_general(&fc->c->type, NULL, 0));
                
-
                if (!upd || (upd = check_types(sql, &fc->c->type, upd, 
type_equal)) == NULL) {
                        stmt_destroy(rows);
-                       list_destroy(l);
                        cleanup_stmts(new_updates, len);
                        return NULL;
                }
 
                if (upd->nrcols <= 0) 
-                       upd = stmt_const(stmt_reverse(rows->type == st_ptable ? 
first_subset(rows) : stmt_bat(fc->c, stmt_dup(fts), RDONLY)), upd);
+                       upd = stmt_const(rows, upd);
                
                /* new bats need values replaced */
                if (fc->c->base.flag == TR_NEW)
@@ -773,7 +779,6 @@
        
        l = create_stmt_list();
        if ((s = sql_update(sql, schema, t, new_updates, l)) == NULL) {
-               list_destroy(l);
                cleanup_stmts(new_updates, len);
                return NULL;
        }
@@ -811,8 +816,22 @@
                if (updates[c->c->colnr]) {
                        if(action == ACT_CASCADE) 
                                upd = stmt_dup(updates[c->c->colnr]->op2.stval);
-                       if (action == ACT_SET_DEFAULT)
-                               upd = stmt_atom(atom_general(&fc->c->type, 
fc->c->def, 0));
+                       if (action == ACT_SET_DEFAULT) {
+                               if (fc->c->def) {
+                                       stmt *sq;
+                                       char buf[BUFSIZ];
+                                                        
+                                       snprintf(buf, BUFSIZ, "select %s;", 
fc->c->def);
+                                       sq = scope_sqlparse(sql, NULL, buf, 
sql->mode);
+                                                        
+                                       if (!sq || sq->type != st_list || 
list_length(sq->op1.lval) != 1) {
+                                               cleanup_stmts(new_updates, len);
+                                               return NULL;
+                                       }
+                                       upd = stmt_dup(sq->op1.lval->h->data);
+                               }  else 
+                                       upd = 
stmt_atom(atom_general(&fc->c->type, NULL, 0));
+                       }
                        if(action == ACT_SET_NULL) 
                                upd = stmt_atom(atom_general(&fc->c->type, 
NULL, 0));
                } else {
@@ -822,13 +841,12 @@
 
                if (!upd || (upd = check_types(sql, &fc->c->type, upd, 
type_equal)) == NULL) {
                        stmt_destroy(rows);
-                       list_destroy(l);
                        cleanup_stmts(new_updates, len);
                        return NULL;
                }
 
                if (upd->nrcols <= 0) 
-                       upd = stmt_const(stmt_reverse(rows->type == st_ptable ? 
first_subset(rows) : stmt_bat(fc->c, stmt_dup(fts), RDONLY)), upd);
+                       upd = stmt_const(rows, upd);
                
                /* new bats need values replaced */
                if (fc->c->base.flag == TR_NEW)
@@ -842,7 +860,6 @@
        
        l = create_stmt_list();
        if ((s = sql_update(sql, schema, t, new_updates, l)) == NULL) {
-               list_destroy(l);
                cleanup_stmts(new_updates, len);
                return NULL;
        }
@@ -1082,9 +1099,7 @@
                int *trigger_id = NEW(int);
                *trigger_id = trigger->base.id;
 
-               if (trigger->event == 2 && 
-                  (!sql->called_triggers || 
-                   !list_find_id(sql->called_triggers, *trigger_id))) {
+               if (trigger->event == 2) {
                        scope *scp = scope_open(NULL);
                        stmt *s = NULL;
        
@@ -1095,8 +1110,6 @@
                        if (!n) n = "new"; 
                        if (!o) o = "old"; 
        
-                       list_append(sql->called_triggers, trigger_id);
-       
                        scope_add_updated(scp, inserts, t, o, n);
                        s = scope_sqlparse(sql, scp, trigger->statement, 
m_execute);
 
@@ -1643,7 +1656,6 @@
                stmt_destroy(s);
 
                if ((s = sql_update(sql, schema, t, updates, l)) == NULL) {
-                       list_destroy(l);
                        if (sql->cascade_action) {
                                list_destroy(sql->cascade_action);
                                sql->cascade_action = NULL;
@@ -1716,9 +1728,7 @@
                int *trigger_id = NEW(int);
                *trigger_id = trigger->base.id;
 
-               if (trigger->event == 1 && 
-                  (!sql->called_triggers || 
-                   !list_find_id(sql->called_triggers, *trigger_id))) {
+               if (trigger->event == 1) {
                        scope *scp = scope_open(NULL);
                        stmt *s = NULL;
        
@@ -1727,8 +1737,6 @@
                
                        if (!o) o = "old"; 
                
-                       list_append(sql->called_triggers, trigger_id);
-
                        scope_add_deleted(scp, deletes, t, o);
                        s = scope_sqlparse(sql, scp, trigger->statement, 
m_execute);
 
@@ -1776,12 +1784,14 @@
 
                        s = stmt_idxbat(fk->idx, RDONLY);
                        s = stmt_semijoin(stmt_reverse(s), stmt_dup(deletes));
+                       s = stmt_reverse(s);
                        switch (((sql_fkey*)fk)->on_delete) {
                                case ACT_NO_ACTION: 
                                        break;
                                case ACT_SET_NULL: 
                                case ACT_SET_DEFAULT: 
                                        s = sql_delete_set_Fkeys(sql, schema, 
fk, s, ((sql_fkey*)fk)->on_delete);
+                                       list_prepend(l, s);
                                        break;
                                case ACT_CASCADE: 
                                        s = sql_delete_cascade_Fkeys(sql, 
schema, s, fk, k);
@@ -1793,7 +1803,6 @@
                                        snprintf(buf, BUFSIZ, "DELETE: FOREIGN 
KEY constraint '%s.%s' violated", k->t->base.name, k->base.name);
                                        s = stmt_exception(s, _strdup(buf), 
00001);
                                        list_prepend(l, s);
-
                        }
                }
        }


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to