1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Back out the 'txn' enhancement to date/time functions. The duration of a

"transaction" is confused and needs to be straightened out prior to moving
forward with this change.

FossilOrigin-Name: 4a145f07322d768a07619bed27e0390d50f3a01d07787b9296234a5ceb6f1218
This commit is contained in:
drh
2023-02-08 20:29:48 +00:00
parent 03b30b7abe
commit 601e4d4a0f
7 changed files with 40 additions and 124 deletions

View File

@@ -331,16 +331,12 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
}
/*
** 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().
**
** Or if bTxn is true, use the transaction time.
** Set the time to the current time reported by the VFS.
**
** Return the number of errors.
*/
static int setCurrentStmtTime(sqlite3_context *context, DateTime *p, int bTxn){
p->iJD = sqlite3StmtCurrentTime(context, bTxn);
static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
p->iJD = sqlite3StmtCurrentTime(context);
if( p->iJD>0 ){
p->validJD = 1;
return 0;
@@ -391,9 +387,7 @@ static int parseDateOrTime(
}else if( parseHhMmSs(zDate, p)==0 ){
return 0;
}else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){
return setCurrentStmtTime(context, p, 0);
}else if( sqlite3StrICmp(zDate,"txn")==0 && sqlite3NotPureFunc(context) ){
return setCurrentStmtTime(context, p, 1);
return setDateTimeToCurrent(context, p);
}else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){
setRawDateNumber(p, r);
return 0;
@@ -937,11 +931,8 @@ static int parseModifier(
** the resulting time into the DateTime structure p. Return 0
** on success and 1 if there are any errors.
**
** If there are zero parameters (if argc<=0) then assume a default
** value of "now" for argv[0] if argc==0 and "txn" if argc<0. SQL
** functions will always have argc>=0, but the special implementations
** of CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP set argc to -1
** in order to force the use of 'txn' semantics.
** If there are zero parameters (if even argv[0] is undefined)
** then assume a default value of "now" for argv[0].
*/
static int isDate(
sqlite3_context *context,
@@ -953,9 +944,9 @@ static int isDate(
const unsigned char *z;
int eType;
memset(p, 0, sizeof(*p));
if( argc<=0 ){
if( argc==0 ){
if( !sqlite3NotPureFunc(context) ) return 1;
return setCurrentStmtTime(context, p, argc<0);
return setDateTimeToCurrent(context, p);
}
if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
|| eType==SQLITE_INTEGER ){
@@ -1262,7 +1253,7 @@ static void ctimeFunc(
sqlite3_value **NotUsed2
){
UNUSED_PARAMETER2(NotUsed, NotUsed2);
timeFunc(context, -1, 0);
timeFunc(context, 0, 0);
}
/*
@@ -1276,7 +1267,7 @@ static void cdateFunc(
sqlite3_value **NotUsed2
){
UNUSED_PARAMETER2(NotUsed, NotUsed2);
dateFunc(context, -1, 0);
dateFunc(context, 0, 0);
}
/*
@@ -1290,7 +1281,7 @@ static void ctimestampFunc(
sqlite3_value **NotUsed2
){
UNUSED_PARAMETER2(NotUsed, NotUsed2);
datetimeFunc(context, -1, 0);
datetimeFunc(context, 0, 0);
}
#endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */
@@ -1321,7 +1312,7 @@ static void currentTimeFunc(
UNUSED_PARAMETER(argc);
UNUSED_PARAMETER(argv);
iT = sqlite3StmtCurrentTime(context, 1);
iT = sqlite3StmtCurrentTime(context);
if( iT<=0 ) return;
t = iT/1000 - 10000*(sqlite3_int64)21086676;
#if HAVE_GMTIME_R