aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-07-14 14:48:50 +0000
committerdrh <drh@noemail.net>2015-07-14 14:48:50 +0000
commit201e0c68f7d5d19ba759f56fadd0d58c838c41f9 (patch)
tree42b4e67d1429509432cdbb6d2892d16fa1182d52
parentebad80e3733d223b5b54dc3c76bb0ef818715bd2 (diff)
downloadsqlite-201e0c68f7d5d19ba759f56fadd0d58c838c41f9.tar.gz
sqlite-201e0c68f7d5d19ba759f56fadd0d58c838c41f9.zip
Always invoke the profile callback even if the statement does not run to
completion. FossilOrigin-Name: 202479aa0a62067343e724487960b8a039e2e978
-rw-r--r--manifest16
-rw-r--r--manifest.uuid2
-rw-r--r--src/vdbeapi.c50
-rw-r--r--test/trace.test8
4 files changed, 55 insertions, 21 deletions
diff --git a/manifest b/manifest
index c87e7f0d2..a07ab9a0d 100644
--- 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
diff --git a/manifest.uuid b/manifest.uuid
index 649bb1286..e4e6a3512 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-e548d77b3c91cdf11c78d1a688fd768e209bdbf5 \ No newline at end of file
+202479aa0a62067343e724487960b8a039e2e978 \ No newline at end of file
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index 010fbfba1..4687aac51 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -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 ){
diff --git a/test/trace.test b/test/trace.test
index a64cc333f..fd51d7ab6 100644
--- a/test/trace.test
+++ b/test/trace.test
@@ -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 {