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

@ -1,5 +1,5 @@
C Always\suse\s64-bit\sintegers\sfor\sstats\sassociated\swith\sSTAT1\sand\sSTAT4.
D 2023-02-08T17:28:42.250
C Back\sout\sthe\s'txn'\senhancement\sto\sdate/time\sfunctions.\s\sThe\sduration\sof\sa\n"transaction"\sis\sconfused\sand\sneeds\sto\sbe\sstraightened\sout\sprior\sto\smoving\nforward\swith\sthis\schange.
D 2023-02-08T20:29:48.017
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -567,7 +567,7 @@ F src/build.c c55ab6d1b089ceef57160e840f05f692955ac90944c3d04fcf01d97fd7bfd08d
F src/callback.c 4cd7225b26a97f7de5fee5ae10464bed5a78f2adefe19534cc2095b3a8ca484a
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
F src/ctime.c 20507cc0b0a6c19cd882fcd0eaeda32ae6a4229fb4b024cfdf3183043d9b703d
F src/date.c 37ca5e3cb34d666fae892156c9317d8bf756ae8a281504040dd3a02813ce5e9e
F src/date.c 94ce83b4cd848a387680a5f920c9018c16655db778c4d36525af0a0f34679ac5
F src/dbpage.c d47549716549311f79dc39fe5c8fb19390a6eb2c960f8e37c89a9c4de0c1052e
F src/dbstat.c ec92074baa61d883de58c945162d9e666c13cd7cf3a23bc38b4d1c4d0b2c2bef
F src/delete.c 86573edae75e3d3e9a8b590d87db8e47222103029df4f3e11fa56044459b514e
@ -626,7 +626,7 @@ F src/shell.c.in 839d2b9f04f2b24e7032edb9ef756c34fbd60be91e24bc1ac8f1dae3a13c774
F src/sqlite.h.in c060f9e6f646fd817abf273c068666e079fc6e8467ea1d3e8b20f355f82722e9
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h da473ce2b3d0ae407a6300c4a164589b9a6bfdbec9462688a8593ff16f3bb6e4
F src/sqliteInt.h 79cc3484763e2a4d4b2a7ea17d50c376671cc438b2610f2c1cd1a503d4e714de
F src/sqliteInt.h 4dcc36b21dd0c77efeb0bb38b0d31916bc63fb429c8a89d186c945eba0816447
F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657
F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
@ -694,8 +694,8 @@ F src/vacuum.c 84ce7f01f8a7a08748e107a441db83bcec13970190ddcb0c9ff522adbc1c23fd
F src/vdbe.c 47d3b78e75e239e1909933f0d77612b4111ebe760f01fdd0085e4e30b59b4cc6
F src/vdbe.h 73b904a6b3bb27f308c6cc287a5751ebc7f1f89456be0ed068a12b92844c6e8c
F src/vdbeInt.h a4147a4ddf613cb1bcb555ace9e9e74a9c099d65facd88155f191b1fb4d74cfb
F src/vdbeapi.c be64df0e21a43056b62f46777749347b7d51f6e5e6c419c4bf42ce9bf98d6064
F src/vdbeaux.c 9f2a2ec80ff90266ab603065c32dd3c8b0a53023ab7210a03fccf324ad6ddbce
F src/vdbeapi.c 40c47b1528d308a322203de21d2e0d711753257ed9771771b6129214b1d65932
F src/vdbeaux.c 3f9e3b6585e7434aa11300169dd66ddf0fc963a0c6f7940bdc058335dadeb353
F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd
F src/vdbemem.c 86908c0ab1624df678458feb53319bf9720992e761cbccf77a36d671ce11693d
F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35
@ -910,7 +910,7 @@ F test/ctime.test 340f362f41f92972bbd71f44e10569a5cc694062b692231bd08aa6fe6c1c47
F test/cursorhint.test 0175e4404181ace3ceca8b114eb0a98eae600d565aa4e2705abbe6614c7fe201
F test/cursorhint2.test 6f3aa9cb19e7418967a10ec6905209bcbb5968054da855fc36c8beee9ae9c42f
F test/dataversion1.test 6e5e86ac681f0782e766ebcb56c019ae001522d114e0e111e5ebf68ccf2a7bb8
F test/date.test 8e9ae588d832c54fa2512b0f9789bea48442ada0736dabee54b377dc1b8d4a87
F test/date.test 118e04db8c8b4efeb885542b4918c7b869a34c460a6bebbfe927dfd75706b80d
F test/date2.test 7e12ec14aaf4d5e6294b4ba140445b0eca06ea50062a9c3a69c4ee13d0b6f8b1
F test/date3.test a1b77abf05c6772fe5ca2337cac1398892f2a41e62bce7e6be0f4a08a0e64ae5
F test/dbdata.test 042f49acff3438f940eeba5868d3af080ae64ddf26ae78f80c92bec3ca7d8603
@ -2045,8 +2045,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 459d986d38fc0ccbfd66801e0f22900cfed831268cf59ac8d1cd1e556f0d1441
R 7d765c5331bdc4fd6218383f0460f3b4
P 6647d1cb8b53102c8114b1f3e34173d907504d78aa3140eab53f88027a36660b
Q -61cc8ed8d3541eddf23a9d542179c3f0223c5b8519b54d3be79988a376e25a89
R a860bd4c312a3654d874052ef844c582
U drh
Z d38d730b036fdc5d765ac843fc1e375f
Z aa31102f6fd0899de50076b8543233cf
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
6647d1cb8b53102c8114b1f3e34173d907504d78aa3140eab53f88027a36660b
4a145f07322d768a07619bed27e0390d50f3a01d07787b9296234a5ceb6f1218

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

