/ Check-in [31e85fbb]
Login

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

Overview
Comment:Fix a problem with running ALTER TABLE ADD COLUMN statements within a transaction that writes to one or more virtual tables. Fix for [8fe768e9].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 31e85fbbc4cfd09a98b4a6dc6624f863816f376c6a4eef1fafc657c8e1abbc36
User & Date: dan 2019-10-07 18:43:21
Original Comment: Fix a problem with running ALTER TABLE ADD COLUMN statements within a transaction that writes to one or more virtual tables.
Context
2019-10-10
16:10
Fix a problem with running ALTER TABLE ADD COLUMN statements within a transaction that writes to one or more virtual tables. Fix for [8fe768e9]. check-in: a4974a0f user: drh tags: branch-3.30
2019-10-07
20:33
Omit a pointless memory allocation in vdbeSorterSort(). check-in: 5d76dbc5 user: drh tags: trunk
18:43
Fix a problem with running ALTER TABLE ADD COLUMN statements within a transaction that writes to one or more virtual tables. Fix for [8fe768e9]. check-in: 31e85fbb user: dan tags: trunk
13:46
Add a test case for the assert() fix in the previous commit. check-in: 32fba11a user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/test/fts5misc.test.

    54     54   db close
    55     55   sqlite3 db test.db
    56     56   
    57     57   do_catchsql_test 1.3.3 {
    58     58     SELECT a FROM t1
    59     59       WHERE rank = (SELECT highlight(t1, 4, '<b>', '</b>') FROM t1('*reads'));
    60     60   } {1 {no such cursor: 1}}
           61  +
           62  +#-------------------------------------------------------------------------
           63  +reset_db
           64  +do_execsql_test 2.0 {
           65  +  CREATE TABLE t0(c0);
           66  +  CREATE VIRTUAL TABLE vt0 USING fts5(c0);
           67  +}
           68  +do_execsql_test 2.1.1 {
           69  +  BEGIN TRANSACTION;
           70  +  INSERT INTO vt0(c0) VALUES ('xyz');
           71  +}
           72  +do_execsql_test 2.1.2 {
           73  +  ALTER TABLE t0 ADD COLUMN c5;
           74  +}
           75  +do_execsql_test 2.1.3 {
           76  +  INSERT INTO vt0(vt0) VALUES('integrity-check');
           77  +}
           78  +do_execsql_test 2.1.4 {
           79  +  INSERT INTO vt0(c0) VALUES ('abc');
           80  +  COMMIT
           81  +}
           82  +do_execsql_test 2.1.5 {
           83  +  INSERT INTO vt0(vt0) VALUES('integrity-check');
           84  +}
           85  +
           86  +reset_db
           87  +do_execsql_test 2.2.1 {
           88  +  CREATE TABLE t0(c0);
           89  +  CREATE VIRTUAL TABLE vt0 USING fts5(c0);
           90  +  BEGIN TRANSACTION;
           91  +  INSERT INTO vt0(c0) VALUES ('xyz');
           92  +}
           93  +
           94  +breakpoint
           95  +do_execsql_test 2.2.2 {
           96  +  ALTER TABLE t0 RENAME TO t1;
           97  +}
           98  +do_execsql_test 2.2.3 {
           99  +  INSERT INTO vt0(vt0) VALUES('integrity-check');
          100  +}
          101  +do_execsql_test 2.2.4 {
          102  +  INSERT INTO vt0(c0) VALUES ('abc');
          103  +  COMMIT;
          104  +}
          105  +do_execsql_test 2.2.5 {
          106  +  INSERT INTO vt0(vt0) VALUES('integrity-check');
          107  +}
          108  +
    61    109   
    62    110   finish_test
    63    111   

Changes to src/alter.c.

   431    431       sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
   432    432       goto exit_begin_add_column;
   433    433     }
   434    434     if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
   435    435       goto exit_begin_add_column;
   436    436     }
   437    437   
          438  +  sqlite3MayAbort(pParse);
   438    439     assert( pTab->addColOffset>0 );
   439    440     iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
   440    441   
   441    442     /* Put a copy of the Table struct in Parse.pNewTable for the
   442    443     ** sqlite3AddColumn() function and friends to modify.  But modify
   443    444     ** the name by adding an "sqlite_altertab_" prefix.  By adding this
   444    445     ** prefix, we insure that the name will not collide with an existing

Changes to src/vdbeaux.c.

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