/ Check-in [0f2129f5]
Login

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

Overview
Comment:Ensure that ALTER TABLE commands open statement transactions. Fix for [596d059a].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0f2129f59f7df929106e2af876c2976dea6528c1dc1850d64cddb256f20e121a
User & Date: dan 2019-03-15 16:17:32
Context
2019-03-15
18:57
Remove a debugging printf() left in test/sessionfuzz.c. check-in: 73c4abc9 user: dan tags: trunk
16:17
Ensure that ALTER TABLE commands open statement transactions. Fix for [596d059a]. check-in: 0f2129f5 user: dan tags: trunk
2019-03-14
00:01
Technical improvements to the documentation for sqlite3_bind_blob() and sqlite3_bind_text(). No changes to code. check-in: fb60150a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   162    162       pVTab = sqlite3GetVTable(db, pTab);
   163    163       if( pVTab->pVtab->pModule->xRename==0 ){
   164    164         pVTab = 0;
   165    165       }
   166    166     }
   167    167   #endif
   168    168   
   169         -  /* Begin a transaction for database iDb. 
   170         -  ** Then modify the schema cookie (since the ALTER TABLE modifies the
   171         -  ** schema). Open a statement transaction if the table is a virtual
   172         -  ** table.
   173         -  */
          169  +  /* Begin a transaction for database iDb. Then modify the schema cookie
          170  +  ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
          171  +  ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the 
          172  +  ** nested SQL may raise an exception.  */
   174    173     v = sqlite3GetVdbe(pParse);
   175    174     if( v==0 ){
   176    175       goto exit_rename_table;
   177    176     }
          177  +  sqlite3MayAbort(pParse);
   178    178   
   179    179     /* figure out how many UTF-8 characters are in zName */
   180    180     zTabName = pTab->zName;
   181    181     nTabName = sqlite3Utf8CharLen(zTabName, -1);
   182    182   
   183    183     /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
   184    184     ** the schema to use the new table name.  */
................................................................................
   239    239     ** SQLite tables) that are identified by the name of the virtual table.
   240    240     */
   241    241   #ifndef SQLITE_OMIT_VIRTUALTABLE
   242    242     if( pVTab ){
   243    243       int i = ++pParse->nMem;
   244    244       sqlite3VdbeLoadString(v, i, zName);
   245    245       sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
   246         -    sqlite3MayAbort(pParse);
   247    246     }
   248    247   #endif
   249    248   
   250    249     renameReloadSchema(pParse, iDb);
   251    250     renameTestSchema(pParse, zDb, iDb==1);
   252    251   
   253    252   exit_rename_table:
................................................................................
   560    559       goto exit_rename_column;
   561    560     }
   562    561   
   563    562     /* Do the rename operation using a recursive UPDATE statement that
   564    563     ** uses the sqlite_rename_column() SQL function to compute the new
   565    564     ** CREATE statement text for the sqlite_master table.
   566    565     */
          566  +  sqlite3MayAbort(pParse);
   567    567     zNew = sqlite3NameFromToken(db, pNew);
   568    568     if( !zNew ) goto exit_rename_column;
   569    569     assert( pNew->n>0 );
   570    570     bQuote = sqlite3Isquote(pNew->z[0]);
   571    571     sqlite3NestedParse(pParse, 
   572    572         "UPDATE \"%w\".%s SET "
   573    573         "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "

Changes to src/vdbeaux.c.

   633    633     memset(&sIter, 0, sizeof(sIter));
   634    634     sIter.v = v;
   635    635   
   636    636     while( (pOp = opIterNext(&sIter))!=0 ){
   637    637       int opcode = pOp->opcode;
   638    638       if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
   639    639        || opcode==OP_VDestroy
          640  +     || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL)
   640    641        || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
   641    642         && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
   642    643       ){
   643    644         hasAbort = 1;
   644    645         break;
   645    646       }
   646    647       if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;

Changes to test/altertab3.test.

    77     77     ALTER TABLE t1 RENAME b TO bbb;
    78     78   }
    79     79   
    80     80   do_execsql_test 3.2 {
    81     81     SELECT sql FROM sqlite_master WHERE name = 'v1'
    82     82   } {{CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (bbb IN ())}}
    83     83   
           84  +#-------------------------------------------------------------------------
           85  +reset_db
           86  +do_execsql_test 4.0 {
           87  +  CREATE TABLE t1(a, b);
           88  +  CREATE TABLE t3(e, f);
           89  +  CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
           90  +    INSERT INTO t2 VALUES(new.a, new.b);
           91  +  END;
           92  +}
           93  +
           94  +do_catchsql_test 4.1.2 {
           95  +  BEGIN;
           96  +    ALTER TABLE t3 RENAME TO t4;
           97  +} {1 {error in trigger tr1: no such table: main.t2}}
           98  +do_execsql_test 4.1.2 {
           99  +  COMMIT;
          100  +}
          101  +do_execsql_test 4.1.3 {
          102  +  SELECT * FROM sqlite_master WHERE type='table' AND name!='t1';
          103  +} {table t3 t3 3 {CREATE TABLE t3(e, f)}}
          104  +
    84    105   
          106  +do_catchsql_test 4.2.1 {
          107  +  BEGIN;
          108  +    ALTER TABLE t3 RENAME e TO eee;
          109  +} {1 {error in trigger tr1: no such table: main.t2}}
          110  +do_execsql_test 4.2.2 {
          111  +  COMMIT;
          112  +}
          113  +do_execsql_test 4.2.3 {
          114  +  SELECT * FROM sqlite_master WHERE type='table' AND name!='t1';
          115  +} {table t3 t3 3 {CREATE TABLE t3(e, f)}}
    85    116   
    86    117   finish_test
    87    118   
    88    119