diff options
Diffstat (limited to 'src/date.c')
-rw-r--r-- | src/date.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/date.c b/src/date.c index a3e58bc4e..21077df93 100644 --- a/src/date.c +++ b/src/date.c @@ -331,11 +331,13 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){ } /* -** Set the time to the current time reported by the VFS. +** Set the time to the current time reported for the prepared statement +** that is currently executing. The same time is reported for all +** invocations of this routine from within the same call to sqlite3_step(). ** ** Return the number of errors. */ -static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){ +static int setCurrentStmtTime(sqlite3_context *context, DateTime *p){ p->iJD = sqlite3StmtCurrentTime(context); if( p->iJD>0 ){ p->validJD = 1; @@ -346,6 +348,23 @@ static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){ } /* +** Set the time to the current time reported for the current transaction. +** The same time is set for all calls to this routine within the same +** transaction. +** +** Return the number of errors. +*/ +static int setCurrentTxnTime(sqlite3_context *context, DateTime *p){ + p->iJD = sqlite3TxnCurrentTime(context); + if( p->iJD>0 ){ + p->validJD = 1; + return 0; + }else{ + return 1; + } +} + +/* ** Input "r" is a numeric quantity which might be a julian day number, ** or the number of seconds since 1970. If the value if r is within ** range of a julian day number, install it as such and set validJD. @@ -387,7 +406,9 @@ static int parseDateOrTime( }else if( parseHhMmSs(zDate, p)==0 ){ return 0; }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){ - return setDateTimeToCurrent(context, p); + return setCurrentStmtTime(context, p); + }else if( sqlite3StrICmp(zDate,"txn")==0 && sqlite3NotPureFunc(context) ){ + return setCurrentTxnTime(context, p); }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){ setRawDateNumber(p, r); return 0; @@ -946,7 +967,7 @@ static int isDate( memset(p, 0, sizeof(*p)); if( argc==0 ){ if( !sqlite3NotPureFunc(context) ) return 1; - return setDateTimeToCurrent(context, p); + return setCurrentStmtTime(context, p); } if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT || eType==SQLITE_INTEGER ){ |