sqlite3 1.6.3 → 2.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +615 -1
- data/CONTRIBUTING.md +103 -6
- data/{faq/faq.md → FAQ.md} +66 -79
- data/INSTALLATION.md +267 -0
- data/LICENSE +18 -22
- data/README.md +87 -124
- data/dependencies.yml +10 -11
- data/ext/sqlite3/aggregator.c +178 -178
- data/ext/sqlite3/aggregator.h +7 -4
- data/ext/sqlite3/backup.c +92 -65
- data/ext/sqlite3/backup.h +2 -2
- data/ext/sqlite3/database.c +964 -477
- data/ext/sqlite3/database.h +26 -4
- data/ext/sqlite3/exception.c +213 -94
- data/ext/sqlite3/exception.h +26 -1
- data/ext/sqlite3/extconf.rb +59 -29
- data/ext/sqlite3/sqlite3.c +190 -115
- data/ext/sqlite3/sqlite3_ruby.h +5 -2
- data/ext/sqlite3/statement.c +672 -297
- data/ext/sqlite3/statement.h +4 -3
- data/ext/sqlite3/timespec.h +29 -0
- data/lib/sqlite3/constants.rb +195 -47
- data/lib/sqlite3/database.rb +272 -225
- data/lib/sqlite3/errors.rb +54 -1
- data/lib/sqlite3/fork_safety.rb +66 -0
- data/lib/sqlite3/pragmas.rb +194 -141
- data/lib/sqlite3/resultset.rb +30 -111
- data/lib/sqlite3/statement.rb +105 -25
- data/lib/sqlite3/value.rb +17 -20
- data/lib/sqlite3/version.rb +2 -21
- data/lib/sqlite3/version_info.rb +17 -0
- data/lib/sqlite3.rb +8 -4
- data/ports/archives/sqlite-autoconf-3540100.tar.gz +0 -0
- metadata +16 -48
- data/API_CHANGES.md +0 -49
- data/ChangeLog.cvs +0 -88
- data/Gemfile +0 -11
- data/LICENSE-DEPENDENCIES +0 -20
- data/faq/faq.rb +0 -145
- data/faq/faq.yml +0 -426
- data/lib/sqlite3/translator.rb +0 -118
- data/ports/archives/sqlite-autoconf-3420000.tar.gz +0 -0
- data/test/helper.rb +0 -27
- data/test/test_backup.rb +0 -33
- data/test/test_collation.rb +0 -82
- data/test/test_database.rb +0 -569
- data/test/test_database_flags.rb +0 -95
- data/test/test_database_readonly.rb +0 -36
- data/test/test_database_readwrite.rb +0 -41
- data/test/test_deprecated.rb +0 -49
- data/test/test_encoding.rb +0 -165
- data/test/test_integration.rb +0 -507
- data/test/test_integration_aggregate.rb +0 -336
- data/test/test_integration_open_close.rb +0 -30
- data/test/test_integration_pending.rb +0 -115
- data/test/test_integration_resultset.rb +0 -142
- data/test/test_integration_statement.rb +0 -194
- data/test/test_pragmas.rb +0 -22
- data/test/test_result_set.rb +0 -47
- data/test/test_sqlite3.rb +0 -30
- data/test/test_statement.rb +0 -288
- data/test/test_statement_execute.rb +0 -39
data/ext/sqlite3/sqlite3.c
CHANGED
|
@@ -3,162 +3,237 @@
|
|
|
3
3
|
VALUE mSqlite3;
|
|
4
4
|
VALUE cSqlite3Blob;
|
|
5
5
|
|
|
6
|
-
int
|
|
6
|
+
int
|
|
7
|
+
bignum_to_int64(VALUE value, sqlite3_int64 *result)
|
|
7
8
|
{
|
|
8
9
|
#ifdef HAVE_RB_INTEGER_PACK
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
const int nails = 0;
|
|
11
|
+
int t = rb_integer_pack(value, result, 1, sizeof(*result), nails,
|
|
12
|
+
INTEGER_PACK_NATIVE_BYTE_ORDER |
|
|
13
|
+
INTEGER_PACK_2COMP);
|
|
14
|
+
switch (t) {
|
|
15
|
+
case -2:
|
|
16
|
+
case +2:
|
|
17
|
+
return 0;
|
|
18
|
+
case +1:
|
|
19
|
+
if (!nails) {
|
|
20
|
+
if (*result < 0) { return 0; }
|
|
21
|
+
}
|
|
22
|
+
break;
|
|
23
|
+
case -1:
|
|
24
|
+
if (!nails) {
|
|
25
|
+
if (*result >= 0) { return 0; }
|
|
26
|
+
} else {
|
|
27
|
+
*result += INT64_MIN;
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
19
30
|
}
|
|
20
|
-
|
|
21
|
-
case -1:
|
|
22
|
-
if (!nails) {
|
|
23
|
-
if (*result >= 0) return 0;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
*result += INT64_MIN;
|
|
27
|
-
}
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
return 1;
|
|
31
|
+
return 1;
|
|
31
32
|
#else
|
|
32
33
|
# ifndef RBIGNUM_LEN
|
|
33
34
|
# define RBIGNUM_LEN(x) RBIGNUM(x)->len
|
|
34
35
|
# endif
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
const long len = RBIGNUM_LEN(value);
|
|
37
|
+
if (len == 0) {
|
|
38
|
+
*result = 0;
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
if (len > 63 / (SIZEOF_BDIGITS * CHAR_BIT) + 1) { return 0; }
|
|
42
|
+
if (len == 63 / (SIZEOF_BDIGITS * CHAR_BIT) + 1) {
|
|
43
|
+
const BDIGIT *digits = RBIGNUM_DIGITS(value);
|
|
44
|
+
BDIGIT blast = digits[len - 1];
|
|
45
|
+
BDIGIT bmax = (BDIGIT)1UL << (63 % (CHAR_BIT * SIZEOF_BDIGITS));
|
|
46
|
+
if (blast > bmax) { return 0; }
|
|
47
|
+
if (blast == bmax) {
|
|
48
|
+
if (RBIGNUM_POSITIVE_P(value)) {
|
|
49
|
+
return 0;
|
|
50
|
+
} else {
|
|
51
|
+
long i = len - 1;
|
|
52
|
+
while (i) {
|
|
53
|
+
if (digits[--i]) { return 0; }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return 1;
|
|
58
|
+
*result = (sqlite3_int64)NUM2LL(value);
|
|
59
|
+
return 1;
|
|
60
60
|
#endif
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
void
|
|
64
|
+
rb_sqlite3_pin_array_and_contents(VALUE ary)
|
|
64
65
|
{
|
|
65
|
-
|
|
66
|
+
long i;
|
|
67
|
+
|
|
68
|
+
if (NIL_P(ary) || !ary) { return; }
|
|
69
|
+
|
|
70
|
+
rb_gc_mark(ary);
|
|
71
|
+
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
|
72
|
+
rb_gc_mark(RARRAY_AREF(ary, i));
|
|
73
|
+
}
|
|
66
74
|
}
|
|
67
75
|
|
|
68
|
-
static VALUE
|
|
76
|
+
static VALUE
|
|
77
|
+
libversion(VALUE UNUSED(klass))
|
|
78
|
+
{
|
|
79
|
+
return INT2NUM(sqlite3_libversion_number());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static VALUE
|
|
83
|
+
using_sqlcipher(VALUE UNUSED(klass))
|
|
69
84
|
{
|
|
70
85
|
#ifdef USING_SQLCIPHER
|
|
71
|
-
|
|
86
|
+
return Qtrue;
|
|
72
87
|
#else
|
|
73
|
-
|
|
88
|
+
return Qfalse;
|
|
74
89
|
#endif
|
|
75
90
|
}
|
|
76
91
|
|
|
77
92
|
/* Returns the compile time setting of the SQLITE_THREADSAFE flag.
|
|
78
93
|
* See: https://www.sqlite.org/c3ref/threadsafe.html
|
|
79
94
|
*/
|
|
80
|
-
static VALUE
|
|
95
|
+
static VALUE
|
|
96
|
+
threadsafe_p(VALUE UNUSED(klass))
|
|
97
|
+
{
|
|
98
|
+
return INT2NUM(sqlite3_threadsafe());
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* call-seq:
|
|
103
|
+
* status(parameter) → Hash
|
|
104
|
+
* status(parameter, reset_flag = false) → Hash
|
|
105
|
+
*
|
|
106
|
+
* Queries the SQLite3 library for run-time status information. Passing a truthy +reset_flag+ will
|
|
107
|
+
* reset the highwater mark to the current value.
|
|
108
|
+
*
|
|
109
|
+
* [Parameters]
|
|
110
|
+
* - +parameter+ (Integer, SQLite3::Constants::Status): The status parameter to query.
|
|
111
|
+
* - +reset_flag+ (Boolean): Whether to reset the highwater mark. (default is +false+)
|
|
112
|
+
*
|
|
113
|
+
* [Returns]
|
|
114
|
+
* A Hash containing +:current+ and +:highwater+ keys for integer values.
|
|
115
|
+
*/
|
|
116
|
+
static VALUE
|
|
117
|
+
rb_sqlite3_status(int argc, VALUE *argv, VALUE klass)
|
|
81
118
|
{
|
|
82
|
-
|
|
119
|
+
VALUE opArg, resetFlagArg;
|
|
120
|
+
|
|
121
|
+
rb_scan_args(argc, argv, "11", &opArg, &resetFlagArg);
|
|
122
|
+
|
|
123
|
+
int op = NUM2INT(opArg);
|
|
124
|
+
bool resetFlag = RTEST(resetFlagArg);
|
|
125
|
+
|
|
126
|
+
int pCurrent = 0;
|
|
127
|
+
int pHighwater = 0;
|
|
128
|
+
sqlite3_status(op, &pCurrent, &pHighwater, resetFlag);
|
|
129
|
+
|
|
130
|
+
VALUE hash = rb_hash_new();
|
|
131
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("current")), INT2FIX(pCurrent));
|
|
132
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("highwater")), INT2FIX(pHighwater));
|
|
133
|
+
|
|
134
|
+
return hash;
|
|
83
135
|
}
|
|
84
136
|
|
|
85
|
-
void
|
|
137
|
+
void
|
|
138
|
+
init_sqlite3_constants(void)
|
|
86
139
|
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
140
|
+
VALUE mSqlite3Constants;
|
|
141
|
+
VALUE mSqlite3Open;
|
|
142
|
+
|
|
143
|
+
mSqlite3Constants = rb_define_module_under(mSqlite3, "Constants");
|
|
144
|
+
|
|
145
|
+
/* sqlite3_open_v2 flags for Database::new */
|
|
146
|
+
mSqlite3Open = rb_define_module_under(mSqlite3Constants, "Open");
|
|
147
|
+
|
|
148
|
+
/* symbols = IO.readlines('sqlite3.h').map { |n| /\A#define\s+(SQLITE_OPEN_\w+)\s/ =~ n && $1 }.compact
|
|
149
|
+
* pad = symbols.map(&:length).max - 9
|
|
150
|
+
* symbols.each { |s| printf %Q{ rb_define_const(mSqlite3Open, %-#{pad}s INT2FIX(#{s}));\n}, '"' + s[12..-1] + '",' }
|
|
151
|
+
*/
|
|
152
|
+
rb_define_const(mSqlite3Open, "READONLY", INT2FIX(SQLITE_OPEN_READONLY));
|
|
153
|
+
rb_define_const(mSqlite3Open, "READWRITE", INT2FIX(SQLITE_OPEN_READWRITE));
|
|
154
|
+
rb_define_const(mSqlite3Open, "CREATE", INT2FIX(SQLITE_OPEN_CREATE));
|
|
155
|
+
rb_define_const(mSqlite3Open, "DELETEONCLOSE", INT2FIX(SQLITE_OPEN_DELETEONCLOSE));
|
|
156
|
+
rb_define_const(mSqlite3Open, "EXCLUSIVE", INT2FIX(SQLITE_OPEN_EXCLUSIVE));
|
|
157
|
+
rb_define_const(mSqlite3Open, "MAIN_DB", INT2FIX(SQLITE_OPEN_MAIN_DB));
|
|
158
|
+
rb_define_const(mSqlite3Open, "TEMP_DB", INT2FIX(SQLITE_OPEN_TEMP_DB));
|
|
159
|
+
rb_define_const(mSqlite3Open, "TRANSIENT_DB", INT2FIX(SQLITE_OPEN_TRANSIENT_DB));
|
|
160
|
+
rb_define_const(mSqlite3Open, "MAIN_JOURNAL", INT2FIX(SQLITE_OPEN_MAIN_JOURNAL));
|
|
161
|
+
rb_define_const(mSqlite3Open, "TEMP_JOURNAL", INT2FIX(SQLITE_OPEN_TEMP_JOURNAL));
|
|
162
|
+
rb_define_const(mSqlite3Open, "SUBJOURNAL", INT2FIX(SQLITE_OPEN_SUBJOURNAL));
|
|
163
|
+
rb_define_const(mSqlite3Open, "MASTER_JOURNAL",
|
|
164
|
+
INT2FIX(SQLITE_OPEN_MASTER_JOURNAL)); /* pre-3.33.0 */
|
|
165
|
+
rb_define_const(mSqlite3Open, "SUPER_JOURNAL", INT2FIX(SQLITE_OPEN_MASTER_JOURNAL));
|
|
166
|
+
rb_define_const(mSqlite3Open, "NOMUTEX", INT2FIX(SQLITE_OPEN_NOMUTEX));
|
|
167
|
+
rb_define_const(mSqlite3Open, "FULLMUTEX", INT2FIX(SQLITE_OPEN_FULLMUTEX));
|
|
113
168
|
#ifdef SQLITE_OPEN_AUTOPROXY
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
169
|
+
/* SQLITE_VERSION_NUMBER>=3007002 */
|
|
170
|
+
rb_define_const(mSqlite3Open, "AUTOPROXY", INT2FIX(SQLITE_OPEN_AUTOPROXY));
|
|
171
|
+
rb_define_const(mSqlite3Open, "SHAREDCACHE", INT2FIX(SQLITE_OPEN_SHAREDCACHE));
|
|
172
|
+
rb_define_const(mSqlite3Open, "PRIVATECACHE", INT2FIX(SQLITE_OPEN_PRIVATECACHE));
|
|
173
|
+
rb_define_const(mSqlite3Open, "WAL", INT2FIX(SQLITE_OPEN_WAL));
|
|
119
174
|
#endif
|
|
120
175
|
#ifdef SQLITE_OPEN_URI
|
|
121
|
-
|
|
122
|
-
|
|
176
|
+
/* SQLITE_VERSION_NUMBER>=3007007 */
|
|
177
|
+
rb_define_const(mSqlite3Open, "URI", INT2FIX(SQLITE_OPEN_URI));
|
|
123
178
|
#endif
|
|
124
179
|
#ifdef SQLITE_OPEN_MEMORY
|
|
125
|
-
|
|
126
|
-
|
|
180
|
+
/* SQLITE_VERSION_NUMBER>=3007013 */
|
|
181
|
+
rb_define_const(mSqlite3Open, "MEMORY", INT2FIX(SQLITE_OPEN_MEMORY));
|
|
127
182
|
#endif
|
|
128
183
|
}
|
|
129
184
|
|
|
130
185
|
RUBY_FUNC_EXPORTED
|
|
131
|
-
void
|
|
186
|
+
void
|
|
187
|
+
Init_sqlite3_native(void)
|
|
132
188
|
{
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
189
|
+
/*
|
|
190
|
+
* SQLite3 is a wrapper around the popular database
|
|
191
|
+
* sqlite[http://sqlite.org].
|
|
192
|
+
*
|
|
193
|
+
* For an example of usage, see SQLite3::Database.
|
|
194
|
+
*/
|
|
195
|
+
mSqlite3 = rb_define_module("SQLite3");
|
|
196
|
+
|
|
197
|
+
/* A class for differentiating between strings and blobs, when binding them
|
|
198
|
+
* into statements.
|
|
199
|
+
*/
|
|
200
|
+
cSqlite3Blob = rb_define_class_under(mSqlite3, "Blob", rb_cString);
|
|
201
|
+
|
|
202
|
+
/* Initialize the sqlite3 library */
|
|
147
203
|
#ifdef HAVE_SQLITE3_INITIALIZE
|
|
148
|
-
|
|
204
|
+
sqlite3_initialize();
|
|
149
205
|
#endif
|
|
150
206
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
207
|
+
init_sqlite3_exception();
|
|
208
|
+
init_sqlite3_constants();
|
|
209
|
+
init_sqlite3_database();
|
|
210
|
+
init_sqlite3_statement();
|
|
154
211
|
#ifdef HAVE_SQLITE3_BACKUP_INIT
|
|
155
|
-
|
|
212
|
+
init_sqlite3_backup();
|
|
156
213
|
#endif
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
rb_define_const(mSqlite3, "SQLITE_VERSION_NUMBER", INT2FIX(SQLITE_VERSION_NUMBER));
|
|
162
|
-
rb_define_const(mSqlite3, "SQLITE_LOADED_VERSION", rb_str_new2(sqlite3_libversion()));
|
|
214
|
+
rb_define_singleton_method(mSqlite3, "sqlcipher?", using_sqlcipher, 0);
|
|
215
|
+
rb_define_singleton_method(mSqlite3, "libversion", libversion, 0);
|
|
216
|
+
rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0);
|
|
217
|
+
rb_define_singleton_method(mSqlite3, "status", rb_sqlite3_status, -1);
|
|
163
218
|
|
|
219
|
+
/* (String) The version of the sqlite3 library compiled with (e.g., "3.46.1") */
|
|
220
|
+
rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));
|
|
221
|
+
|
|
222
|
+
/* (Integer) The version of the sqlite3 library compiled with (e.g., 346001) */
|
|
223
|
+
rb_define_const(mSqlite3, "SQLITE_VERSION_NUMBER", INT2FIX(SQLITE_VERSION_NUMBER));
|
|
224
|
+
|
|
225
|
+
/* (String) The version of the sqlite3 library loaded at runtime (e.g., "3.46.1") */
|
|
226
|
+
rb_define_const(mSqlite3, "SQLITE_LOADED_VERSION", rb_str_new2(sqlite3_libversion()));
|
|
227
|
+
|
|
228
|
+
#ifdef USING_PACKAGED_LIBRARIES
|
|
229
|
+
rb_define_const(mSqlite3, "SQLITE_PACKAGED_LIBRARIES", Qtrue);
|
|
230
|
+
#else
|
|
231
|
+
rb_define_const(mSqlite3, "SQLITE_PACKAGED_LIBRARIES", Qfalse);
|
|
232
|
+
#endif
|
|
233
|
+
|
|
234
|
+
#ifdef USING_PRECOMPILED_LIBRARIES
|
|
235
|
+
rb_define_const(mSqlite3, "SQLITE_PRECOMPILED_LIBRARIES", Qtrue);
|
|
236
|
+
#else
|
|
237
|
+
rb_define_const(mSqlite3, "SQLITE_PRECOMPILED_LIBRARIES", Qfalse);
|
|
238
|
+
#endif
|
|
164
239
|
}
|
data/ext/sqlite3/sqlite3_ruby.h
CHANGED
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
#define UTF8_P(_obj) (rb_enc_get_index(_obj) == rb_utf8_encindex())
|
|
19
19
|
#define UTF16_LE_P(_obj) (rb_enc_get_index(_obj) == rb_enc_find_index("UTF-16LE"))
|
|
20
20
|
#define UTF16_BE_P(_obj) (rb_enc_get_index(_obj) == rb_enc_find_index("UTF-16BE"))
|
|
21
|
-
#define SQLITE3_UTF8_STR_NEW2(_obj)
|
|
22
|
-
(rb_enc_associate_index(rb_str_new2(_obj), rb_utf8_encindex()))
|
|
21
|
+
#define SQLITE3_UTF8_STR_NEW2(_obj) (rb_utf8_str_new_cstr(_obj))
|
|
23
22
|
|
|
24
23
|
#ifdef USING_SQLCIPHER_INC_SUBDIR
|
|
25
24
|
# include <sqlcipher/sqlite3.h>
|
|
@@ -42,7 +41,11 @@ extern VALUE cSqlite3Blob;
|
|
|
42
41
|
#include <statement.h>
|
|
43
42
|
#include <exception.h>
|
|
44
43
|
#include <backup.h>
|
|
44
|
+
#include <timespec.h>
|
|
45
45
|
|
|
46
46
|
int bignum_to_int64(VALUE big, sqlite3_int64 *result);
|
|
47
47
|
|
|
48
|
+
/* Pinning a collection doesn't pin what's in it, hence both. */
|
|
49
|
+
void rb_sqlite3_pin_array_and_contents(VALUE ary);
|
|
50
|
+
|
|
48
51
|
#endif
|