/ Check-in [39f763bf]
Login

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

Overview
Comment:Avoid repeating calls to the sqlite3_trace() callback when the same statement is evaluted multiple times by sqlite3_step() due to an SQLITE_SCHEMA reprepare.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:39f763bfc04174ee0fe2cdf6a92b7c12f726bd1b
User & Date: drh 2012-09-04 21:34:26
References
2014-08-19
19:57 New ticket [11d5aa45] sqlite3_trace() sometimes does not invoke its callback. artifact: cc30ae32 user: drh
Context
2012-09-10
06:02
Fix typo in documentation for sqlite3_open_v2. No changes to code. check-in: b532120a user: mistachkin tags: trunk
2012-09-07
16:46
Add an experimental busy_timeout pragma to facilitate access to the sqlite3_busy_timeout() interfaces for programmers that are working from behind a language wrapper that does not expose that interface. check-in: 22ebc668 user: drh tags: busy-timeout-pragma
2012-09-04
21:34
Avoid repeating calls to the sqlite3_trace() callback when the same statement is evaluted multiple times by sqlite3_step() due to an SQLITE_SCHEMA reprepare. check-in: 39f763bf user: drh tags: trunk
2012-09-03
15:42
Version 3.7.14 check-in: c0d89d4a user: drh tags: trunk, release, version-3.7.14
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

  6071   6071   ** If tracing is enabled (by the sqlite3_trace()) interface, then
  6072   6072   ** the UTF-8 string contained in P4 is emitted on the trace callback.
  6073   6073   */
  6074   6074   case OP_Trace: {
  6075   6075     char *zTrace;
  6076   6076     char *z;
  6077   6077   
  6078         -  if( db->xTrace && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 ){
         6078  +  if( db->xTrace
         6079  +   && !p->doingRerun
         6080  +   && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
         6081  +  ){
  6079   6082       z = sqlite3VdbeExpandSql(p, zTrace);
  6080   6083       db->xTrace(db->pTraceArg, z);
  6081   6084       sqlite3DbFree(db, z);
  6082   6085     }
  6083   6086   #ifdef SQLITE_DEBUG
  6084   6087     if( (db->flags & SQLITE_SqlTrace)!=0
  6085   6088      && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0

Changes to src/vdbeInt.h.

   269    269     Vdbe *pVdbe;       /* Attach the explanation to this Vdbe */
   270    270     StrAccum str;      /* The string being accumulated */
   271    271     int nIndent;       /* Number of elements in aIndent */
   272    272     u16 aIndent[100];  /* Levels of indentation */
   273    273     char zBase[100];   /* Initial space */
   274    274   };
   275    275   
          276  +/* A bitfield type for use inside of structures.  Always follow with :N where
          277  +** N is the number of bits.
          278  +*/
          279  +typedef unsigned bft;  /* Bit Field Type */
          280  +
   276    281   /*
   277    282   ** An instance of the virtual machine.  This structure contains the complete
   278    283   ** state of the virtual machine.
   279    284   **
   280    285   ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
   281    286   ** is really a pointer to an instance of this structure.
   282    287   **
................................................................................
   310    315     char **azVar;           /* Name of variables */
   311    316     ynVar nVar;             /* Number of entries in aVar[] */
   312    317     ynVar nzVar;            /* Number of entries in azVar[] */
   313    318     u32 cacheCtr;           /* VdbeCursor row cache generation counter */
   314    319     int pc;                 /* The program counter */
   315    320     int rc;                 /* Value to return */
   316    321     u8 errorAction;         /* Recovery action to do in case of an error */
   317         -  u8 explain;             /* True if EXPLAIN present on SQL command */
   318         -  u8 changeCntOn;         /* True to update the change-counter */
   319         -  u8 expired;             /* True if the VM needs to be recompiled */
   320         -  u8 runOnlyOnce;         /* Automatically expire on reset */
   321    322     u8 minWriteFileFormat;  /* Minimum file format for writable database files */
   322         -  u8 inVtabMethod;        /* See comments above */
   323         -  u8 usesStmtJournal;     /* True if uses a statement journal */
   324         -  u8 readOnly;            /* True for read-only statements */
   325         -  u8 isPrepareV2;         /* True if prepared with prepare_v2() */
          323  +  bft explain:2;          /* True if EXPLAIN present on SQL command */
          324  +  bft inVtabMethod:2;     /* See comments above */
          325  +  bft changeCntOn:1;      /* True to update the change-counter */
          326  +  bft expired:1;          /* True if the VM needs to be recompiled */
          327  +  bft runOnlyOnce:1;      /* Automatically expire on reset */
          328  +  bft usesStmtJournal:1;  /* True if uses a statement journal */
          329  +  bft readOnly:1;         /* True for read-only statements */
          330  +  bft isPrepareV2:1;      /* True if prepared with prepare_v2() */
          331  +  bft doingRerun:1;       /* True if rerunning after an auto-reprepare */
   326    332     int nChange;            /* Number of db changes made since last reset */
   327    333     yDbMask btreeMask;      /* Bitmask of db->aDb[] entries referenced */
   328    334     yDbMask lockMask;       /* Subset of btreeMask that requires a lock */
   329    335     int iStatement;         /* Statement number (or 0 if has not opened stmt) */
   330    336     int aCounter[3];        /* Counters used by sqlite3_stmt_status() */
   331    337   #ifndef SQLITE_OMIT_TRACE
   332    338     i64 startTime;          /* Time when query started - used for profiling */

Changes to src/vdbeapi.c.

   474    474     sqlite3 *db;             /* The database connection */
   475    475   
   476    476     if( vdbeSafetyNotNull(v) ){
   477    477       return SQLITE_MISUSE_BKPT;
   478    478     }
   479    479     db = v->db;
   480    480     sqlite3_mutex_enter(db->mutex);
          481  +  v->doingRerun = 0;
   481    482     while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
   482    483            && cnt++ < SQLITE_MAX_SCHEMA_RETRY
   483    484            && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
   484    485       sqlite3_reset(pStmt);
          486  +    v->doingRerun = 1;
   485    487       assert( v->expired==0 );
   486    488     }
   487    489     if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
   488    490       /* This case occurs after failing to recompile an sql statement. 
   489    491       ** The error message from the SQL compiler has already been loaded 
   490    492       ** into the database handle. This block copies the error message 
   491    493       ** from the database handle into the statement and sets the statement