diff options
author | drh <> | 2023-02-07 21:55:14 +0000 |
---|---|---|
committer | drh <> | 2023-02-07 21:55:14 +0000 |
commit | d4af882a1bebbefa02cb40ba85b78c82d1deebd9 (patch) | |
tree | 601fa788e8c334f3153b5f7fd7fc227eb08f7517 /src/date.c | |
parent | c3ea539dc21f193c277851ab44109aef8de8a15d (diff) | |
download | sqlite-d4af882a1bebbefa02cb40ba85b78c82d1deebd9.tar.gz sqlite-d4af882a1bebbefa02cb40ba85b78c82d1deebd9.zip |
Add support for the 'txn' argument to date/time functions that works like
'now' but keeps the same time for the entire transaction.
FossilOrigin-Name: 5e4f45af96247e29910403a63ac148cb313b005f9c014b37a9a49d98f5fef9a6
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 ){ |