Repository navigation
Expand file tree
/
Copy pathsqlite3_nocurrenttime.go
More file actions
69 lines (59 loc) · 1.85 KB
/
Copy pathsqlite3_nocurrenttime.go
File metadata and controls
69 lines (59 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//go:build cgo
package sqlite3
/*
#ifndef USE_LIBSQLITE3
#include "sqlite3-binding.h"
#else
#include <sqlite3.h>
#endif
static sqlite3_vfs noCurrentTimeVfs;
static int noCurrentTime(sqlite3_vfs *vfs, double *now) {
*now = 0;
return SQLITE_ERROR;
}
static int noCurrentTimeInt64(sqlite3_vfs *vfs, sqlite3_int64 *now) {
*now = 0;
return SQLITE_ERROR;
}
// Register a copy of the default VFS named "nocurrenttime" whose current time
// is unavailable. The copy shares the methods and pAppData of the default VFS,
// which suits the unix and win32 VFSes, but not a default VFS that checks its
// own name or extends sqlite3_vfs.
static int _sqlite3_register_no_current_time_vfs(void) {
sqlite3_vfs *base = sqlite3_vfs_find(0);
if (base == 0) {
return SQLITE_ERROR;
}
noCurrentTimeVfs = *base;
noCurrentTimeVfs.zName = "nocurrenttime";
noCurrentTimeVfs.pNext = 0;
noCurrentTimeVfs.xCurrentTime = noCurrentTime;
if (noCurrentTimeVfs.iVersion >= 2) {
noCurrentTimeVfs.xCurrentTimeInt64 = noCurrentTimeInt64;
}
return sqlite3_vfs_register(&noCurrentTimeVfs, 0);
}
*/
import "C"
import (
"fmt"
"sync"
)
// noCurrentTimeVFS is the VFS that the DSN parameter vfs=nocurrenttime selects.
// Date and time functions get no current time from it, so 'now', date and time
// functions without a time value and the CURRENT_* keywords give NULL, and
// their results do not depend on when a query runs. Without a current time,
// SQLite also skips the profile callbacks of statements.
const noCurrentTimeVFS = "nocurrenttime"
var (
noCurrentTimeOnce sync.Once
noCurrentTimeErr error
)
func registerNoCurrentTimeVFS() error {
noCurrentTimeOnce.Do(func() {
if rv := C._sqlite3_register_no_current_time_vfs(); rv != C.SQLITE_OK {
noCurrentTimeErr = fmt.Errorf("sqlite3: registering the %s VFS failed: %d", noCurrentTimeVFS, rv)
}
})
return noCurrentTimeErr
}