SQLite

Check-in [1856ea63b3]
Login

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

Overview
Comment:Add extra test for the fix on this branch. Also fix a pointer-compare-after-free problem that occurs in similar cases.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | tkt-b41031ea
Files: files | file ages | folders
SHA3-256: 1856ea63b3186c2c8fa716ffe01c731397bdbbc3fbb56dc72ad0686cb7f152ca
User & Date: dan 2018-09-17 08:27:23.927
Context
2018-09-17
13:38
Minor modification to the fix on this branch to avoid adding extra conditional compilation macros. (check-in: 4d8be404da user: dan tags: tkt-b41031ea)
08:27
Add extra test for the fix on this branch. Also fix a pointer-compare-after-free problem that occurs in similar cases. (check-in: 1856ea63b3 user: dan tags: tkt-b41031ea)
00:15
Add assert()s to the new code in the previous check-in. (check-in: b12f23a5c4 user: drh tags: tkt-b41031ea)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/build.c.
2283
2284
2285
2286
2287
2288
2289




2290
2291
2292
2293
2294
2295
2296
  ** to the elements of the FROM clause.  But we do not want these changes
  ** to be permanent.  So the computation is done on a copy of the SELECT
  ** statement that defines the view.
  */
  assert( pTable->pSelect );
  pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
  if( pSel ){




    n = pParse->nTab;
    sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
    pTable->nCol = -1;
    db->lookaside.bDisable++;
#ifndef SQLITE_OMIT_AUTHORIZATION
    xAuth = db->xAuth;
    db->xAuth = 0;







>
>
>
>







2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
  ** to the elements of the FROM clause.  But we do not want these changes
  ** to be permanent.  So the computation is done on a copy of the SELECT
  ** statement that defines the view.
  */
  assert( pTable->pSelect );
  pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
  if( pSel ){
#ifndef SQLITE_OMIT_ALTERTABLE
    u8 eParseMode = pParse->eParseMode;
    pParse->eParseMode = PARSE_MODE_NORMAL;
#endif
    n = pParse->nTab;
    sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
    pTable->nCol = -1;
    db->lookaside.bDisable++;
#ifndef SQLITE_OMIT_AUTHORIZATION
    xAuth = db->xAuth;
    db->xAuth = 0;
2328
2329
2330
2331
2332
2333
2334



2335
2336
2337
2338
2339
2340
2341
    }else{
      pTable->nCol = 0;
      nErr++;
    }
    sqlite3DeleteTable(db, pSelTab);
    sqlite3SelectDelete(db, pSel);
    db->lookaside.bDisable--;



  } else {
    nErr++;
  }
  pTable->pSchema->schemaFlags |= DB_UnresetViews;
  if( db->mallocFailed ){
    sqlite3DeleteColumnNames(db, pTable);
    pTable->aCol = 0;







>
>
>







2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
    }else{
      pTable->nCol = 0;
      nErr++;
    }
    sqlite3DeleteTable(db, pSelTab);
    sqlite3SelectDelete(db, pSel);
    db->lookaside.bDisable--;
#ifndef SQLITE_OMIT_ALTERTABLE
    pParse->eParseMode = eParseMode;
#endif
  } else {
    nErr++;
  }
  pTable->pSchema->schemaFlags |= DB_UnresetViews;
  if( db->mallocFailed ){
    sqlite3DeleteColumnNames(db, pTable);
    pTable->aCol = 0;
Changes to test/altertab.test.
406
407
408
409
410
411
412


















































413
414
415
do_execsql_test 13.1 {
  INSERT INTO t1 VALUES(1, 2);
}

do_catchsql_test 13.2 {
  ALTER TABLE t2 RENAME b TO y;
} {1 {error in trigger tr1 after rename: ambiguous column name: y}}



















































finish_test








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
do_execsql_test 13.1 {
  INSERT INTO t1 VALUES(1, 2);
}

do_catchsql_test 13.2 {
  ALTER TABLE t2 RENAME b TO y;
} {1 {error in trigger tr1 after rename: ambiguous column name: y}}

#-------------------------------------------------------------------------
reset_db

ifcapable rtree {
  do_execsql_test 14.0 {
    CREATE VIRTUAL TABLE rt USING rtree(id, minx, maxx, miny, maxy);

    CREATE TABLE "mytable" ( "fid" INTEGER PRIMARY KEY, "geom" BLOB);

    CREATE TRIGGER tr1 AFTER UPDATE OF "geom" ON "mytable" 
          WHEN OLD."fid" = NEW."fid" AND NEW."geom" IS NULL BEGIN 
      DELETE FROM rt WHERE id = OLD."fid"; 
    END;

    INSERT INTO mytable VALUES(1, X'abcd');
  }

  do_execsql_test 14.1 {
    UPDATE mytable SET geom = X'1234'
  }

  do_execsql_test 14.2 {
    ALTER TABLE mytable RENAME TO mytable_renamed;
  }

  do_execsql_test 14.3 {
    CREATE TRIGGER tr2 AFTER INSERT ON mytable_renamed BEGIN
      DELETE FROM rt WHERE id=(SELECT min(id) FROM rt);
    END;
  }

  do_execsql_test 14.4 {
    ALTER TABLE mytable_renamed RENAME TO mytable2;
  }
}

reset_db
do_execsql_test 14.5 {
  CREATE TABLE t1(a, b, c);
  CREATE VIEW v1 AS SELECT * FROM t1;
  CREATE TRIGGER xyz AFTER INSERT ON t1 BEGIN
    SELECT a, b FROM v1;
  END;
}
do_execsql_test 14.6 {
  ALTER TABLE t1 RENAME TO tt1;
}



finish_test