/ Check-in [549f4fd0]
Login

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

Overview
Comment:Add the new SQLITE_ABORT_ROLLBACK extended error code to be returned for statements that are cancelled due to a rollback.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nonblocking-rollback
Files: files | file ages | folders
SHA1:549f4fd00d8325c10099b100e5202b77ee1d83ad
User & Date: drh 2012-02-13 17:01:51
Context
2012-02-13
21:24
Merge the non-blocking ROLLBACK changes into trunk. check-in: 9c572d42 user: drh tags: trunk
17:01
Add the new SQLITE_ABORT_ROLLBACK extended error code to be returned for statements that are cancelled due to a rollback. Closed-Leaf check-in: 549f4fd0 user: drh tags: nonblocking-rollback
16:43
Change the ROLLBACK command so that pending statements to not block it. The pending statements instead return SQLITE_ABORT upon next access. Note: This causes separate shared-cache connections in read_uncommitted mode to abort as well. check-in: 9b66c79e user: drh tags: nonblocking-rollback
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

   916    916       /* SQLITE_MISUSE      */ "library routine called out of sequence",
   917    917       /* SQLITE_NOLFS       */ "large file support is disabled",
   918    918       /* SQLITE_AUTH        */ "authorization denied",
   919    919       /* SQLITE_FORMAT      */ "auxiliary database format error",
   920    920       /* SQLITE_RANGE       */ "bind or column index out of range",
   921    921       /* SQLITE_NOTADB      */ "file is encrypted or is not a database",
   922    922     };
   923         -  rc &= 0xff;
   924         -  if( ALWAYS(rc>=0) && rc<(int)(sizeof(aMsg)/sizeof(aMsg[0])) && aMsg[rc]!=0 ){
   925         -    return aMsg[rc];
   926         -  }else{
   927         -    return "unknown error";
          923  +  const char *zErr = "unknown error";
          924  +  switch( rc ){
          925  +    case SQLITE_ABORT_ROLLBACK: {
          926  +      zErr = "abort due to ROLLBACK";
          927  +      break;
          928  +    }
          929  +    default: {
          930  +      rc &= 0xff;
          931  +      if( ALWAYS(rc>=0) && rc<ArraySize(aMsg) && aMsg[rc]!=0 ){
          932  +        zErr = aMsg[rc];
          933  +      }
          934  +      break;
          935  +    }
   928    936     }
          937  +  return zErr;
   929    938   }
   930    939   
   931    940   /*
   932    941   ** This routine implements a busy callback that sleeps and tries
   933    942   ** again until a timeout value is reached.  The timeout value is
   934    943   ** an integer number of milliseconds passed in as the first
   935    944   ** argument.

Changes to src/sqlite.h.in.

   452    452   #define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
   453    453   #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
   454    454   #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
   455    455   #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
   456    456   #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
   457    457   #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
   458    458   #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
          459  +#define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
   459    460   
   460    461   /*
   461    462   ** CAPI3REF: Flags For File Open Operations
   462    463   **
   463    464   ** These bit values are intended for use in the
   464    465   ** 3rd parameter to the [sqlite3_open_v2()] interface and
   465    466   ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.

Changes to src/vdbe.c.

  2802   2802       */
  2803   2803       sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
  2804   2804           "SQL statements in progress");
  2805   2805       rc = SQLITE_BUSY;
  2806   2806     }else if( desiredAutoCommit!=db->autoCommit ){
  2807   2807       if( iRollback ){
  2808   2808         assert( desiredAutoCommit==1 );
  2809         -      sqlite3RollbackAll(db, SQLITE_ABORT);
         2809  +      sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
  2810   2810         db->autoCommit = 1;
  2811   2811       }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
  2812   2812         goto vdbe_return;
  2813   2813       }else{
  2814   2814         db->autoCommit = (u8)desiredAutoCommit;
  2815   2815         if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
  2816   2816           p->pc = pc;

Changes to src/vdbeaux.c.

  2162   2162         if( !p->readOnly || mrc!=SQLITE_INTERRUPT ){
  2163   2163           if( (mrc==SQLITE_NOMEM || mrc==SQLITE_FULL) && p->usesStmtJournal ){
  2164   2164             eStatementOp = SAVEPOINT_ROLLBACK;
  2165   2165           }else{
  2166   2166             /* We are forced to roll back the active transaction. Before doing
  2167   2167             ** so, abort any other statements this handle currently has active.
  2168   2168             */
  2169         -          sqlite3RollbackAll(db, SQLITE_ABORT);
         2169  +          sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
  2170   2170             sqlite3CloseSavepoints(db);
  2171   2171             db->autoCommit = 1;
  2172   2172           }
  2173   2173         }
  2174   2174       }
  2175   2175   
  2176   2176       /* Check for immediate foreign key violations. */
