]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Always invoke the profile callback even if the statement does not run to
authordrh <drh@noemail.net>
Tue, 14 Jul 2015 14:48:50 +0000 (14:48 +0000)
committerdrh <drh@noemail.net>
Tue, 14 Jul 2015 14:48:50 +0000 (14:48 +0000)
completion.

FossilOrigin-Name: 202479aa0a62067343e724487960b8a039e2e978

manifest
manifest.uuid
src/vdbeapi.c
test/trace.test

index c87e7f0d2be4e362c7b9b07cd76d4d80cea7e756..a07ab9a0dd486a8b2833c4e14f420649e3604b88 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Refine\scleaning\sof\sFTS5\sfiles\sby\sMakefile\stargets.
-D 2015-07-14T00:36:34.209
+C Always\sinvoke\sthe\sprofile\scallback\seven\sif\sthe\sstatement\sdoes\snot\srun\sto\ncompletion.
+D 2015-07-14T14:48:50.217
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2a4a94d9c6ad8cde388b672d89d1463e6f38a6da
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -393,7 +393,7 @@ F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701
 F src/vdbe.c 5ee4a2bf871418f61d06dc256b9b3a0084b5ec46
 F src/vdbe.h 7a75045d879118b9d3af7e8b3c108f2f27c51473
 F src/vdbeInt.h 8b54e01ad0463590e7cffabce0bc36da9ee4f816
-F src/vdbeapi.c 6a0d7757987018ff6b1b81bc5293219cd26bb299
+F src/vdbeapi.c 2fa7ed7520313d6dd1dc6e6495999201c630adfc
 F src/vdbeaux.c 787f5f9d58f4c6f39294ed06909ba602d1a402e6
 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90
 F src/vdbemem.c ae38a0d35ae71cf604381a887c170466ba518090
@@ -1183,7 +1183,7 @@ F test/tkt3997.test a335fa41ca3985660a139df7b734a26ef53284bd
 F test/tkt4018.test 7c2c9ba4df489c676a0a7a0e809a1fb9b2185bd1
 F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
 F test/tpch01.test 04adbf8d8300fa60a222f28d901abd76e7be6dd4
-F test/trace.test 73a5508100f7fccfbc3f8018d5f6963ed478eea0
+F test/trace.test 6f676313e3ebd2a50585036d2f212a3319dd5836
 F test/trace2.test f5cb67ad3bc09e0c58e8cca78dfd0b5639259983
 F test/trans.test 6e1b4c6a42dba31bd65f8fa5e61a2708e08ddde6
 F test/trans2.test 62bd045bfc7a1c14c5ba83ba64d21ade31583f76
@@ -1365,7 +1365,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 5c76c062c0cbf7c95897c5de4868172292023303
-R 426b5fccc68ae98e50db8b48fd4e7d32
-U mistachkin
-Z 30f4df410df2e184bde2b63910ad9db6
+P e548d77b3c91cdf11c78d1a688fd768e209bdbf5
+R f434f0b9092147e4e9389e2958ccbd33
+U drh
+Z 3bea78814fd8f9c4678ec13302736bdc
index 649bb12860f0b6ca9ac31a311fb2e021b79401da..e4e6a3512aead09c06eb4a820c95c112aa5c8e36 100644 (file)
@@ -1 +1 @@
-e548d77b3c91cdf11c78d1a688fd768e209bdbf5
\ No newline at end of file
+202479aa0a62067343e724487960b8a039e2e978
\ No newline at end of file
index 010fbfba167225479becf3e740dd07e54f1be162..4687aac5104b128566dcdd7ad8da2110270a9753 100644 (file)
@@ -53,6 +53,31 @@ static int vdbeSafetyNotNull(Vdbe *p){
   }
 }
 
