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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/++
Miscellaneous SQLite3 library functions.
Authors:
Nicolas Sicard (biozic) and other contributors at $(LINK https://github.com/biozic/d2sqlite3)
Copyright:
Copyright 2011-18 Nicolas Sicard.
License:
$(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
+/
module d2sqlite3.library;
import d2sqlite3.sqlite3;
import d2sqlite3.database : SqliteException;
import std.exception : enforce;
import std.string : format;
/++
Gets the library's version string (e.g. "3.8.7"), version number (e.g. 3_008_007)
or source ID.
These values are returned by the linked SQLite C library. They can be checked against
the values of the enums defined by the `d2sqlite3` package (`SQLITE_VERSION`,
`SQLITE_VERSION_NUMBER` and `SQLITE_SOURCE_ID`).
See_Also: $(LINK http://www.sqlite.org/c3ref/libversion.html).
+/
string versionString()
{
import std.conv : to;
return sqlite3_libversion().to!string;
}
/// Ditto
int versionNumber() nothrow
{
return sqlite3_libversion_number();
}
/// Ditto
string sourceID()
{
import std.conv : to;
return sqlite3_sourceid().to!string;
}
/++
Tells whether SQLite was compiled with the thread-safe options.
See_also: $(LINK http://www.sqlite.org/c3ref/threadsafe.html).
+/
bool threadSafe() nothrow
{
return cast(bool) sqlite3_threadsafe();
}
/++
Manually initializes (or shuts down) SQLite.
SQLite initializes itself automatically on the first request execution, so this
usually wouldn't be called. Use for instance before a call to config().
+/
void initialize()
{
immutable result = sqlite3_initialize();
enforce(result == SQLITE_OK, new SqliteException("Initialization: error %s".format(result), result));
}
/// Ditto
void shutdown()
{
immutable result = sqlite3_shutdown();
enforce(result == SQLITE_OK, new SqliteException("Shutdown: error %s".format(result), result));
}
/++
Sets a configuration option.
Use before initialization, e.g. before the first
call to initialize and before execution of the first statement.
See_Also: $(LINK http://www.sqlite.org/c3ref/config.html).
+/
void config(Args...)(int code, Args args)
{
immutable result = sqlite3_config(code, args);
enforce(result == SQLITE_OK, new SqliteException("Configuration: error %s".format(result), result));
}
/++
Tests if an SQLite compile option is set
See_Also: $(LINK http://sqlite.org/c3ref/compileoption_get.html).
+/
bool isCompiledWith(string option)
{
import std.string : toStringz;
return cast(bool) sqlite3_compileoption_used(option.toStringz);
}
///
version (SqliteEnableUnlockNotify)
unittest
{
assert(isCompiledWith("SQLITE_ENABLE_UNLOCK_NOTIFY"));
assert(!isCompiledWith("SQLITE_UNKNOWN_COMPILE_OPTION"));
}
|