]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
The date and time functions use the exact same notion of "now" for every
authordrh <drh@noemail.net>
Mon, 16 Sep 2013 12:57:19 +0000 (12:57 +0000)
committerdrh <drh@noemail.net>
Mon, 16 Sep 2013 12:57:19 +0000 (12:57 +0000)
invocation within the same call to sqlite3_step().

FossilOrigin-Name: daf6ba413cb3cb6065774ba07495eab4a28b49b0

manifest
manifest.uuid
src/date.c
src/sqliteInt.h
src/vdbe.c
src/vdbeInt.h
src/vdbeapi.c
test/date.test

index ff008ce7d2b22fa661c8b1b003989242ed920f52..cc269e2b53ea96ade1fabda24392273ee4540619 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sWindows\sSDK\scompiler\swarning.
-D 2013-09-13T23:27:39.040
+C The\sdate\sand\stime\sfunctions\suse\sthe\sexact\ssame\snotion\sof\s"now"\sfor\severy\ninvocation\swithin\sthe\ssame\scall\sto\ssqlite3_step().
+D 2013-09-16T12:57:19.083
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -170,7 +170,7 @@ F src/build.c f63e8929c7f89c0074fbc74929bc946ea117b2f8
 F src/callback.c f99a8957ba2adf369645fac0db09ad8adcf1caa2
 F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
 F src/ctime.c ea4b7f3623a0fcb1146e7f245d7410033e86859c
-F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4
+F src/date.c 65196e95e69f36993659bd7781abe7c2f1994739
 F src/delete.c 2dc64ca360b7d7da481183ea920a813a0c203c97
 F src/expr.c 1017f482217e093ecdaca91e8666681e83733252
 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
@@ -221,7 +221,7 @@ F src/shell.c d920a891ca09b8bd262cced7fb0ab9d723f7a747
 F src/sqlite.h.in ec40aa958a270416fb04b4f72210357bf163d2c5
 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
-F src/sqliteInt.h 896034293a7e52e2d4a6edff61a797f36d43c0a9
+F src/sqliteInt.h 18c7f80e7e23098942436f7286e9c93adc6908be
 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
 F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -277,10 +277,10 @@ F src/update.c f5182157f5d0d0a97bc5f5e3c9bdba0dfbe08f08
 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
 F src/util.c 7f3e35432d6888d1e770c488c35bd98970c44eec
 F src/vacuum.c d9c5759f4c5a438bb43c2086f72c5d2edabc36c8
-F src/vdbe.c a393a94c0d77b86c7c4ad2cfb43ec4ba278d9596
+F src/vdbe.c 56e648f5ba9a91810caf216857adfed9039cd174
 F src/vdbe.h 4f554b5627f26710c4c36d919110a3fc611ca5c4
-F src/vdbeInt.h cbe71b8b36d8b3bba5709cc3f436c7e3b47b7b08
-F src/vdbeapi.c 96b24b946cf21894f63d9393e821baa2f0a80979
+F src/vdbeInt.h ff57f67aee1ba26a3a47e786533dab155ab6dad6
+F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed
 F src/vdbeaux.c 88beca92f2ed0bbe2c6f87946d0e999a6807ea1b
 F src/vdbeblob.c 5dc79627775bd9a9b494dd956e26297946417d69
 F src/vdbemem.c 817ce21ab4ca57f902619bb8fef3f8a51bbd0ed8
@@ -413,7 +413,7 @@ F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
 F test/createtab.test b5de160630b209c4b8925bdcbbaf48cc90b67fe8
 F test/cse.test 277350a26264495e86b1785f34d2d0c8600e021c
 F test/ctime.test 7bd009071e242aac4f18521581536b652b789a47
-F test/date.test f3228180c87bbe5d39c9397bf001c0095c3821b9
+F test/date.test 502ddcbaaac9ce103bcd76d8e9d9bc8aa04e61b0
 F test/dbstatus.test aee30c3f337e6c217ff06df59fb8fe6e6448dce2
 F test/dbstatus2.test 10418e62b3db5dca070f0c3eef3ea13946f339c2
 F test/default.test 6faf23ccb300114924353007795aa9a8ec0aa9dc