View File

@ -1615,7 +1615,6 @@ struct sqlite3 {
u8 nSqlExec; /* Number of pending OP_SqlExec opcodes */
u8 eOpenState; /* Current condition of the connection */
int nextPagesize; /* Pagesize after VACUUM if >0 */
i64 txnTime; /* Timestamp for current transaction */
i64 nChange; /* Value returned by sqlite3_changes() */
i64 nTotalChange; /* Value returned by sqlite3_total_changes() */
int aLimit[SQLITE_N_LIMIT]; /* Limits */
@ -5335,7 +5334,7 @@ FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
&& !defined(SQLITE_OMIT_VIRTUALTABLE)
void sqlite3VtabUsesAllSchemas(sqlite3_index_info*);
#endif
sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*, int);
sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
void sqlite3ParseObjectInit(Parse*,sqlite3*);

View File

@ -970,27 +970,18 @@ int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut){
** statement, the exact same time is returned for each invocation regardless
** of the amount of time that elapses between invocations. In other words,
** the time returned is always the time of the first call.
**
** Or, if bTxn, return the transaction time. The transaction time is the
** same for all calls within the same transaction.
**
** bTxn is 0 for SQL like datetime('now') and is 1 for datetime('txn').
*/
sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p, int bTxn){
sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){
int rc;
#ifndef SQLITE_ENABLE_STAT4
sqlite3_int64 *piTime;
sqlite3 *db = p->pOut->db;
sqlite3_int64 *piTime = &p->pVdbe->iCurrentTime;
assert( p->pVdbe!=0 );
piTime = bTxn ? &db->txnTime : &p->pVdbe->iCurrentTime;
#else
sqlite3_int64 iTime = 0;
sqlite3_int64 *piTime;
sqlite3 *db = p->pOut->db;
piTime = bTxn ? &db->txnTime : p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime;
sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime;
#endif
if( *piTime==0 ){
rc = sqlite3OsCurrentTimeInt64(db->pVfs, piTime);
rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, piTime);
if( rc ) *piTime = 0;
}
return *piTime;

View File

@ -3394,7 +3394,6 @@ int sqlite3VdbeHalt(Vdbe *p){
*/
if( db->autoCommit ){
sqlite3ConnectionUnlocked(db);
db->txnTime = 0;
}
assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );

View File

