sqlite3 1.3.5 → 1.3.13
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 +7 -0
- data/CHANGELOG.rdoc +84 -0
- data/Gemfile +15 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +29 -6
- data/ext/sqlite3/database.c +131 -27
- data/ext/sqlite3/extconf.rb +31 -7
- data/ext/sqlite3/sqlite3.c +112 -0
- data/ext/sqlite3/sqlite3_ruby.h +12 -4
- data/ext/sqlite3/statement.c +33 -22
- data/faq/faq.yml +1 -1
- data/lib/sqlite3.rb +6 -1
- data/lib/sqlite3/database.rb +36 -24
- data/lib/sqlite3/pragmas.rb +357 -49
- data/lib/sqlite3/resultset.rb +94 -25
- data/lib/sqlite3/statement.rb +13 -17
- data/lib/sqlite3/version.rb +2 -2
- data/setup.rb +2 -2
- data/tasks/gem.rake +12 -6
- data/tasks/native.rake +22 -7
- data/tasks/vendor_sqlite3.rake +69 -20
- data/test/helper.rb +17 -2
- data/test/test_backup.rb +2 -2
- data/test/test_collation.rb +1 -1
- data/test/test_database.rb +102 -7
- data/test/test_database_readonly.rb +10 -3
- data/test/test_deprecated.rb +8 -1
- data/test/test_encoding.rb +35 -1
- data/test/test_integration.rb +36 -15
- data/test/test_integration_open_close.rb +1 -1
- data/test/test_integration_pending.rb +2 -2
- data/test/test_integration_resultset.rb +6 -3
- data/test/test_integration_statement.rb +2 -2
- data/test/test_result_set.rb +37 -0
- data/test/test_sqlite3.rb +13 -1
- data/test/test_statement.rb +26 -4
- data/test/test_statement_execute.rb +1 -1
- metadata +125 -121
- data/.gemtest +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b430789a68a6d6079e0395db6fc53421e4b317ab
|
4
|
+
data.tar.gz: db014f4a1f4e980913a3dcb48d9aab14a5a9eca1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e2764239b107677240476bb608bcb46cc0966c06d06e90881113b91dbdb8342c6c7558760cf0645a56449ac8e267f13a0e25dbef0d3e820a38f5857a96c4e05
|
7
|
+
data.tar.gz: 1e08a478ed043d22bbe95df2151bf009a7f03a1457c37df4199c8601fa1ccb9de27986e64341c4fb9a009e5ab4023638704078222f88441b55ac1ee2773838d8
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,87 @@
|
|
1
|
+
=== 1.3.12
|
2
|
+
|
3
|
+
* Bugfixes:
|
4
|
+
* OS X install will default to homebrew if available. Fixes #195
|
5
|
+
|
6
|
+
=== 1.3.11 / 2015-10-10
|
7
|
+
|
8
|
+
* Enhancements:
|
9
|
+
* Windows: build against SQLite 3.8.11.1
|
10
|
+
|
11
|
+
* Internal:
|
12
|
+
* Use rake-compiler-dock to build Windows binaries. Pull #159 [larskanis]
|
13
|
+
* Expand Ruby versions being tested for Travis and AppVeyor
|
14
|
+
|
15
|
+
=== 1.3.10 / 2014-10-30
|
16
|
+
|
17
|
+
* Enhancements:
|
18
|
+
* Windows: build against SQLite 3.8.7.1. Closes #134, #135 [Hubro]
|
19
|
+
|
20
|
+
=== 1.3.9 / 2014-02-25
|
21
|
+
|
22
|
+
* Bugfixes:
|
23
|
+
* Reset exception message. Closes #80
|
24
|
+
* Reduce warnings due unused pointers. Closes #89
|
25
|
+
* Add BSD-3 license reference to gemspec. Refs #99 and #106
|
26
|
+
|
27
|
+
=== 1.3.8 / 2013-08-17
|
28
|
+
|
29
|
+
* Enhancements:
|
30
|
+
* Windows: build against SQLite 3.7.17
|
31
|
+
|
32
|
+
* Bugfixes:
|
33
|
+
* Reset exception message. Closes #80
|
34
|
+
* Correctly convert BLOB values to Ruby. Closes #65
|
35
|
+
* Add MIT license reference to gemspec. Closes #99
|
36
|
+
* Remove unused pointer. Closes #89
|
37
|
+
|
38
|
+
* Internal:
|
39
|
+
* Backport improvements in cross compilation for Windows
|
40
|
+
* Use of Minitest for internal tests
|
41
|
+
* Use Gemfile (generated by Hoe) to deal with dependencies
|
42
|
+
* Cleanup Travis CI
|
43
|
+
|
44
|
+
=== 1.3.7 / 2013-01-11
|
45
|
+
|
46
|
+
* Bugfixes
|
47
|
+
* Closing a bad statement twice will not segv.
|
48
|
+
* Aggregate handlers are initialized on each query. Closes #44
|
49
|
+
|
50
|
+
* Internal
|
51
|
+
* Unset environment variables that could affect cross compilation.
|
52
|
+
|
53
|
+
=== 1.3.6 / 2012-04-16
|
54
|
+
|
55
|
+
* Enhancements
|
56
|
+
* Windows: build against SQLite 3.7.11
|
57
|
+
* Added SQLite3::ResultSet#each_hash for fetching each row as a hash.
|
58
|
+
* Added SQLite3::ResultSet#next_hash for fetching one row as a hash.
|
59
|
+
|
60
|
+
* Bugfixes
|
61
|
+
* Support both UTF-16LE and UTF-16BE encoding modes on PPC. Closes #63
|
62
|
+
* Protect parameters to custom functions from being garbage collected too
|
63
|
+
soon. Fixes #60. Thanks hirataya!
|
64
|
+
* Fix backwards compatibility with 1.2.5 with bind vars and `query` method.
|
65
|
+
Fixes #35.
|
66
|
+
* Fix double definition error caused by defining sqlite3_int64/uint64.
|
67
|
+
* Fix suspicious version regexp.
|
68
|
+
|
69
|
+
* Deprecations
|
70
|
+
* ArrayWithTypesAndFields#types is deprecated and the class will be removed
|
71
|
+
in version 2.0.0. Please use the `types` method on the ResultSet class
|
72
|
+
that created this object.
|
73
|
+
* ArrayWithTypesAndFields#fields is deprecated and the class will be removed
|
74
|
+
in version 2.0.0. Please use the `columns` method on the ResultSet class
|
75
|
+
that created this object.
|
76
|
+
* The ArrayWithTypesAndFields class will be removed in 2.0.0
|
77
|
+
* The ArrayWithTypes class will be removed in 2.0.0
|
78
|
+
* HashWithTypesAndFields#types is deprecated and the class will be removed
|
79
|
+
in version 2.0.0. Please use the `types` method on the ResultSet class
|
80
|
+
that created this object.
|
81
|
+
* HashWithTypesAndFields#fields is deprecated and the class will be removed
|
82
|
+
in version 2.0.0. Please use the `columns` method on the ResultSet class
|
83
|
+
that created this object.
|
84
|
+
|
1
85
|
=== 1.3.5 / 2011-12-03 - ZOMG Holidays are here Edition!
|
2
86
|
|
3
87
|
* Enhancements
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
# DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
|
4
|
+
|
5
|
+
source "https://rubygems.org/"
|
6
|
+
|
7
|
+
|
8
|
+
gem "minitest", "~>5.9", :group => [:development, :test]
|
9
|
+
gem "rake-compiler", "~>0.9.3", :group => [:development, :test]
|
10
|
+
gem "rake-compiler-dock", "~>0.5.2", :group => [:development, :test]
|
11
|
+
gem "mini_portile", "~>0.6.2", :group => [:development, :test]
|
12
|
+
gem "hoe-bundler", "~>1.0", :group => [:development, :test]
|
13
|
+
gem "hoe", "~>3.15", :group => [:development, :test]
|
14
|
+
|
15
|
+
# vim: syntax=ruby
|
data/Manifest.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
API_CHANGES.rdoc
|
2
2
|
CHANGELOG.rdoc
|
3
3
|
ChangeLog.cvs
|
4
|
+
Gemfile
|
4
5
|
LICENSE
|
5
6
|
Manifest.txt
|
6
7
|
README.rdoc
|
@@ -45,6 +46,7 @@ test/test_integration_open_close.rb
|
|
45
46
|
test/test_integration_pending.rb
|
46
47
|
test/test_integration_resultset.rb
|
47
48
|
test/test_integration_statement.rb
|
49
|
+
test/test_result_set.rb
|
48
50
|
test/test_sqlite3.rb
|
49
51
|
test/test_statement.rb
|
50
52
|
test/test_statement_execute.rb
|
data/README.rdoc
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
= SQLite3/Ruby Interface
|
2
2
|
|
3
|
-
*
|
3
|
+
* https://github.com/sparklemotion/sqlite3-ruby
|
4
4
|
* http://groups.google.com/group/sqlite3-ruby
|
5
|
+
* http://rubygems.org/gems/sqlite3
|
6
|
+
* http://www.rubydoc.info/gems/sqlite3/frames
|
7
|
+
|
8
|
+
{<img src="https://travis-ci.org/sparklemotion/sqlite3-ruby.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/sparklemotion/sqlite3-ruby]
|
5
9
|
|
6
10
|
== DESCRIPTION
|
7
11
|
|
@@ -18,7 +22,7 @@ Note that this module is only compatible with SQLite 3.6.16 or newer.
|
|
18
22
|
# Open a database
|
19
23
|
db = SQLite3::Database.new "test.db"
|
20
24
|
|
21
|
-
# Create a
|
25
|
+
# Create a table
|
22
26
|
rows = db.execute <<-SQL
|
23
27
|
create table numbers (
|
24
28
|
name varchar(30),
|
@@ -33,12 +37,31 @@ Note that this module is only compatible with SQLite 3.6.16 or newer.
|
|
33
37
|
}.each do |pair|
|
34
38
|
db.execute "insert into numbers values ( ?, ? )", pair
|
35
39
|
end
|
36
|
-
|
40
|
+
|
37
41
|
# Find a few rows
|
38
42
|
db.execute( "select * from numbers" ) do |row|
|
39
43
|
p row
|
40
44
|
end
|
41
45
|
|
46
|
+
# Create another table with multiple columns
|
47
|
+
|
48
|
+
db.execute <<-SQL
|
49
|
+
create table students (
|
50
|
+
name varchar(50),
|
51
|
+
email varchar(50),
|
52
|
+
grade varchar(5),
|
53
|
+
blog varchar(50)
|
54
|
+
);
|
55
|
+
SQL
|
56
|
+
|
57
|
+
# Execute inserts with parameter markers
|
58
|
+
db.execute("INSERT INTO students (name, email, grade, blog)
|
59
|
+
VALUES (?, ?, ?, ?)", ["Jane", "me@janedoe.com", "A", "http://blog.janedoe.com"])
|
60
|
+
|
61
|
+
db.execute( "select * from students" ) do |row|
|
62
|
+
p row
|
63
|
+
end
|
64
|
+
|
42
65
|
|
43
66
|
== Compilation and Installation
|
44
67
|
|
@@ -75,10 +98,10 @@ can be found here:
|
|
75
98
|
|
76
99
|
Uh oh. After contacting the mailing list, you've found that you've actually
|
77
100
|
discovered a bug. You can file the bug at the
|
78
|
-
{github issues page}[
|
101
|
+
{github issues page}[https://github.com/sparklemotion/sqlite3-ruby/issues]
|
79
102
|
which can be found here:
|
80
103
|
|
81
|
-
*
|
104
|
+
* https://github.com/sparklemotion/sqlite3-ruby/issues
|
82
105
|
|
83
106
|
== Usage
|
84
107
|
|
@@ -91,5 +114,5 @@ FAQ, please send them to {the mailing list}[http://groups.google.com/group/sqlit
|
|
91
114
|
|
92
115
|
The source repository is accessible via git:
|
93
116
|
|
94
|
-
git clone git://github.com/
|
117
|
+
git clone git://github.com/sparklemotion/sqlite3-ruby.git
|
95
118
|
|
data/ext/sqlite3/database.c
CHANGED
@@ -30,6 +30,8 @@ utf16_string_value_ptr(VALUE str)
|
|
30
30
|
return RSTRING_PTR(str);
|
31
31
|
}
|
32
32
|
|
33
|
+
static VALUE sqlite3_rb_close(VALUE self);
|
34
|
+
|
33
35
|
/* call-seq: SQLite3::Database.new(file, options = {})
|
34
36
|
*
|
35
37
|
* Create a new Database object that opens the given file. If utf16
|
@@ -44,7 +46,10 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
44
46
|
VALUE file;
|
45
47
|
VALUE opts;
|
46
48
|
VALUE zvfs;
|
49
|
+
VALUE flags;
|
50
|
+
#ifdef HAVE_SQLITE3_OPEN_V2
|
47
51
|
int mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
|
52
|
+
#endif
|
48
53
|
int status;
|
49
54
|
|
50
55
|
Data_Get_Struct(self, sqlite3Ruby, ctx);
|
@@ -60,7 +65,7 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
60
65
|
else Check_Type(opts, T_HASH);
|
61
66
|
|
62
67
|
#ifdef HAVE_RUBY_ENCODING_H
|
63
|
-
if(UTF16_LE_P(file)) {
|
68
|
+
if(UTF16_LE_P(file) || UTF16_BE_P(file)) {
|
64
69
|
status = sqlite3_open16(utf16_string_value_ptr(file), &ctx->db);
|
65
70
|
} else {
|
66
71
|
#endif
|
@@ -75,15 +80,52 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
75
80
|
}
|
76
81
|
#endif
|
77
82
|
|
83
|
+
/* The three primary flag values for sqlite3_open_v2 are:
|
84
|
+
* SQLITE_OPEN_READONLY
|
85
|
+
* SQLITE_OPEN_READWRITE
|
86
|
+
* SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE -- always used for sqlite3_open and sqlite3_open16
|
87
|
+
*/
|
78
88
|
if (Qtrue == rb_hash_aref(opts, ID2SYM(rb_intern("readonly")))) {
|
89
|
+
#ifdef HAVE_SQLITE3_OPEN_V2
|
79
90
|
mode = SQLITE_OPEN_READONLY;
|
91
|
+
#else
|
92
|
+
rb_raise(rb_eNotImpError, "sqlite3-ruby was compiled against a version of sqlite that does not support readonly databases");
|
93
|
+
#endif
|
94
|
+
}
|
95
|
+
if (Qtrue == rb_hash_aref(opts, ID2SYM(rb_intern("readwrite")))) {
|
96
|
+
#ifdef HAVE_SQLITE3_OPEN_V2
|
97
|
+
if (mode == SQLITE_OPEN_READONLY) {
|
98
|
+
rb_raise(rb_eRuntimeError, "conflicting options: readonly and readwrite");
|
99
|
+
}
|
100
|
+
mode = SQLITE_OPEN_READWRITE;
|
101
|
+
#else
|
102
|
+
rb_raise(rb_eNotImpError, "sqlite3-ruby was compiled against a version of sqlite that does not support readwrite without create");
|
103
|
+
#endif
|
104
|
+
}
|
105
|
+
flags = rb_hash_aref(opts, ID2SYM(rb_intern("flags")));
|
106
|
+
if (flags != Qnil) {
|
107
|
+
#ifdef HAVE_SQLITE3_OPEN_V2
|
108
|
+
if ((mode & SQLITE_OPEN_CREATE) == 0) {
|
109
|
+
rb_raise(rb_eRuntimeError, "conflicting options: flags with readonly and/or readwrite");
|
110
|
+
}
|
111
|
+
mode = (int)NUM2INT(flags);
|
112
|
+
#else
|
113
|
+
rb_raise(rb_eNotImpError, "sqlite3-ruby was compiled against a version of sqlite that does not support flags on open");
|
114
|
+
#endif
|
80
115
|
}
|
116
|
+
#ifdef HAVE_SQLITE3_OPEN_V2
|
81
117
|
status = sqlite3_open_v2(
|
82
118
|
StringValuePtr(file),
|
83
119
|
&ctx->db,
|
84
120
|
mode,
|
85
121
|
NIL_P(zvfs) ? NULL : StringValuePtr(zvfs)
|
86
122
|
);
|
123
|
+
#else
|
124
|
+
status = sqlite3_open(
|
125
|
+
StringValuePtr(file),
|
126
|
+
&ctx->db
|
127
|
+
);
|
128
|
+
#endif
|
87
129
|
}
|
88
130
|
|
89
131
|
#ifdef HAVE_RUBY_ENCODING_H
|
@@ -100,11 +142,14 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
100
142
|
rb_iv_set(self, "@functions", rb_hash_new());
|
101
143
|
rb_iv_set(self, "@results_as_hash", rb_hash_aref(opts, sym_results_as_hash));
|
102
144
|
rb_iv_set(self, "@type_translation", rb_hash_aref(opts, sym_type_translation));
|
103
|
-
|
145
|
+
#ifdef HAVE_SQLITE3_OPEN_V2
|
146
|
+
rb_iv_set(self, "@readonly", (mode & SQLITE_OPEN_READONLY) ? Qtrue : Qfalse);
|
147
|
+
#else
|
148
|
+
rb_iv_set(self, "@readonly", Qfalse);
|
149
|
+
#endif
|
104
150
|
|
105
151
|
if(rb_block_given_p()) {
|
106
|
-
rb_yield
|
107
|
-
rb_funcall(self, rb_intern("close"), 0);
|
152
|
+
rb_ensure(rb_yield, self, sqlite3_rb_close, self);
|
108
153
|
}
|
109
154
|
|
110
155
|
return self;
|
@@ -264,9 +309,23 @@ static VALUE sqlite3val2rb(sqlite3_value * val)
|
|
264
309
|
case SQLITE_TEXT:
|
265
310
|
return rb_tainted_str_new2((const char *)sqlite3_value_text(val));
|
266
311
|
break;
|
267
|
-
case SQLITE_BLOB:
|
268
|
-
|
312
|
+
case SQLITE_BLOB: {
|
313
|
+
/* Sqlite warns calling sqlite3_value_bytes may invalidate pointer from sqlite3_value_blob,
|
314
|
+
so we explicitly get the length before getting blob pointer.
|
315
|
+
Note that rb_str_new and rb_tainted_str_new apparently create string with ASCII-8BIT (BINARY) encoding,
|
316
|
+
which is what we want, as blobs are binary
|
317
|
+
*/
|
318
|
+
int len = sqlite3_value_bytes(val);
|
319
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
320
|
+
return rb_tainted_str_new((const char *)sqlite3_value_blob(val), len);
|
321
|
+
#else
|
322
|
+
/* When encoding is not available, make it class SQLite3::Blob. */
|
323
|
+
VALUE strargv[1];
|
324
|
+
strargv[0] = rb_tainted_str_new((const char *)sqlite3_value_blob(val), len);
|
325
|
+
return rb_class_new_instance(1, strargv, cSqlite3Blob);
|
326
|
+
#endif
|
269
327
|
break;
|
328
|
+
}
|
270
329
|
case SQLITE_NULL:
|
271
330
|
return Qnil;
|
272
331
|
break;
|
@@ -284,23 +343,39 @@ static void set_sqlite3_func_result(sqlite3_context * ctx, VALUE result)
|
|
284
343
|
case T_FIXNUM:
|
285
344
|
sqlite3_result_int64(ctx, (sqlite3_int64)FIX2LONG(result));
|
286
345
|
break;
|
287
|
-
case T_BIGNUM:
|
346
|
+
case T_BIGNUM: {
|
288
347
|
#if SIZEOF_LONG < 8
|
289
|
-
|
290
|
-
|
291
|
-
|
348
|
+
sqlite3_int64 num64;
|
349
|
+
|
350
|
+
if (bignum_to_int64(result, &num64)) {
|
351
|
+
sqlite3_result_int64(ctx, num64);
|
352
|
+
break;
|
292
353
|
}
|
293
354
|
#endif
|
355
|
+
}
|
294
356
|
case T_FLOAT:
|
295
357
|
sqlite3_result_double(ctx, NUM2DBL(result));
|
296
358
|
break;
|
297
359
|
case T_STRING:
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
360
|
+
if(CLASS_OF(result) == cSqlite3Blob
|
361
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
362
|
+
|| rb_enc_get_index(result) == rb_ascii8bit_encindex()
|
363
|
+
#endif
|
364
|
+
) {
|
365
|
+
sqlite3_result_blob(
|
366
|
+
ctx,
|
367
|
+
(const void *)StringValuePtr(result),
|
368
|
+
(int)RSTRING_LEN(result),
|
369
|
+
SQLITE_TRANSIENT
|
370
|
+
);
|
371
|
+
} else {
|
372
|
+
sqlite3_result_text(
|
373
|
+
ctx,
|
374
|
+
(const char *)StringValuePtr(result),
|
375
|
+
(int)RSTRING_LEN(result),
|
376
|
+
SQLITE_TRANSIENT
|
377
|
+
);
|
378
|
+
}
|
304
379
|
break;
|
305
380
|
default:
|
306
381
|
rb_raise(rb_eRuntimeError, "can't return %s",
|
@@ -311,20 +386,18 @@ static void set_sqlite3_func_result(sqlite3_context * ctx, VALUE result)
|
|
311
386
|
static void rb_sqlite3_func(sqlite3_context * ctx, int argc, sqlite3_value **argv)
|
312
387
|
{
|
313
388
|
VALUE callable = (VALUE)sqlite3_user_data(ctx);
|
314
|
-
VALUE
|
389
|
+
VALUE params = rb_ary_new2(argc);
|
315
390
|
VALUE result;
|
316
391
|
int i;
|
317
392
|
|
318
393
|
if (argc > 0) {
|
319
|
-
params = xcalloc((size_t)argc, sizeof(VALUE *));
|
320
|
-
|
321
394
|
for(i = 0; i < argc; i++) {
|
322
|
-
|
395
|
+
VALUE param = sqlite3val2rb(argv[i]);
|
396
|
+
rb_ary_push(params, param);
|
323
397
|
}
|
324
398
|
}
|
325
399
|
|
326
|
-
result =
|
327
|
-
xfree(params);
|
400
|
+
result = rb_apply(callable, rb_intern("call"), params);
|
328
401
|
|
329
402
|
set_sqlite3_func_result(ctx, result);
|
330
403
|
}
|
@@ -625,13 +698,12 @@ static VALUE collation(VALUE self, VALUE name, VALUE comparator)
|
|
625
698
|
Data_Get_Struct(self, sqlite3Ruby, ctx);
|
626
699
|
REQUIRE_OPEN_DB(ctx);
|
627
700
|
|
628
|
-
CHECK(ctx->db,
|
701
|
+
CHECK(ctx->db, sqlite3_create_collation(
|
629
702
|
ctx->db,
|
630
703
|
StringValuePtr(name),
|
631
704
|
SQLITE_UTF8,
|
632
705
|
(void *)comparator,
|
633
|
-
NIL_P(comparator) ? NULL : rb_comparator_func
|
634
|
-
NULL));
|
706
|
+
NIL_P(comparator) ? NULL : rb_comparator_func));
|
635
707
|
|
636
708
|
/* Make sure our comparator doesn't get garbage collected. */
|
637
709
|
rb_hash_aset(rb_iv_get(self, "@collations"), name, comparator);
|
@@ -639,10 +711,11 @@ static VALUE collation(VALUE self, VALUE name, VALUE comparator)
|
|
639
711
|
return self;
|
640
712
|
}
|
641
713
|
|
714
|
+
#ifdef HAVE_SQLITE3_LOAD_EXTENSION
|
642
715
|
/* call-seq: db.load_extension(file)
|
643
716
|
*
|
644
717
|
* Loads an SQLite extension library from the named file. Extension
|
645
|
-
* loading must be enabled using db.enable_load_extension(
|
718
|
+
* loading must be enabled using db.enable_load_extension(true) prior
|
646
719
|
* to calling this API.
|
647
720
|
*/
|
648
721
|
static VALUE load_extension(VALUE self, VALUE file)
|
@@ -664,7 +737,9 @@ static VALUE load_extension(VALUE self, VALUE file)
|
|
664
737
|
|
665
738
|
return self;
|
666
739
|
}
|
740
|
+
#endif
|
667
741
|
|
742
|
+
#ifdef HAVE_SQLITE3_ENABLE_LOAD_EXTENSION
|
668
743
|
/* call-seq: db.enable_load_extension(onoff)
|
669
744
|
*
|
670
745
|
* Enable or disable extension loading.
|
@@ -672,13 +747,23 @@ static VALUE load_extension(VALUE self, VALUE file)
|
|
672
747
|
static VALUE enable_load_extension(VALUE self, VALUE onoff)
|
673
748
|
{
|
674
749
|
sqlite3RubyPtr ctx;
|
750
|
+
int onoffparam;
|
675
751
|
Data_Get_Struct(self, sqlite3Ruby, ctx);
|
676
752
|
REQUIRE_OPEN_DB(ctx);
|
677
753
|
|
678
|
-
|
754
|
+
if (Qtrue == onoff) {
|
755
|
+
onoffparam = 1;
|
756
|
+
} else if (Qfalse == onoff) {
|
757
|
+
onoffparam = 0;
|
758
|
+
} else {
|
759
|
+
onoffparam = (int)NUM2INT(onoff);
|
760
|
+
}
|
761
|
+
|
762
|
+
CHECK(ctx->db, sqlite3_enable_load_extension(ctx->db, onoffparam));
|
679
763
|
|
680
764
|
return self;
|
681
765
|
}
|
766
|
+
#endif
|
682
767
|
|
683
768
|
#ifdef HAVE_RUBY_ENCODING_H
|
684
769
|
static int enc_cb(void * _self, int UNUSED(columns), char **data, char **UNUSED(names))
|
@@ -737,6 +822,24 @@ static VALUE transaction_active_p(VALUE self)
|
|
737
822
|
return sqlite3_get_autocommit(ctx->db) ? Qfalse : Qtrue;
|
738
823
|
}
|
739
824
|
|
825
|
+
/* call-seq: db.db_filename(database_name)
|
826
|
+
*
|
827
|
+
* Returns the file associated with +database_name+. Can return nil or an
|
828
|
+
* empty string if the database is temporary, or in-memory.
|
829
|
+
*/
|
830
|
+
static VALUE db_filename(VALUE self, VALUE db_name)
|
831
|
+
{
|
832
|
+
sqlite3RubyPtr ctx;
|
833
|
+
const char * fname;
|
834
|
+
Data_Get_Struct(self, sqlite3Ruby, ctx);
|
835
|
+
REQUIRE_OPEN_DB(ctx);
|
836
|
+
|
837
|
+
fname = sqlite3_db_filename(ctx->db, StringValueCStr(db_name));
|
838
|
+
|
839
|
+
if(fname) return SQLITE3_UTF8_STR_NEW2(fname);
|
840
|
+
return Qnil;
|
841
|
+
}
|
842
|
+
|
740
843
|
void init_sqlite3_database()
|
741
844
|
{
|
742
845
|
ID id_utf16, id_results_as_hash, id_type_translation;
|
@@ -764,6 +867,7 @@ void init_sqlite3_database()
|
|
764
867
|
rb_define_method(cSqlite3Database, "busy_handler", busy_handler, -1);
|
765
868
|
rb_define_method(cSqlite3Database, "busy_timeout=", set_busy_timeout, 1);
|
766
869
|
rb_define_method(cSqlite3Database, "transaction_active?", transaction_active_p, 0);
|
870
|
+
rb_define_private_method(cSqlite3Database, "db_filename", db_filename, 1);
|
767
871
|
|
768
872
|
#ifdef HAVE_SQLITE3_LOAD_EXTENSION
|
769
873
|
rb_define_method(cSqlite3Database, "load_extension", load_extension, 1);
|