................................................................................
  2219   2219         db->nStatement = 0;
  2220   2220       }else if( eStatementOp==0 ){
  2221   2221         if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
  2222   2222           eStatementOp = SAVEPOINT_RELEASE;
  2223   2223         }else if( p->errorAction==OE_Abort ){
  2224   2224           eStatementOp = SAVEPOINT_ROLLBACK;
  2225   2225         }else{
  2226         -        sqlite3RollbackAll(db, SQLITE_ABORT);
         2226  +        sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
  2227   2227           sqlite3CloseSavepoints(db);
  2228   2228           db->autoCommit = 1;
  2229   2229         }
  2230   2230       }
  2231   2231     
  2232   2232       /* If eStatementOp is non-zero, then a statement transaction needs to
  2233   2233       ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
................................................................................
  2239   2239         rc = sqlite3VdbeCloseStatement(p, eStatementOp);
  2240   2240         if( rc ){
  2241   2241           if( p->rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT ){
  2242   2242             p->rc = rc;
  2243   2243             sqlite3DbFree(db, p->zErrMsg);
  2244   2244             p->zErrMsg = 0;
  2245   2245           }
  2246         -        sqlite3RollbackAll(db, SQLITE_ABORT);
         2246  +        sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
  2247   2247           sqlite3CloseSavepoints(db);
  2248   2248           db->autoCommit = 1;
  2249   2249         }
  2250   2250       }
  2251   2251     
  2252   2252       /* If this was an INSERT, UPDATE or DELETE and no statement transaction
  2253   2253       ** has been rolled back, update the database connection change-counter. 

Changes to test/tkt-f777251dc7a.test.

    38     38   db function force_rollback force_rollback
    39     39   
    40     40   do_test tkt-f7772-1.2 {
    41     41     catchsql {
    42     42       BEGIN IMMEDIATE;
    43     43       SELECT x, force_rollback(), EXISTS(SELECT 1 FROM t3 WHERE w=x) FROM t2;
    44     44     }
    45         -} {1 {callback requested query abort}}
           45  +} {1 {abort due to ROLLBACK}}
    46     46   do_test tkt-f7772-1.3 {
    47     47     sqlite3_get_autocommit db
    48     48   } {1}
    49     49   
    50     50   do_test tkt-f7772-2.1 {
    51     51     execsql {
    52     52        DROP TABLE IF EXISTS t1;

Changes to test/trans3.test.

    60     60           if {[catch {db eval ROLLBACK} errmsg]} {
    61     61              set ::ecode [sqlite3_extended_errcode db]
    62     62              error $errmsg
    63     63           }
    64     64        }
    65     65     } errmsg]
    66     66     lappend x $errmsg
    67         -} {1 {cannot rollback transaction - SQL statements in progress}}
           67  +} {1 {abort due to ROLLBACK}}
    68     68   do_test trans3-1.6 {
    69     69     set ::ecode
    70         -} {SQLITE_BUSY}
           70  +} {}
    71     71   do_test trans3-1.7 {
    72         -  db eval COMMIT
    73     72     db eval {SELECT * FROM t1}
    74         -} {1 2 3 4 5}
           73  +} {1 2 3 4}
    75     74   unset -nocomplain ecode
    76     75   
    77     76   finish_test