@ -309,9 +309,9 @@ sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0
#
datetest 7.1 {datetime(null)} NULL
datetest 7.2 {datetime('now',null)} NULL
datetest 7.3 {datetime('txn','localtime',null)} NULL
datetest 7.3 {datetime('now','localtime',null)} NULL
datetest 7.4 {time(null)} NULL
datetest 7.5 {time('txn',null)} NULL
datetest 7.5 {time('now',null)} NULL
datetest 7.6 {time('now','localtime',null)} NULL
datetest 7.7 {date(null)} NULL
datetest 7.8 {date('now',null)} NULL
@ -322,28 +322,28 @@ datetest 7.12 {julianday('now','localtime',null)} NULL
datetest 7.13 {strftime(null,'now')} NULL
datetest 7.14 {strftime('%s',null)} NULL
datetest 7.15 {strftime('%s','now',null)} NULL
datetest 7.16 {strftime('%s','txn','localtime',null)} NULL
datetest 7.16 {strftime('%s','now','localtime',null)} NULL
# Test modifiers when the date begins as a julian day number - to
# make sure the HH:MM:SS is preserved. Ticket #551.
#
set sqlite_current_time [db eval {SELECT strftime('%s','2003-10-22 12:34:00')}]
datetest 8.1 {datetime('now','weekday 0')} {2003-10-26 12:34:00}
datetest 8.2 {datetime('txn','weekday 1')} {2003-10-27 12:34:00}
datetest 8.2 {datetime('now','weekday 1')} {2003-10-27 12:34:00}
datetest 8.3 {datetime('now','weekday 2')} {2003-10-28 12:34:00}
datetest 8.4 {datetime('txn','weekday 3')} {2003-10-22 12:34:00}
datetest 8.4 {datetime('now','weekday 3')} {2003-10-22 12:34:00}
datetest 8.5 {datetime('now','start of month')} {2003-10-01 00:00:00}
datetest 8.6 {datetime('txn','start of year')} {2003-01-01 00:00:00}
datetest 8.6 {datetime('now','start of year')} {2003-01-01 00:00:00}
datetest 8.7 {datetime('now','start of day')} {2003-10-22 00:00:00}
datetest 8.8 {datetime('txn','1 day')} {2003-10-23 12:34:00}
datetest 8.8 {datetime('now','1 day')} {2003-10-23 12:34:00}
datetest 8.9 {datetime('now','+1 day')} {2003-10-23 12:34:00}
datetest 8.10 {datetime('txn','+1.25 day')} {2003-10-23 18:34:00}
datetest 8.10 {datetime('now','+1.25 day')} {2003-10-23 18:34:00}
datetest 8.11 {datetime('now','-1.0 day')} {2003-10-21 12:34:00}
datetest 8.12 {datetime('txn','1 month')} {2003-11-22 12:34:00}
datetest 8.12 {datetime('now','1 month')} {2003-11-22 12:34:00}
datetest 8.13 {datetime('now','11 month')} {2004-09-22 12:34:00}
datetest 8.14 {datetime('txn','-13 month')} {2002-09-22 12:34:00}
datetest 8.14 {datetime('now','-13 month')} {2002-09-22 12:34:00}
datetest 8.15 {datetime('now','1.5 months')} {2003-12-07 12:34:00}
datetest 8.16 {datetime('txn','-5 years')} {1998-10-22 12:34:00}
datetest 8.16 {datetime('now','-5 years')} {1998-10-22 12:34:00}
datetest 8.17 {datetime('now','+10.5 minutes')} {2003-10-22 12:44:30}
datetest 8.18 {datetime('now','-1.25 hours')} {2003-10-22 11:19:00}
datetest 8.19 {datetime('now','11.25 seconds')} {2003-10-22 12:34:11}
@ -486,76 +486,11 @@ do_test date-15.1 {
}
} {0.0}
do_test date-15.2 {
db func sleeper sleeper
db eval {
SELECT c - a FROM (SELECT julianday('txn') AS a,
sleeper(), julianday('txn') AS c);
}
} {0.0}
do_test date-15.3 {
db eval {
SELECT a==b FROM (SELECT current_timestamp AS a,
sleeper(), current_timestamp AS b);
}
} {1}
do_test date-15.4 {
db eval {
SELECT a==b FROM (SELECT julianday('txn') AS a,
sleeper(), julianday('now') AS b);
}
} {0}
do_execsql_test date-15.5 {
CREATE TEMP TABLE t15(a,b);
BEGIN;
INSERT INTO t15(a,b) VALUES(julianday('txn'),sleeper());
INSERT INTO t15(a,b) VALUES(julianday('txn'),sleeper());
INSERT INTO t15(a,b) VALUES(julianday('txn'),sleeper());
COMMIT;
SELECT count(a), count(DISTINCT a) FROM t15;
} {3 1}
do_execsql_test date-15.6 {
DELETE FROM t15;
BEGIN;
INSERT INTO t15(a,b) VALUES(julianday('now'),sleeper());
INSERT INTO t15(a,b) VALUES(julianday('now'),sleeper());
INSERT INTO t15(a,b) VALUES(julianday('now'),sleeper());
COMMIT;
SELECT count(a), count(DISTINCT a) FROM t15;
} {3 3}
do_execsql_test date-15.7 {
DELETE FROM t15;
INSERT INTO t15(a,b) VALUES(julianday('txn'),sleeper());
INSERT INTO t15(a,b) VALUES(julianday('txn'),sleeper());
BEGIN;
INSERT INTO t15(a,b) VALUES(julianday('txn'),sleeper());
INSERT INTO t15(a,b) VALUES(julianday('txn'),sleeper());
COMMIT;
SELECT count(a), count(DISTINCT a) FROM t15;
} {4 3}
do_test date-15.10 {
unset -nocomplain x
db eval {BEGIN;}
db eval {
SELECT
current_time AS ct1,
current_date AS cd1,
current_timestamp AS cs1,
time() AS ct2,
datetime() AS cs2;
} x {continue}
after 1000
db eval {
SELECT
current_time=$x(ct1),
current_date=$x(cd1),
current_timestamp=$x(cs1),
time()=$x(ct2),
datetime()=$x(cs2);
}
} {1 1 1 0 0}
db eval {COMMIT}
# Tests of extreme values in date/time functions. Run with UBSan or the
# equivalent to verify no signed interger overflow warnings.