/ Check-in [e56be74e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge latest trunk changes with experimental branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: e56be74eabc03d1a524d96aa4e87102dea4e348e
User & Date: dan 2011-07-01 18:43:13
Context
2011-07-02
06:44
Fix a broken assert() in where.c. Closed-Leaf check-in: 090b2917 user: dan tags: experimental
2011-07-01
18:43
Merge latest trunk changes with experimental branch. check-in: e56be74e user: dan tags: experimental
18:26
Improve use of indexes to optimize DISTINCT queries. check-in: 6c202ea0 user: dan tags: experimental
14:22
Test case for ticket [d6ddba6706353915ceed] check-in: 953e169e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/trigger.c.

   113    113     }else{
   114    114       /* Figure out the db that the the trigger will be created in */
   115    115       iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
   116    116       if( iDb<0 ){
   117    117         goto trigger_cleanup;
   118    118       }
   119    119     }
          120  +  if( !pTableName || db->mallocFailed ){
          121  +    goto trigger_cleanup;
          122  +  }
          123  +
          124  +  /* A long-standing parser bug is that this syntax was allowed:
          125  +  **
          126  +  **    CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
          127  +  **                                                 ^^^^^^^^
          128  +  **
          129  +  ** To maintain backwards compatibility, ignore the database
          130  +  ** name on pTableName if we are reparsing our of SQLITE_MASTER.
          131  +  */
          132  +  if( db->init.busy && iDb!=1 ){
          133  +    sqlite3DbFree(db, pTableName->a[0].zDatabase);
          134  +    pTableName->a[0].zDatabase = 0;
          135  +  }
   120    136   
   121    137     /* If the trigger name was unqualified, and the table is a temp table,
   122    138     ** then set iDb to 1 to create the trigger in the temporary database.
   123    139     ** If sqlite3SrcListLookup() returns 0, indicating the table does not
   124    140     ** exist, the error is caught by the block below.
   125    141     */
   126         -  if( !pTableName || db->mallocFailed ){
   127         -    goto trigger_cleanup;
   128         -  }
   129    142     pTab = sqlite3SrcListLookup(pParse, pTableName);
   130    143     if( db->init.busy==0 && pName2->n==0 && pTab
   131    144           && pTab->pSchema==db->aDb[1].pSchema ){
   132    145       iDb = 1;
   133    146     }
   134    147   
   135    148     /* Ensure the table name matches database name and that the table exists */

Changes to test/triggerD.test.

    10     10   #***********************************************************************
    11     11   #
    12     12   # Verify that when columns named "rowid", "oid", and "_rowid_" appear
    13     13   # in a table as ordinary columns (not as the INTEGER PRIMARY KEY) then
    14     14   # the use of these columns in triggers will refer to the column and not
    15     15   # to the actual ROWID.  Ticket [34d2ae1c6d08b5271ba5e5592936d4a1d913ffe3]
    16     16   #
           17  +# Also, verify that triggers created like this:
           18  +#
           19  +#    CREATE TRIGGER attached.trig AFTER INSERT ON attached.tab ...
           20  +#
           21  +# can be reparsed as a main database.  Ticket [d6ddba6706353915ceedc56b4e3]
           22  +#
    17     23   
    18     24   set testdir [file dirname $argv0]
    19     25   source $testdir/tester.tcl
    20     26   ifcapable {!trigger} {
    21     27     finish_test
    22     28     return
    23     29   }
................................................................................
   166    172       END;
   167    173       INSERT INTO main.t300 VALUES(3);
   168    174       INSERT INTO temp.t300 VALUES(4);
   169    175       SELECT * FROM t301;
   170    176     }
   171    177   } {10003 20004}
   172    178   
          179  +
          180  +#############################################################################
          181  +# 
          182  +# Ticket [d6ddba6706353915ceedc56b4e3e72ecb4d77ba4]
          183  +#
          184  +# The following syntax really should not be allowed:
          185  +#
          186  +#    CREATE TRIGGER xyz.trig BEFORE UPDATE ON xyz.tab BEGIN ...
          187  +#
          188  +# But a long-standing bug does allow it.  And the "xyz.tab" slips into
          189  +# the sqlite_master table.  We cannot fix the bug simply by disallowing
          190  +# "xyz.tab" since that could break legacy applications.  We have to 
          191  +# fix the system so that the "xyz." on "xyz.tab" is ignored.
          192  +# Verify that this is the case.
          193  +#
          194  +do_test triggerD-4.1 {
          195  +  db close
          196  +  file delete -force test.db test2.db
          197  +  sqlite3 db test.db
          198  +  db eval {
          199  +    CREATE TABLE t1(x);
          200  +    ATTACH 'test2.db' AS db2;
          201  +    CREATE TABLE db2.t2(y);
          202  +    CREATE TABLE db2.log(z);
          203  +    CREATE TRIGGER db2.trig AFTER INSERT ON db2.t2 BEGIN
          204  +      INSERT INTO log(z) VALUES(new.y);
          205  +    END;
          206  +    INSERT INTO t2 VALUES(123);
          207  +    SELECT * FROM log;
          208  +  }
          209  +} {123}
          210  +do_test triggerD-4.2 {
          211  +  sqlite3 db2 test2.db
          212  +  db2 eval {
          213  +    INSERT INTO t2 VALUES(234);
          214  +    SELECT * FROM log;
          215  +  }
          216  +} {123 234}
          217  +db2 close
   173    218   
   174    219   finish_test