/ Check-in [ceb60bd7]
Login

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

Overview
Comment:Fix a problem with renaming a non-temp table that has at least one temp trigger and shares its name with a temp table.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ceb60bd7e5f2a0a4247bff476fc6468227305467339ae0c24591be9d2b14bdde
User & Date: dan 2018-09-07 15:50:31
Context
2018-09-07
18:52
Add assert() and ALWAYS() to identify two unreachable branches. check-in: 8fa254aa user: drh tags: trunk
15:50
Fix a problem with renaming a non-temp table that has at least one temp trigger and shares its name with a temp table. check-in: ceb60bd7 user: dan tags: trunk
11:51
Minor fixes for problems revealed by releasetest.tcl. check-in: 1a8aedc3 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

  1027   1027   ** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
  1028   1028   ** it was read from the schema of database zDb. Return SQLITE_OK if 
  1029   1029   ** successful. Otherwise, return an SQLite error code and leave an error
  1030   1030   ** message in the Parse object.
  1031   1031   */
  1032   1032   static int renameResolveTrigger(Parse *pParse, const char *zDb){
  1033   1033     sqlite3 *db = pParse->db;
         1034  +  Trigger *pNew = pParse->pNewTrigger;
  1034   1035     TriggerStep *pStep;
  1035   1036     NameContext sNC;
  1036   1037     int rc = SQLITE_OK;
  1037   1038   
  1038   1039     memset(&sNC, 0, sizeof(sNC));
  1039   1040     sNC.pParse = pParse;
  1040         -  pParse->pTriggerTab = sqlite3FindTable(db, pParse->pNewTrigger->table, zDb);
  1041         -  pParse->eTriggerOp = pParse->pNewTrigger->op;
         1041  +  assert( pNew->pTabSchema );
         1042  +  pParse->pTriggerTab = sqlite3FindTable(db, pNew->table, 
         1043  +      db->aDb[sqlite3SchemaToIndex(db, pNew->pTabSchema)].zDbSName
         1044  +  );
         1045  +  pParse->eTriggerOp = pNew->op;
  1042   1046   
  1043   1047     /* Resolve symbols in WHEN clause */
  1044         -  if( pParse->pNewTrigger->pWhen ){
  1045         -    rc = sqlite3ResolveExprNames(&sNC, pParse->pNewTrigger->pWhen);
         1048  +  if( pNew->pWhen ){
         1049  +    rc = sqlite3ResolveExprNames(&sNC, pNew->pWhen);
  1046   1050     }
  1047   1051   
  1048         -  for(pStep=pParse->pNewTrigger->step_list; 
  1049         -      rc==SQLITE_OK && pStep; 
  1050         -      pStep=pStep->pNext
  1051         -  ){
         1052  +  for(pStep=pNew->step_list; rc==SQLITE_OK && pStep; pStep=pStep->pNext){
  1052   1053       if( pStep->pSelect ){
  1053   1054         sqlite3SelectPrep(pParse, pStep->pSelect, &sNC);
  1054   1055         if( pParse->nErr ) rc = pParse->rc;
  1055   1056       }
  1056         -    if( rc==SQLITE_OK && pStep->zTarget ){ 
         1057  +    if( rc==SQLITE_OK && pStep->zTarget ){
  1057   1058         Table *pTarget = sqlite3LocateTable(pParse, 0, pStep->zTarget, zDb);
  1058   1059         if( pTarget==0 ){
  1059   1060           rc = SQLITE_ERROR;
  1060   1061         }else{
  1061   1062           SrcList sSrc;
  1062   1063           memset(&sSrc, 0, sizeof(sSrc));
  1063   1064           sSrc.nSrc = 1;

Changes to test/altertab.test.

   366    366     SELECT name, tbl_name FROM sqlite_temp_master;
   367    367   } {tr t2}
   368    368   
   369    369   do_execsql_test 11.6 {
   370    370     INSERT INTO aux.t2 VALUES(7, 8, 9);
   371    371   }
   372    372   do_test 11.7 { set ::trigger } {{4 5 6} {7 8 9}}
          373  +
          374  +#-------------------------------------------------------------------------
          375  +reset_db
          376  +do_execsql_test 12.0 {
          377  +  CREATE TABLE t1(a);
          378  +  CREATE TABLE t2(w);
          379  +  CREATE TRIGGER temp.r1 AFTER INSERT ON main.t2 BEGIN
          380  +    INSERT INTO t1(a) VALUES(new.w);
          381  +  END;
          382  +  CREATE TEMP TABLE t2(x);
          383  +}
          384  +
          385  +do_execsql_test 12.1 {
          386  +  ALTER TABLE main.t2 RENAME TO t3;
          387  +}
          388  +
          389  +do_execsql_test 12.2 {
          390  +  INSERT INTO t3 VALUES('WWW');
          391  +  SELECT * FROM t1;
          392  +} {WWW}
   373    393   
   374    394   finish_test
   375    395   

Changes to test/permutations.test.

   284    284   ]
   285    285   
   286    286   test_suite "window" -prefix "" -description {
   287    287     All window function related tests .
   288    288   } -files [
   289    289     test_set [glob -nocomplain $::testdir/window*.test]
   290    290   ]
          291  +
          292  +test_suite "alter" -prefix "" -description {
          293  +  All ALTER function related tests .
          294  +} -files [
          295  +  test_set [glob -nocomplain $::testdir/alter*.test]
          296  +]
   291    297   
   292    298   test_suite "lsm1" -prefix "" -description {
   293    299     All LSM1 tests.
   294    300   } -files [glob -nocomplain $::testdir/../ext/lsm1/test/*.test]
   295    301   
   296    302   test_suite "nofaultsim" -prefix "" -description {
   297    303     "Very" quick test suite. Runs in less than 5 minutes on a workstation.