+#ifndef SQLITE_OMIT_TRACE
+/*
+** Invoke the profile callback.  This routine is only called if we already
+** know that the profile callback is defined and needs to be invoked.
+*/
+static SQLITE_NOINLINE void invokeProfileCallback(sqlite3 *db, Vdbe *p){
+  sqlite3_int64 iNow;
+  assert( p->startTime>0 );
+  assert( db->xProfile!=0 );
+  assert( db->init.busy==0 );
+  assert( p->zSql!=0 );
+  sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
+  db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
+  p->startTime = 0;
+}
+/*
+** The checkProfileCallback(DB,P) macro checks to see if a profile callback
+** is needed, and it invokes the callback if it is needed.
+*/
+# define checkProfileCallback(DB,P) \
+   if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); }
+#else
+# define checkProfileCallback(DB,P)  /*no-op*/
+#endif
+
 /*
 ** The following routine destroys a virtual machine that is created by
 ** the sqlite3_compile() routine. The integer returned is an SQLITE_
@@ -73,6 +98,7 @@ int sqlite3_finalize(sqlite3_stmt *pStmt){
     sqlite3 *db = v->db;
     if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
     sqlite3_mutex_enter(db->mutex);
+    checkProfileCallback(db, v);
     rc = sqlite3VdbeFinalize(v);
     rc = sqlite3ApiExit(db, rc);
     sqlite3LeaveMutexAndCloseZombie(db);
@@ -94,12 +120,14 @@ int sqlite3_reset(sqlite3_stmt *pStmt){
     rc = SQLITE_OK;
   }else{
     Vdbe *v = (Vdbe*)pStmt;
-    sqlite3_mutex_enter(v->db->mutex);
+    sqlite3 *db = v->db;
+    sqlite3_mutex_enter(db->mutex);
+    checkProfileCallback(db, v);
     rc = sqlite3VdbeReset(v);
     sqlite3VdbeRewind(v);
-    assert( (rc & (v->db->errMask))==rc );
-    rc = sqlite3ApiExit(v->db, rc);
-    sqlite3_mutex_leave(v->db->mutex);
+    assert( (rc & (db->errMask))==rc );
+    rc = sqlite3ApiExit(db, rc);
+    sqlite3_mutex_leave(db->mutex);
   }
   return rc;
 }
@@ -450,6 +478,7 @@ static int doWalCallbacks(sqlite3 *db){
   return rc;
 }
 
+
 /*
 ** Execute the statement pStmt, either until a row of data is ready, the
 ** statement is completely executed or an error occurs.
@@ -518,8 +547,10 @@ static int sqlite3Step(Vdbe *p){
     );
 
 #ifndef SQLITE_OMIT_TRACE
-    if( db->xProfile && !db->init.busy ){
+    if( db->xProfile && !db->init.busy && p->zSql ){
       sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
+    }else{
+      assert( p->startTime==0 );
     }
 #endif
 
@@ -543,13 +574,8 @@ static int sqlite3Step(Vdbe *p){
   }
 
 #ifndef SQLITE_OMIT_TRACE
-  /* Invoke the profile callback if there is one
-  */
-  if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
-    sqlite3_int64 iNow;
-    sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
-    db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
-  }
+  /* If the statement completed successfully, invoke the profile callback */
+  if( rc!=SQLITE_ROW ) checkProfileCallback(db, p);
 #endif
 
   if( rc==SQLITE_DONE ){
index a64cc333fa59d483c7a7eeedeaf0f9fb2fbdba9a..fd51d7ab64a9f2458a45d1d56bf6dfa7bb8856dd 100644 (file)
@@ -169,6 +169,14 @@ do_test trace-4.5 {
 } {{SELECT * FROM t1}}
 catch {sqlite3_finalize $STMT}
 
+# 3.8.11: Profile output even if the statement is not run to completion.
+do_test trace-4.6 {
+  set TRACE_OUT {}
+  db eval {SELECT * FROM t1} {} {if {$a>=1} break}
+  set TRACE_OUT
+} {{SELECT * FROM t1}}
+
+
 # Trigger tracing.
 #
 ifcapable trigger {