@@ -1114,7 +1114,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P 650b32825a85baff11b8e568649fd797066c8ab1
-R 86c4f81df3e0f8f912478820f6baf7a0
-U mistachkin
-Z 2b97a046c7bb8da4da56f5c1f9954d1c
+P d5fc3f1dabc7227230dcabdd808357f63432357b
+R ead99db3a62653402af31bb55f28a609
+U drh
+Z 697f82a0e98989fae400e82ea730851a
index ca910973a5ea4e58baa3b6e8156c17d6e0e0ea34..ed50928ac91927f93f79325e6725bb690358b580 100644 (file)
@@ -1 +1 @@
-d5fc3f1dabc7227230dcabdd808357f63432357b
\ No newline at end of file
+daf6ba413cb3cb6065774ba07495eab4a28b49b0
\ No newline at end of file
index 758dd7c89bca3937a90d706ea982ce3acf11d183..5fe3f67867f6bcfa8c09a4bc83e9819e182890da 100644 (file)
@@ -294,8 +294,8 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
 ** Return the number of errors.
 */
 static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
-  sqlite3 *db = sqlite3_context_db_handle(context);
-  if( sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD)==SQLITE_OK ){
+  p->iJD = sqlite3StmtCurrentTime(context);
+  if( p->iJD>0 ){
     p->validJD = 1;
     return 0;
   }else{
@@ -1078,8 +1078,8 @@ static void currentTimeFunc(
   UNUSED_PARAMETER(argc);
   UNUSED_PARAMETER(argv);
 
-  db = sqlite3_context_db_handle(context);
-  if( sqlite3OsCurrentTimeInt64(db->pVfs, &iT) ) return;
+  iT = sqlite3StmtCurrentTime(context);
+  if( iT<=0 ) return;
   t = iT/1000 - 10000*(sqlite3_int64)21086676;
 #ifdef HAVE_GMTIME_R
   pTm = gmtime_r(&t, &sNow);
index 8d01b902f1f34ee88bc1f4a025fec1973579a532..4a52b64f6290e74daa0ed8ba8ee3b8e50087bb1c 100644 (file)
@@ -3184,6 +3184,7 @@ int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
 int sqlite3VtabBegin(sqlite3 *, VTable *);
 FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
 void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
+sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
 int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
 int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
 int sqlite3Reprepare(Vdbe*);
index 70d06eb31f20b7c6e1dee78bd887c28789f3ebb0..c75aadb19c0cfe14ff36d3c10414e4cb74a52bb6 100644 (file)
@@ -567,6 +567,7 @@ int sqlite3VdbeExec(
   assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
   assert( p->bIsReader || p->readOnly!=0 );
   p->rc = SQLITE_OK;
+  p->iCurrentTime = 0;
   assert( p->explain==0 );
   p->pResultSet = 0;
   db->busyHandler.nBusy = 0;
index a699c414b0a9e162387e95313755ea81b854688a..3cac04016cd27ef531908a4e031ef94e71cdae1e 100644 (file)
@@ -350,6 +350,7 @@ struct Vdbe {
 #ifndef SQLITE_OMIT_TRACE
   i64 startTime;          /* Time when query started - used for profiling */
 #endif
+  i64 iCurrentTime;       /* Value of julianday('now') for this statement */
   i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
   i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
   i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
index 52c6b2a797b4d5c244b8450cdb009382b2de071b..d51256217413188766279307e3a9721b9ed8e94c 100644 (file)
@@ -510,6 +510,7 @@ int sqlite3_step(sqlite3_stmt *pStmt){
   return rc;
 }
 
+
 /*
 ** Extract the user data from a sqlite3_context structure and return a
 ** pointer to it.
@@ -534,6 +535,19 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
   return p->s.db;
 }
 
+/*
+** Return the current time for a statement
+*/
+sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){
+  Vdbe *v = p->pVdbe;
+  int rc;
+  if( v->iCurrentTime==0 ){
+    rc = sqlite3OsCurrentTimeInt64(p->s.db->pVfs, &v->iCurrentTime);
+    if( rc ) v->iCurrentTime = 0;
+  }
+  return v->iCurrentTime;
+}
+
 /*
 ** The following is the implementation of an SQL function that always
 ** fails with an error message stating that the function is used in the
index a30402c0d655d3205c1282ffd5fbd56362780437..895b415436b53ae37902b2ec44586b86415bcdb0 100644 (file)
@@ -528,4 +528,23 @@ if {0==[sqlite3 -has-codec]} {
     } {1}
   }
 }
+
+# Verify that multiple calls to date functions with 'now' return the
+# same answer.
+#
+proc sleeper {} {after 100}
+do_test date-15.1 {
+  db func sleeper sleeper
+  db eval {
+     SELECT c - a FROM (SELECT julianday('now') AS a,
+                               sleeper(), julianday('now') AS c);
+  }
+} {0.0}
+do_test date-15.2 {
+  db eval {
+     SELECT a==b FROM (SELECT current_timestamp AS a,
+                               sleeper(), current_timestamp AS b);
+  }
+} {1}
+
 finish_test