/ Check-in [ac1fd6be]
Login

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

Overview
Comment:Allow ATTACH and DETACH to occur inside of a transaction.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | attach-in-trans
Files: files | file ages | folders
SHA3-256: ac1fd6beb6c804af5faf1e06a51177a8316007ff9e718c398bd7a24d2ecc4ed3
User & Date: drh 2017-07-26 18:26:44
Context
2017-08-01
00:20
Allow ATTACH and DETACH inside of a transaction. check-in: 95e8f316 user: drh tags: trunk
2017-07-26
18:26
Allow ATTACH and DETACH to occur inside of a transaction. Closed-Leaf check-in: ac1fd6be user: drh tags: attach-in-trans
10:04
Fix a comment on the UnpackedRecord.r1 and UnpackedRecord.r2 fields. No changes to code. check-in: 622b1089 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/attach.c.

    89     89     */
    90     90     if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
    91     91       zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d", 
    92     92         db->aLimit[SQLITE_LIMIT_ATTACHED]
    93     93       );
    94     94       goto attach_error;
    95     95     }
    96         -  if( !db->autoCommit ){
    97         -    zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
    98         -    goto attach_error;
    99         -  }
   100     96     for(i=0; i<db->nDb; i++){
   101     97       char *z = db->aDb[i].zDbSName;
   102     98       assert( z && zName );
   103     99       if( sqlite3StrICmp(z, zName)==0 ){
   104    100         zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
   105    101         goto attach_error;
   106    102       }
................................................................................
   284    280       sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
   285    281       goto detach_error;
   286    282     }
   287    283     if( i<2 ){
   288    284       sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);
   289    285       goto detach_error;
   290    286     }
   291         -  if( !db->autoCommit ){
   292         -    sqlite3_snprintf(sizeof(zErr), zErr,
   293         -                     "cannot DETACH database within transaction");
   294         -    goto detach_error;
   295         -  }
   296    287     if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
   297    288       sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
   298    289       goto detach_error;
   299    290     }
   300    291   
   301    292     sqlite3BtreeClose(pDb->pBt);
   302    293     pDb->pBt = 0;

Changes to test/attach2.test.

   370    370     execsql {
   371    371       BEGIN;
   372    372     }
   373    373   } {}
   374    374   do_test attach2-6.2 {
   375    375     catchsql {
   376    376       ATTACH 'test3.db' as aux2;
          377  +    DETACH aux2;
   377    378     }
   378         -} {1 {cannot ATTACH database within transaction}}
          379  +} {0 {}}
   379    380   
   380    381   # EVIDENCE-OF: R-59740-55581 This statement will fail if SQLite is in
   381    382   # the middle of a transaction.
   382    383   #
   383    384   do_test attach2-6.3 {
   384    385     catchsql {
   385    386       DETACH aux;
   386    387     }
   387         -} {1 {cannot DETACH database within transaction}}
   388         -do_test attach2-6.4 {
   389         -  execsql {
   390         -    COMMIT;
   391         -    DETACH aux;
   392         -  }
   393         -} {}
          388  +} {0 {}}
   394    389   
   395    390   db close
   396    391   
   397    392   finish_test

Changes to test/savepoint.test.

   611    611   #-------------------------------------------------------------------------
   612    612   # The following tests - savepoint-10.* - test the interaction of 
   613    613   # savepoints and ATTACH statements.
   614    614   # 
   615    615   
   616    616   # First make sure it is not possible to attach or detach a database while
   617    617   # a savepoint is open (it is not possible if any transaction is open).
          618  +#
          619  +# UPDATE 2017-07-26:  It is not possible to ATTACH and DETACH within a
          620  +# a transaction.
   618    621   #
   619    622   do_test savepoint-10.1.1 {
   620    623     catchsql {
   621    624       SAVEPOINT one;
   622    625       ATTACH 'test2.db' AS aux;
          626  +    DETACH aux;
   623    627     }
   624         -} {1 {cannot ATTACH database within transaction}}
          628  +} {0 {}}
   625    629   do_test savepoint-10.1.2 {
   626    630     execsql {
   627    631       RELEASE one;
   628    632       ATTACH 'test2.db' AS aux;
   629    633     }
   630    634     catchsql {
   631    635       SAVEPOINT one;
   632    636       DETACH aux;
          637  +    ATTACH 'test2.db' AS aux;
   633    638     }
   634         -} {1 {cannot DETACH database within transaction}}
          639  +} {0 {}}
   635    640   do_test savepoint-10.1.3 {
   636    641     execsql {
   637    642       RELEASE one;
   638    643       DETACH aux;
   639    644     }
   640    645   } {}
   641    646