/ Check-in [6071b7cc]
Login

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

Overview
Comment:When closing a connection, avoid tripping active cursors belonging to a different shared-cache client. Also, if sqlite3_close() is called while there are still active statements belonging to the connection, return SQLITE_BUSY and do not roll back any active transaction. Proposed fix for ticket [e636a050b709].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | shared-cache-fixes
Files: files | file ages | folders
SHA1: 6071b7cce067c807e040283fc4b7449dc6eca498
User & Date: dan 2013-05-15 10:21:50
Original Comment: When closing a connection, avoid tripping active cursors belonging to a different shared-cache client. Also, if sqlite3_close() is called while there are still active statements belonging to the connection, return SQLITE_BUSY and do not roll back any active transaction.
Context
2013-05-15
15:42
Merge latest trunk changes with this branch. check-in: 47dd65a8 user: dan tags: shared-cache-fixes
10:21
When closing a connection, avoid tripping active cursors belonging to a different shared-cache client. Also, if sqlite3_close() is called while there are still active statements belonging to the connection, return SQLITE_BUSY and do not roll back any active transaction. Proposed fix for ticket [e636a050b709]. check-in: 6071b7cc user: dan tags: shared-cache-fixes
2013-05-14
23:13
Merge together the fork in this branch. check-in: 164e3d4d user: drh tags: shared-cache-fixes
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

   832    832     /* If a transaction is open, the disconnectAllVtab() call above
   833    833     ** will not have called the xDisconnect() method on any virtual
   834    834     ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
   835    835     ** call will do so. We need to do this before the check for active
   836    836     ** SQL statements below, as the v-table implementation may be storing
   837    837     ** some prepared statements internally.
   838    838     */
   839         -  sqlite3RollbackAll(db, SQLITE_ABORT);
          839  +  sqlite3VtabRollback(db);
   840    840   
   841    841     /* Legacy behavior (sqlite3_close() behavior) is to return
   842    842     ** SQLITE_BUSY if the connection can not be closed immediately.
   843    843     */
   844    844     if( !forceZombie && connectionIsBusy(db) ){
   845    845       sqlite3Error(db, SQLITE_BUSY, "unable to close due to unfinalized "
   846    846          "statements or unfinished backups");
   847    847       sqlite3_mutex_leave(db->mutex);
   848    848       return SQLITE_BUSY;
   849    849     }
          850  +
          851  +  /* If a transaction is open, roll it back. This also ensures that if
          852  +  ** any database schemas have been modified by the current transaction
          853  +  ** they are reset. And that the required b-tree mutex is held to make
          854  +  ** the the pager rollback and schema reset an atomic operation. */
          855  +  sqlite3RollbackAll(db, SQLITE_OK);
   850    856   
   851    857   #ifdef SQLITE_ENABLE_SQLLOG
   852    858     if( sqlite3GlobalConfig.xSqllog ){
   853    859       /* Closing the handle. Fourth parameter is passed the value 2. */
   854    860       sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
   855    861     }
   856    862   #endif

Changes to test/misuse.test.

   166    166   do_test misuse-4.3 {
   167    167     set v [catch {
   168    168       db eval {SELECT * FROM t1} {} {
   169    169         set r [sqlite3_close $::DB]
   170    170       }
   171    171     } msg]
   172    172     lappend v $msg $r
   173         -} {1 {callback requested query abort} SQLITE_BUSY}
          173  +} {0 {} SQLITE_BUSY}
   174    174   do_test misuse-4.4 {
   175    175     # Flush the TCL statement cache here, otherwise the sqlite3_close() will
   176    176     # fail because there are still un-finalized() VDBEs.
   177    177     db cache flush
   178    178     sqlite3_close $::DB
   179    179     catchsql2 {SELECT * FROM t1}
   180    180   } {1 {library routine called out of sequence}}