/ Check-in [a9b6a067]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Minor simplification to the OP_AutoCommit opcode. Fix some code comments related to transaction control.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a9b6a0672f84dd205f9333951e4c2a608d027d71
User & Date: drh 2016-02-01 13:21:13
Context
2016-02-01
13:58
Fix a problem causing the OR/covering-index optimization to be disabled if compile time parameter SQLITE_MAX_ATTACHED were set to greater than 30. check-in: a17712bf user: dan tags: trunk
13:21
Minor simplification to the OP_AutoCommit opcode. Fix some code comments related to transaction control. check-in: a9b6a067 user: drh tags: trunk
00:21
Fix an assert() that might fail on a corrupt database. check-in: 22eaced7 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  3888   3888         p->a[i].fg.jointype = p->a[i-1].fg.jointype;
  3889   3889       }
  3890   3890       p->a[0].fg.jointype = 0;
  3891   3891     }
  3892   3892   }
  3893   3893   
  3894   3894   /*
  3895         -** Begin a transaction
         3895  +** Generate VDBE code for a BEGIN statement.
  3896   3896   */
  3897   3897   void sqlite3BeginTransaction(Parse *pParse, int type){
  3898   3898     sqlite3 *db;
  3899   3899     Vdbe *v;
  3900   3900     int i;
  3901   3901   
  3902   3902     assert( pParse!=0 );
  3903   3903     db = pParse->db;
  3904   3904     assert( db!=0 );
  3905         -/*  if( db->aDb[0].pBt==0 ) return; */
  3906   3905     if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ){
  3907   3906       return;
  3908   3907     }
  3909   3908     v = sqlite3GetVdbe(pParse);
  3910   3909     if( !v ) return;
  3911   3910     if( type!=TK_DEFERRED ){
  3912   3911       for(i=0; i<db->nDb; i++){
  3913   3912         sqlite3VdbeAddOp2(v, OP_Transaction, i, (type==TK_EXCLUSIVE)+1);
  3914   3913         sqlite3VdbeUsesBtree(v, i);
  3915   3914       }
  3916   3915     }
  3917         -  sqlite3VdbeAddOp2(v, OP_AutoCommit, 0, 0);
         3916  +  sqlite3VdbeAddOp0(v, OP_AutoCommit);
  3918   3917   }
  3919   3918   
  3920   3919   /*
  3921         -** Commit a transaction
         3920  +** Generate VDBE code for a COMMIT statement.
  3922   3921   */
  3923   3922   void sqlite3CommitTransaction(Parse *pParse){
  3924   3923     Vdbe *v;
  3925   3924   
  3926   3925     assert( pParse!=0 );
  3927   3926     assert( pParse->db!=0 );
  3928   3927     if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ){
  3929   3928       return;
  3930   3929     }
  3931   3930     v = sqlite3GetVdbe(pParse);
  3932   3931     if( v ){
  3933         -    sqlite3VdbeAddOp2(v, OP_AutoCommit, 1, 0);
         3932  +    sqlite3VdbeAddOp1(v, OP_AutoCommit, 1);
  3934   3933     }
  3935   3934   }
  3936   3935   
  3937   3936   /*
  3938         -** Rollback a transaction
         3937  +** Generate VDBE code for a ROLLBACK statement.
  3939   3938   */
  3940   3939   void sqlite3RollbackTransaction(Parse *pParse){
  3941   3940     Vdbe *v;
  3942   3941   
  3943   3942     assert( pParse!=0 );
  3944   3943     assert( pParse->db!=0 );
  3945   3944     if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0) ){

Changes to src/vdbe.c.

  3004   3004   ** there are active writing VMs or active VMs that use shared cache.
  3005   3005   **
  3006   3006   ** This instruction causes the VM to halt.
  3007   3007   */
  3008   3008   case OP_AutoCommit: {
  3009   3009     int desiredAutoCommit;
  3010   3010     int iRollback;
  3011         -  int turnOnAC;
  3012   3011   
  3013   3012     desiredAutoCommit = pOp->p1;
  3014   3013     iRollback = pOp->p2;
  3015         -  turnOnAC = desiredAutoCommit && !db->autoCommit;
  3016   3014     assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
  3017   3015     assert( desiredAutoCommit==1 || iRollback==0 );
  3018   3016     assert( db->nVdbeActive>0 );  /* At least this one VM is active */
  3019   3017     assert( p->bIsReader );
  3020   3018   
  3021         -  if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){
  3022         -    /* If this instruction implements a COMMIT and other VMs are writing
  3023         -    ** return an error indicating that the other VMs must complete first. 
  3024         -    */
  3025         -    sqlite3VdbeError(p, "cannot commit transaction - "
  3026         -                        "SQL statements in progress");
  3027         -    rc = SQLITE_BUSY;
  3028         -  }else if( desiredAutoCommit!=db->autoCommit ){
         3019  +  if( desiredAutoCommit!=db->autoCommit ){
  3029   3020       if( iRollback ){
  3030   3021         assert( desiredAutoCommit==1 );
  3031   3022         sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
  3032   3023         db->autoCommit = 1;
         3024  +    }else if( desiredAutoCommit && db->nVdbeWrite>0 ){
         3025  +      /* If this instruction implements a COMMIT and other VMs are writing
         3026  +      ** return an error indicating that the other VMs must complete first. 
         3027  +      */
         3028  +      sqlite3VdbeError(p, "cannot commit transaction - "
         3029  +                          "SQL statements in progress");
         3030  +      rc = SQLITE_BUSY;
         3031  +      break;
  3033   3032       }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
  3034   3033         goto vdbe_return;
  3035   3034       }else{
  3036   3035         db->autoCommit = (u8)desiredAutoCommit;
  3037   3036       }
  3038   3037       if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
  3039   3038         p->pc = (int)(pOp - aOp);

Changes to src/vdbeaux.c.

   530    530     Parse *pParse = p->pParse;
   531    531     int *aLabel = pParse->aLabel;
   532    532     p->readOnly = 1;
   533    533     p->bIsReader = 0;
   534    534     for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
   535    535       u8 opcode = pOp->opcode;
   536    536   
   537         -    /* NOTE: Be sure to update mkopcodeh.awk when adding or removing
          537  +    /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
   538    538       ** cases from this switch! */
   539    539       switch( opcode ){
   540    540         case OP_Transaction: {
   541    541           if( pOp->p2!=0 ) p->readOnly = 0;
   542    542           /* fall thru */
   543    543         }
   544    544         case OP_AutoCommit: