1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

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
This commit is contained in:
drh
2023-02-07 21:55:14 +00:00
parent c3ea539dc2
commit d4af882a1b
6 changed files with 65 additions and 15 deletions

View File

@@ -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;
@@ -345,6 +347,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
@@ -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 ){