aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/date.c17
-rw-r--r--src/os.c12
-rw-r--r--src/os.h2
-rw-r--r--src/os_unix.c41
-rw-r--r--src/test_devsym.c2
-rw-r--r--src/test_journal.c2
-rw-r--r--src/vdbeapi.c14
7 files changed, 48 insertions, 42 deletions
diff --git a/src/date.c b/src/date.c
index 2c39a0a0d..cae0a270d 100644
--- a/src/date.c
+++ b/src/date.c
@@ -314,10 +314,8 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
** Set the time to the current time reported by the VFS
*/
static void setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
- double r;
sqlite3 *db = sqlite3_context_db_handle(context);
- sqlite3OsCurrentTime(db->pVfs, &r);
- p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
+ sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD);
p->validJD = 1;
}
@@ -1038,22 +1036,15 @@ static void currentTimeFunc(
time_t t;
char *zFormat = (char *)sqlite3_user_data(context);
sqlite3 *db;
- double rT;
+ sqlite3_int64 iT;
char zBuf[20];
UNUSED_PARAMETER(argc);
UNUSED_PARAMETER(argv);
db = sqlite3_context_db_handle(context);
- sqlite3OsCurrentTime(db->pVfs, &rT);
-#ifndef SQLITE_OMIT_FLOATING_POINT
- t = 86400.0*(rT - 2440587.5) + 0.5;
-#else
- /* without floating point support, rT will have
- ** already lost fractional day precision.
- */
- t = 86400 * (rT - 2440587) - 43200;
-#endif
+ sqlite3OsCurrentTimeInt64(db->pVfs, &iT);
+ t = (iT - 100*(sqlite3_int64)244058755)/1000;
#ifdef HAVE_GMTIME_R
{
struct tm sNow;
diff --git a/src/os.c b/src/os.c
index f3600cb0e..b3e870034 100644
--- a/src/os.c
+++ b/src/os.c
@@ -161,8 +161,16 @@ int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
return pVfs->xSleep(pVfs, nMicro);
}
-int sqlite3OsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
- return pVfs->xCurrentTime(pVfs, pTimeOut);
+int sqlite3OsCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *pTimeOut){
+ int rc;
+ if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
+ rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
+ }else{
+ double r;
+ rc = pVfs->xCurrentTime(pVfs, &r);
+ *pTimeOut = (sqlite3_int64)(r*86400000.0);
+ }
+ return rc;
}
int sqlite3OsOpenMalloc(
diff --git a/src/os.h b/src/os.h
index 089901e0f..7b2bff0dc 100644
--- a/src/os.h
+++ b/src/os.h
@@ -259,7 +259,7 @@ void sqlite3OsDlClose(sqlite3_vfs *, void *);
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
int sqlite3OsSleep(sqlite3_vfs *, int);
-int sqlite3OsCurrentTime(sqlite3_vfs *, double*);
+int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*);
/*
** Convenience functions for opening and closing files using
diff --git a/src/os_unix.c b/src/os_unix.c
index 986963a18..cb3e19009 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -4516,32 +4516,33 @@ int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
#endif
/*
-** Find the current time (in Universal Coordinated Time). Write the
-** current time and date as a Julian Day number into *prNow and
-** return 0. Return 1 if the time and date cannot be found.
+** Find the current time (in Universal Coordinated Time). Write into *piNow
+** the current time and date as a Julian Day number times 86_400_000. In
+** other words, write into *piNow the number of milliseconds since the Julian
+** epoch of noon in Greenwich on November 24, 4714 B.C according to the
+** proleptic Gregorian calendar.
+**
+** On success, return 0. Return 1 if the time and date cannot be found.
*/
-static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
-#if defined(SQLITE_OMIT_FLOATING_POINT)
- time_t t;
- time(&t);
- *prNow = (((sqlite3_int64)t)/8640 + 24405875)/10;
-#elif defined(NO_GETTOD)
+static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
+ static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000;
+#if defined(NO_GETTOD)
time_t t;
time(&t);
- *prNow = t/86400.0 + 2440587.5;
+ *piNow = ((sqlite3_int64)i)*1000 + unixEpoch;
#elif OS_VXWORKS
struct timespec sNow;
clock_gettime(CLOCK_REALTIME, &sNow);
- *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_nsec/86400000000000.0;
+ *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
#else
struct timeval sNow;
gettimeofday(&sNow, 0);
- *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0;
+ *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
#endif
#ifdef SQLITE_TEST
if( sqlite3_current_time ){
- *prNow = sqlite3_current_time/86400.0 + 2440587.5;
+ *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
}
#endif
UNUSED_PARAMETER(NotUsed);
@@ -4549,6 +4550,18 @@ static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
}
/*
+** Find the current time (in Universal Coordinated Time). Write the
+** current time and date as a Julian Day number into *prNow and
+** return 0. Return 1 if the time and date cannot be found.
+*/
+static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
+ sqlite3_int64 i;
+ unixCurrentTimeInt64(0, &i);
+ *prNow = i*86400000.0;
+ return 0;
+}
+
+/*
** We added the xGetLastError() method with the intention of providing
** better low-level error messages when operating-system problems come up
** during SQLite operation. But so far, none of that has been implemented
@@ -6601,7 +6614,7 @@ int sqlite3_os_init(void){
unixShmLock, /* xShmLock */ \
unixShmClose, /* xShmClose */ \
0, /* xRename */ \
- 0, /* xCurrentTimeInt64 */ \
+ unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
}
/*
diff --git a/src/test_devsym.c b/src/test_devsym.c
index 69d716246..118af8b08 100644
--- a/src/test_devsym.c
+++ b/src/test_devsym.c
@@ -346,7 +346,7 @@ static int devsymSleep(sqlite3_vfs *pVfs, int nMicro){
** Return the current time as a Julian Day number in *pTimeOut.
*/
static int devsymCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
- return sqlite3OsCurrentTime(g.pVfs, pTimeOut);
+ return g.pVfs->xCurrentTime(g.pVfs, pTimeOut);
}
diff --git a/src/test_journal.c b/src/test_journal.c
index 020b41575..c4bc5d094 100644
--- a/src/test_journal.c
+++ b/src/test_journal.c
@@ -801,7 +801,7 @@ static int jtSleep(sqlite3_vfs *pVfs, int nMicro){
** Return the current time as a Julian Day number in *pTimeOut.
*/
static int jtCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
- return sqlite3OsCurrentTime(g.pVfs, pTimeOut);
+ return g.pVfs->xCurrentTime(g.pVfs, pTimeOut);
}
/**************************************************************************
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index f16cc1be0..2a8c1dd18 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -377,9 +377,7 @@ static int sqlite3Step(Vdbe *p){
#ifndef SQLITE_OMIT_TRACE
if( db->xProfile && !db->init.busy ){
- double rNow;
- sqlite3OsCurrentTime(db->pVfs, &rNow);
- p->startTime = (u64)((rNow - (int)rNow)*3600.0*24.0*1000000000.0);
+ sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
}
#endif
@@ -400,13 +398,9 @@ static int sqlite3Step(Vdbe *p){
/* Invoke the profile callback if there is one
*/
if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
- double rNow;
- u64 elapseTime;
-
- sqlite3OsCurrentTime(db->pVfs, &rNow);
- elapseTime = (u64)((rNow - (int)rNow)*3600.0*24.0*1000000000.0);
- elapseTime -= p->startTime;
- db->xProfile(db->pProfileArg, p->zSql, elapseTime);
+ sqlite3_int64 iNow;
+ sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
+ db->xProfile(db->pProfileArg, p->zSql, iNow - p->startTime);
}
#endif