mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
The date/time functions return NULL if the xCurrentTime or
xCurrentTimeInt64 VFS methods fail. Ticket [0b803bff856c644c] FossilOrigin-Name: c96651dd6ceadd51c9e1f4d942177d3c128c47b4
This commit is contained in:
16
manifest
16
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Suppress\sa\scompiler\swarning\sthat\soccurs\swith\sSQLITE_OMIT_VIRTUALTABLE.
|
C The\sdate/time\sfunctions\sreturn\sNULL\sif\sthe\sxCurrentTime\sor\nxCurrentTimeInt64\sVFS\smethods\sfail.\nTicket\s[0b803bff856c644c]
|
||||||
D 2011-10-12T19:04:07.402
|
D 2011-10-12T23:13:43.648
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in a162fe39e249b8ed4a65ee947c30152786cfe897
|
F Makefile.in a162fe39e249b8ed4a65ee947c30152786cfe897
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -131,7 +131,7 @@ F src/build.c 119937b0ae1ff4dcec8fdea53771acc95bafca51
|
|||||||
F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a
|
F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a
|
||||||
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
|
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
|
||||||
F src/ctime.c 829f3261d3db48e3d87891bc887208734734c2e4
|
F src/ctime.c 829f3261d3db48e3d87891bc887208734734c2e4
|
||||||
F src/date.c a3c6842bad7ae632281811de112a8ba63ff08ab3
|
F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4
|
||||||
F src/delete.c ff68e5ef23aee08c0ff528f699a19397ed8bbed8
|
F src/delete.c ff68e5ef23aee08c0ff528f699a19397ed8bbed8
|
||||||
F src/expr.c f4dcaeb8252c4b16fcdc245660f70ed366bc6cdd
|
F src/expr.c f4dcaeb8252c4b16fcdc245660f70ed366bc6cdd
|
||||||
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
|
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
|
||||||
@@ -165,8 +165,8 @@ F src/os.c 3b3f69c34be7f998f5ea6bd46a2fe8a2b7fa8f70
|
|||||||
F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
|
F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
|
||||||
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
|
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
|
||||||
F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440
|
F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440
|
||||||
F src/os_unix.c b14e8b40e28d983a908249442e1e0273a1ecb64e
|
F src/os_unix.c 7f8031b5b3aee1b9e066e2ea8f83e02775debcb4
|
||||||
F src/os_win.c fbe47c7fdc9a846a772bbf98719c328becad5f8a
|
F src/os_win.c 58c1cef8a167275d5238bdfb3c455e53e3146354
|
||||||
F src/pager.c 8a6ac3e0d9694412076e2273e3c81e9c4e08758f
|
F src/pager.c 8a6ac3e0d9694412076e2273e3c81e9c4e08758f
|
||||||
F src/pager.h dbcaa791e8b6c3a6b77c168c5c27deec289fb176
|
F src/pager.h dbcaa791e8b6c3a6b77c168c5c27deec289fb176
|
||||||
F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
|
F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
|
||||||
@@ -966,7 +966,7 @@ F tool/symbols.sh caaf6ccc7300fd43353318b44524853e222557d5
|
|||||||
F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
|
F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
|
||||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||||
P 97ef4f5013731fa3a0f72451b7e8c9aec5523104
|
P 6bedb49d68f2960a6fc4701d02e177789abf9099
|
||||||
R aa347fcaa7b1b78f72c141e6103db8e0
|
R f6f2282ee33c9438c6a443681fa52486
|
||||||
U drh
|
U drh
|
||||||
Z 4df9a6a5c072d98e4f59e9f8ded1b3be
|
Z e1a02e86d35f387f95f1d1ceb1084f34
|
||||||
|
@@ -1 +1 @@
|
|||||||
6bedb49d68f2960a6fc4701d02e177789abf9099
|
c96651dd6ceadd51c9e1f4d942177d3c128c47b4
|
39
src/date.c
39
src/date.c
@@ -289,12 +289,18 @@ 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 by the VFS.
|
||||||
|
**
|
||||||
|
** Return the number of errors.
|
||||||
*/
|
*/
|
||||||
static void setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
|
static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
|
||||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||||
sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD);
|
if( sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD)==SQLITE_OK ){
|
||||||
p->validJD = 1;
|
p->validJD = 1;
|
||||||
|
return 0;
|
||||||
|
}else{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -324,8 +330,7 @@ static int parseDateOrTime(
|
|||||||
}else if( parseHhMmSs(zDate, p)==0 ){
|
}else if( parseHhMmSs(zDate, p)==0 ){
|
||||||
return 0;
|
return 0;
|
||||||
}else if( sqlite3StrICmp(zDate,"now")==0){
|
}else if( sqlite3StrICmp(zDate,"now")==0){
|
||||||
setDateTimeToCurrent(context, p);
|
return setDateTimeToCurrent(context, p);
|
||||||
return 0;
|
|
||||||
}else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
|
}else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
|
||||||
p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
|
p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
|
||||||
p->validJD = 1;
|
p->validJD = 1;
|
||||||
@@ -752,8 +757,9 @@ static int isDate(
|
|||||||
int eType;
|
int eType;
|
||||||
memset(p, 0, sizeof(*p));
|
memset(p, 0, sizeof(*p));
|
||||||
if( argc==0 ){
|
if( argc==0 ){
|
||||||
setDateTimeToCurrent(context, p);
|
return setDateTimeToCurrent(context, p);
|
||||||
}else if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
|
}
|
||||||
|
if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
|
||||||
|| eType==SQLITE_INTEGER ){
|
|| eType==SQLITE_INTEGER ){
|
||||||
p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
|
p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
|
||||||
p->validJD = 1;
|
p->validJD = 1;
|
||||||
@@ -1065,31 +1071,28 @@ static void currentTimeFunc(
|
|||||||
char *zFormat = (char *)sqlite3_user_data(context);
|
char *zFormat = (char *)sqlite3_user_data(context);
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_int64 iT;
|
sqlite3_int64 iT;
|
||||||
|
struct tm *pTm;
|
||||||
|
struct tm sNow;
|
||||||
char zBuf[20];
|
char zBuf[20];
|
||||||
|
|
||||||
UNUSED_PARAMETER(argc);
|
UNUSED_PARAMETER(argc);
|
||||||
UNUSED_PARAMETER(argv);
|
UNUSED_PARAMETER(argv);
|
||||||
|
|
||||||
db = sqlite3_context_db_handle(context);
|
db = sqlite3_context_db_handle(context);
|
||||||
sqlite3OsCurrentTimeInt64(db->pVfs, &iT);
|
if( sqlite3OsCurrentTimeInt64(db->pVfs, &iT) ) return;
|
||||||
t = iT/1000 - 10000*(sqlite3_int64)21086676;
|
t = iT/1000 - 10000*(sqlite3_int64)21086676;
|
||||||
#ifdef HAVE_GMTIME_R
|
#ifdef HAVE_GMTIME_R
|
||||||
{
|
pTm = gmtime_r(&t, &sNow);
|
||||||
struct tm sNow;
|
|
||||||
gmtime_r(&t, &sNow);
|
|
||||||
strftime(zBuf, 20, zFormat, &sNow);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
{
|
|
||||||
struct tm *pTm;
|
|
||||||
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
|
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
|
||||||
pTm = gmtime(&t);
|
pTm = gmtime(&t);
|
||||||
strftime(zBuf, 20, zFormat, pTm);
|
if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
|
||||||
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
|
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
if( pTm ){
|
||||||
|
strftime(zBuf, 20, zFormat, &sNow);
|
||||||
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -5428,10 +5428,12 @@ int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
|
|||||||
** epoch of noon in Greenwich on November 24, 4714 B.C according to the
|
** epoch of noon in Greenwich on November 24, 4714 B.C according to the
|
||||||
** proleptic Gregorian calendar.
|
** proleptic Gregorian calendar.
|
||||||
**
|
**
|
||||||
** On success, return 0. Return 1 if the time and date cannot be found.
|
** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date
|
||||||
|
** cannot be found.
|
||||||
*/
|
*/
|
||||||
static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
|
static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
|
||||||
static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000;
|
static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000;
|
||||||
|
int rc = SQLITE_OK;
|
||||||
#if defined(NO_GETTOD)
|
#if defined(NO_GETTOD)
|
||||||
time_t t;
|
time_t t;
|
||||||
time(&t);
|
time(&t);
|
||||||
@@ -5442,8 +5444,11 @@ static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
|
|||||||
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
|
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
|
||||||
#else
|
#else
|
||||||
struct timeval sNow;
|
struct timeval sNow;
|
||||||
gettimeofday(&sNow, 0);
|
if( gettimeofday(&sNow, 0)==0 ){
|
||||||
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
|
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
|
||||||
|
}else{
|
||||||
|
rc = SQLITE_ERROR;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SQLITE_TEST
|
#ifdef SQLITE_TEST
|
||||||
@@ -5452,7 +5457,7 @@ static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
UNUSED_PARAMETER(NotUsed);
|
UNUSED_PARAMETER(NotUsed);
|
||||||
return 0;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -5462,10 +5467,11 @@ static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
|
|||||||
*/
|
*/
|
||||||
static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
|
static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
|
||||||
sqlite3_int64 i;
|
sqlite3_int64 i;
|
||||||
|
int rc;
|
||||||
UNUSED_PARAMETER(NotUsed);
|
UNUSED_PARAMETER(NotUsed);
|
||||||
unixCurrentTimeInt64(0, &i);
|
rc = unixCurrentTimeInt64(0, &i);
|
||||||
*prNow = i/86400000.0;
|
*prNow = i/86400000.0;
|
||||||
return 0;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -3066,7 +3066,8 @@ int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
|
|||||||
** epoch of noon in Greenwich on November 24, 4714 B.C according to the
|
** epoch of noon in Greenwich on November 24, 4714 B.C according to the
|
||||||
** proleptic Gregorian calendar.
|
** proleptic Gregorian calendar.
|
||||||
**
|
**
|
||||||
** On success, return 0. Return 1 if the time and date cannot be found.
|
** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date
|
||||||
|
** cannot be found.
|
||||||
*/
|
*/
|
||||||
static int winCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *piNow){
|
static int winCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *piNow){
|
||||||
/* FILETIME structure is a 64-bit value representing the number of
|
/* FILETIME structure is a 64-bit value representing the number of
|
||||||
@@ -3086,7 +3087,7 @@ static int winCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *piNow){
|
|||||||
GetSystemTime(&time);
|
GetSystemTime(&time);
|
||||||
/* if SystemTimeToFileTime() fails, it returns zero. */
|
/* if SystemTimeToFileTime() fails, it returns zero. */
|
||||||
if (!SystemTimeToFileTime(&time,&ft)){
|
if (!SystemTimeToFileTime(&time,&ft)){
|
||||||
return 1;
|
return SQLITE_ERROR;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
GetSystemTimeAsFileTime( &ft );
|
GetSystemTimeAsFileTime( &ft );
|
||||||
@@ -3102,7 +3103,7 @@ static int winCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *piNow){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
UNUSED_PARAMETER(pVfs);
|
UNUSED_PARAMETER(pVfs);
|
||||||
return 0;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user