sqlite3 1.3.11-x86-mingw32 → 1.3.12-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +5 -0
- data/Gemfile +3 -4
- data/README.rdoc +21 -4
- data/ext/sqlite3/database.c +79 -16
- data/ext/sqlite3/extconf.rb +23 -2
- data/ext/sqlite3/sqlite3.c +55 -0
- data/lib/sqlite3.rb +5 -0
- data/lib/sqlite3/1.8/sqlite3_native.so +0 -0
- data/lib/sqlite3/1.9/sqlite3_native.so +0 -0
- data/lib/sqlite3/2.0/sqlite3_native.so +0 -0
- data/lib/sqlite3/2.1/sqlite3_native.so +0 -0
- data/lib/sqlite3/2.2/sqlite3_native.so +0 -0
- data/lib/sqlite3/2.3/sqlite3_native.so +0 -0
- data/lib/sqlite3/database.rb +11 -10
- data/lib/sqlite3/pragmas.rb +357 -40
- data/lib/sqlite3/version.rb +2 -2
- data/tasks/gem.rake +1 -1
- data/test/test_database.rb +63 -1
- data/test/test_database_readonly.rb +9 -2
- data/test/test_integration.rb +4 -0
- data/test/test_sqlite3.rb +12 -0
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 988e8ffc46d2c517456bcf245e319e78bd0f5865
|
4
|
+
data.tar.gz: cd03bf0b7959c56d32ffb304d00eec8fff2bf153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6790f2f33bb72f826e4dd4878dd207c0637b6975642eccced21b152f401dbc57fb2457c11f5e8f5e02325828f55a09363f839a95f3160c62ddc63e46fb773d5
|
7
|
+
data.tar.gz: 45644743aed7ea5e1bb7ee3914b7395066f808d7d14b1706d8d69fd921035ea998e6ed7f8ef98536913ddaf25bf403dada22c6b046e0410feb8e846050c4245f
|
data/CHANGELOG.rdoc
CHANGED
data/Gemfile
CHANGED
@@ -5,12 +5,11 @@
|
|
5
5
|
source "https://rubygems.org/"
|
6
6
|
|
7
7
|
|
8
|
-
gem "minitest", "~>5.
|
9
|
-
gem "rdoc", "~>4.0", :group => [:development, :test]
|
8
|
+
gem "minitest", "~>5.9", :group => [:development, :test]
|
10
9
|
gem "rake-compiler", "~>0.9.3", :group => [:development, :test]
|
11
|
-
gem "rake-compiler-dock", "~>0.
|
10
|
+
gem "rake-compiler-dock", "~>0.5.2", :group => [:development, :test]
|
12
11
|
gem "mini_portile", "~>0.6.2", :group => [:development, :test]
|
13
12
|
gem "hoe-bundler", "~>1.0", :group => [:development, :test]
|
14
|
-
gem "hoe", "~>3.
|
13
|
+
gem "hoe", "~>3.15", :group => [:development, :test]
|
15
14
|
|
16
15
|
# vim: syntax=ruby
|
data/README.rdoc
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
* http://rubygems.org/gems/sqlite3
|
6
6
|
* http://www.rubydoc.info/gems/sqlite3/frames
|
7
7
|
|
8
|
+
{<img src="https://travis-ci.org/sparklemotion/sqlite3-ruby.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/sparklemotion/sqlite3-ruby]
|
9
|
+
|
8
10
|
== DESCRIPTION
|
9
11
|
|
10
12
|
This module allows Ruby programs to interface with the SQLite3
|
@@ -20,7 +22,7 @@ Note that this module is only compatible with SQLite 3.6.16 or newer.
|
|
20
22
|
# Open a database
|
21
23
|
db = SQLite3::Database.new "test.db"
|
22
24
|
|
23
|
-
# Create a
|
25
|
+
# Create a table
|
24
26
|
rows = db.execute <<-SQL
|
25
27
|
create table numbers (
|
26
28
|
name varchar(30),
|
@@ -36,12 +38,27 @@ Note that this module is only compatible with SQLite 3.6.16 or newer.
|
|
36
38
|
db.execute "insert into numbers values ( ?, ? )", pair
|
37
39
|
end
|
38
40
|
|
41
|
+
# Find a few rows
|
42
|
+
db.execute( "select * from numbers" ) do |row|
|
43
|
+
p row
|
44
|
+
end
|
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
|
+
|
39
57
|
# Execute inserts with parameter markers
|
40
58
|
db.execute("INSERT INTO students (name, email, grade, blog)
|
41
|
-
VALUES (?, ?, ?, ?)", [
|
59
|
+
VALUES (?, ?, ?, ?)", ["Jane", "me@janedoe.com", "A", "http://blog.janedoe.com"])
|
42
60
|
|
43
|
-
|
44
|
-
db.execute( "select * from numbers" ) do |row|
|
61
|
+
db.execute( "select * from students" ) do |row|
|
45
62
|
p row
|
46
63
|
end
|
47
64
|
|
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
|
@@ -45,6 +47,7 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
45
47
|
VALUE opts;
|
46
48
|
VALUE zvfs;
|
47
49
|
#ifdef HAVE_SQLITE3_OPEN_V2
|
50
|
+
VALUE flags;
|
48
51
|
int mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
|
49
52
|
#endif
|
50
53
|
int status;
|
@@ -77,11 +80,37 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
77
80
|
}
|
78
81
|
#endif
|
79
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
|
+
*/
|
80
88
|
if (Qtrue == rb_hash_aref(opts, ID2SYM(rb_intern("readonly")))) {
|
81
89
|
#ifdef HAVE_SQLITE3_OPEN_V2
|
82
90
|
mode = SQLITE_OPEN_READONLY;
|
83
91
|
#else
|
84
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");
|
85
114
|
#endif
|
86
115
|
}
|
87
116
|
#ifdef HAVE_SQLITE3_OPEN_V2
|
@@ -114,14 +143,13 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
|
114
143
|
rb_iv_set(self, "@results_as_hash", rb_hash_aref(opts, sym_results_as_hash));
|
115
144
|
rb_iv_set(self, "@type_translation", rb_hash_aref(opts, sym_type_translation));
|
116
145
|
#ifdef HAVE_SQLITE3_OPEN_V2
|
117
|
-
rb_iv_set(self, "@readonly", mode
|
146
|
+
rb_iv_set(self, "@readonly", (mode & SQLITE_OPEN_READONLY) ? Qtrue : Qfalse);
|
118
147
|
#else
|
119
148
|
rb_iv_set(self, "@readonly", Qfalse);
|
120
149
|
#endif
|
121
150
|
|
122
151
|
if(rb_block_given_p()) {
|
123
|
-
rb_yield
|
124
|
-
rb_funcall(self, rb_intern("close"), 0);
|
152
|
+
rb_ensure(rb_yield, self, sqlite3_rb_close, self);
|
125
153
|
}
|
126
154
|
|
127
155
|
return self;
|
@@ -288,7 +316,14 @@ static VALUE sqlite3val2rb(sqlite3_value * val)
|
|
288
316
|
which is what we want, as blobs are binary
|
289
317
|
*/
|
290
318
|
int len = sqlite3_value_bytes(val);
|
319
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
291
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
|
292
327
|
break;
|
293
328
|
}
|
294
329
|
case SQLITE_NULL:
|
@@ -322,12 +357,25 @@ static void set_sqlite3_func_result(sqlite3_context * ctx, VALUE result)
|
|
322
357
|
sqlite3_result_double(ctx, NUM2DBL(result));
|
323
358
|
break;
|
324
359
|
case T_STRING:
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
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
|
+
}
|
331
379
|
break;
|
332
380
|
default:
|
333
381
|
rb_raise(rb_eRuntimeError, "can't return %s",
|
@@ -338,22 +386,18 @@ static void set_sqlite3_func_result(sqlite3_context * ctx, VALUE result)
|
|
338
386
|
static void rb_sqlite3_func(sqlite3_context * ctx, int argc, sqlite3_value **argv)
|
339
387
|
{
|
340
388
|
VALUE callable = (VALUE)sqlite3_user_data(ctx);
|
341
|
-
VALUE
|
389
|
+
VALUE params = rb_ary_new2(argc);
|
342
390
|
VALUE result;
|
343
391
|
int i;
|
344
392
|
|
345
393
|
if (argc > 0) {
|
346
|
-
params = xcalloc((size_t)argc, sizeof(VALUE *));
|
347
|
-
|
348
394
|
for(i = 0; i < argc; i++) {
|
349
395
|
VALUE param = sqlite3val2rb(argv[i]);
|
350
|
-
|
351
|
-
params[i] = param;
|
396
|
+
rb_ary_push(params, param);
|
352
397
|
}
|
353
398
|
}
|
354
399
|
|
355
|
-
result =
|
356
|
-
xfree(params);
|
400
|
+
result = rb_apply(callable, rb_intern("call"), params);
|
357
401
|
|
358
402
|
set_sqlite3_func_result(ctx, result);
|
359
403
|
}
|
@@ -778,6 +822,24 @@ static VALUE transaction_active_p(VALUE self)
|
|
778
822
|
return sqlite3_get_autocommit(ctx->db) ? Qfalse : Qtrue;
|
779
823
|
}
|
780
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
|
+
|
781
843
|
void init_sqlite3_database()
|
782
844
|
{
|
783
845
|
ID id_utf16, id_results_as_hash, id_type_translation;
|
@@ -805,6 +867,7 @@ void init_sqlite3_database()
|
|
805
867
|
rb_define_method(cSqlite3Database, "busy_handler", busy_handler, -1);
|
806
868
|
rb_define_method(cSqlite3Database, "busy_timeout=", set_busy_timeout, 1);
|
807
869
|
rb_define_method(cSqlite3Database, "transaction_active?", transaction_active_p, 0);
|
870
|
+
rb_define_private_method(cSqlite3Database, "db_filename", db_filename, 1);
|
808
871
|
|
809
872
|
#ifdef HAVE_SQLITE3_LOAD_EXTENSION
|
810
873
|
rb_define_method(cSqlite3Database, "load_extension", load_extension, 1);
|
data/ext/sqlite3/extconf.rb
CHANGED
@@ -6,8 +6,28 @@ require 'mkmf'
|
|
6
6
|
|
7
7
|
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
|
8
8
|
|
9
|
+
|
10
|
+
|
11
|
+
ldflags = cppflags = nil
|
12
|
+
if RbConfig::CONFIG["host_os"] =~ /darwin/
|
13
|
+
begin
|
14
|
+
brew_info = `brew info sqlite3`
|
15
|
+
ldflags = brew_info[/LDFLAGS.*$/].split(/-L/).last
|
16
|
+
cppflags = brew_info[/CPPFLAGS.*$/].split(/-I/).last
|
17
|
+
pkg_conf = brew_info[/PKG_CONFIG_PATH.*$/].split(": ").last
|
18
|
+
|
19
|
+
# pkg_config should be less error prone than parsing compiler
|
20
|
+
# commandline options, but we need to set default ldflags and cpp flags
|
21
|
+
# in case the user doesn't have pkg-config installed
|
22
|
+
ENV['PKG_CONFIG_PATH'] ||= pkg_conf
|
23
|
+
rescue
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
pkg_config("sqlite3")
|
28
|
+
|
9
29
|
# --with-sqlite3-{dir,include,lib}
|
10
|
-
dir_config("sqlite3")
|
30
|
+
dir_config("sqlite3", cppflags, ldflags)
|
11
31
|
|
12
32
|
if RbConfig::CONFIG["host_os"] =~ /mswin/
|
13
33
|
$CFLAGS << ' -W3'
|
@@ -19,7 +39,7 @@ def asplode missing
|
|
19
39
|
"http://www.sqlite.org/ first."
|
20
40
|
else
|
21
41
|
abort <<-error
|
22
|
-
#{missing} is missing. Try '
|
42
|
+
#{missing} is missing. Try 'brew install sqlite3',
|
23
43
|
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
|
24
44
|
and check your shared library search path (the
|
25
45
|
location where your sqlite3 shared library is located).
|
@@ -28,6 +48,7 @@ location where your sqlite3 shared library is located).
|
|
28
48
|
end
|
29
49
|
|
30
50
|
asplode('sqlite3.h') unless find_header 'sqlite3.h'
|
51
|
+
find_library 'pthread', 'pthread_create' # 1.8 support. *shrug*
|
31
52
|
asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'
|
32
53
|
|
33
54
|
# Functions defined in 1.9 but not 1.8
|
data/ext/sqlite3/sqlite3.c
CHANGED
@@ -65,6 +65,59 @@ static VALUE libversion(VALUE UNUSED(klass))
|
|
65
65
|
return INT2NUM(sqlite3_libversion_number());
|
66
66
|
}
|
67
67
|
|
68
|
+
/* Returns the compile time setting of the SQLITE_THREADSAFE flag.
|
69
|
+
* See: https://www.sqlite.org/c3ref/threadsafe.html
|
70
|
+
*/
|
71
|
+
static VALUE threadsafe_p(VALUE UNUSED(klass))
|
72
|
+
{
|
73
|
+
return INT2NUM(sqlite3_threadsafe());
|
74
|
+
}
|
75
|
+
|
76
|
+
void init_sqlite3_constants()
|
77
|
+
{
|
78
|
+
VALUE mSqlite3Constants;
|
79
|
+
VALUE mSqlite3Open;
|
80
|
+
|
81
|
+
mSqlite3Constants = rb_define_module_under(mSqlite3, "Constants");
|
82
|
+
|
83
|
+
/* sqlite3_open_v2 flags for Database::new */
|
84
|
+
mSqlite3Open = rb_define_module_under(mSqlite3Constants, "Open");
|
85
|
+
|
86
|
+
/* symbols = IO.readlines('sqlite3.h').map { |n| /\A#define\s+(SQLITE_OPEN_\w+)\s/ =~ n && $1 }.compact
|
87
|
+
* pad = symbols.map(&:length).max - 9
|
88
|
+
* symbols.each { |s| printf %Q{ rb_define_const(mSqlite3Open, %-#{pad}s INT2FIX(#{s}));\n}, '"' + s[12..-1] + '",' }
|
89
|
+
*/
|
90
|
+
rb_define_const(mSqlite3Open, "READONLY", INT2FIX(SQLITE_OPEN_READONLY));
|
91
|
+
rb_define_const(mSqlite3Open, "READWRITE", INT2FIX(SQLITE_OPEN_READWRITE));
|
92
|
+
rb_define_const(mSqlite3Open, "CREATE", INT2FIX(SQLITE_OPEN_CREATE));
|
93
|
+
rb_define_const(mSqlite3Open, "DELETEONCLOSE", INT2FIX(SQLITE_OPEN_DELETEONCLOSE));
|
94
|
+
rb_define_const(mSqlite3Open, "EXCLUSIVE", INT2FIX(SQLITE_OPEN_EXCLUSIVE));
|
95
|
+
rb_define_const(mSqlite3Open, "MAIN_DB", INT2FIX(SQLITE_OPEN_MAIN_DB));
|
96
|
+
rb_define_const(mSqlite3Open, "TEMP_DB", INT2FIX(SQLITE_OPEN_TEMP_DB));
|
97
|
+
rb_define_const(mSqlite3Open, "TRANSIENT_DB", INT2FIX(SQLITE_OPEN_TRANSIENT_DB));
|
98
|
+
rb_define_const(mSqlite3Open, "MAIN_JOURNAL", INT2FIX(SQLITE_OPEN_MAIN_JOURNAL));
|
99
|
+
rb_define_const(mSqlite3Open, "TEMP_JOURNAL", INT2FIX(SQLITE_OPEN_TEMP_JOURNAL));
|
100
|
+
rb_define_const(mSqlite3Open, "SUBJOURNAL", INT2FIX(SQLITE_OPEN_SUBJOURNAL));
|
101
|
+
rb_define_const(mSqlite3Open, "MASTER_JOURNAL", INT2FIX(SQLITE_OPEN_MASTER_JOURNAL));
|
102
|
+
rb_define_const(mSqlite3Open, "NOMUTEX", INT2FIX(SQLITE_OPEN_NOMUTEX));
|
103
|
+
rb_define_const(mSqlite3Open, "FULLMUTEX", INT2FIX(SQLITE_OPEN_FULLMUTEX));
|
104
|
+
#ifdef SQLITE_OPEN_AUTOPROXY
|
105
|
+
/* SQLITE_VERSION_NUMBER>=3007002 */
|
106
|
+
rb_define_const(mSqlite3Open, "AUTOPROXY", INT2FIX(SQLITE_OPEN_AUTOPROXY));
|
107
|
+
rb_define_const(mSqlite3Open, "SHAREDCACHE", INT2FIX(SQLITE_OPEN_SHAREDCACHE));
|
108
|
+
rb_define_const(mSqlite3Open, "PRIVATECACHE", INT2FIX(SQLITE_OPEN_PRIVATECACHE));
|
109
|
+
rb_define_const(mSqlite3Open, "WAL", INT2FIX(SQLITE_OPEN_WAL));
|
110
|
+
#endif
|
111
|
+
#ifdef SQLITE_OPEN_URI
|
112
|
+
/* SQLITE_VERSION_NUMBER>=3007007 */
|
113
|
+
rb_define_const(mSqlite3Open, "URI", INT2FIX(SQLITE_OPEN_URI));
|
114
|
+
#endif
|
115
|
+
#ifdef SQLITE_OPEN_MEMORY
|
116
|
+
/* SQLITE_VERSION_NUMBER>=3007013 */
|
117
|
+
rb_define_const(mSqlite3Open, "MEMORY", INT2FIX(SQLITE_OPEN_MEMORY));
|
118
|
+
#endif
|
119
|
+
}
|
120
|
+
|
68
121
|
void Init_sqlite3_native()
|
69
122
|
{
|
70
123
|
/*
|
@@ -85,6 +138,7 @@ void Init_sqlite3_native()
|
|
85
138
|
sqlite3_initialize();
|
86
139
|
#endif
|
87
140
|
|
141
|
+
init_sqlite3_constants();
|
88
142
|
init_sqlite3_database();
|
89
143
|
init_sqlite3_statement();
|
90
144
|
#ifdef HAVE_SQLITE3_BACKUP_INIT
|
@@ -92,6 +146,7 @@ void Init_sqlite3_native()
|
|
92
146
|
#endif
|
93
147
|
|
94
148
|
rb_define_singleton_method(mSqlite3, "libversion", libversion, 0);
|
149
|
+
rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0);
|
95
150
|
rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));
|
96
151
|
rb_define_const(mSqlite3, "SQLITE_VERSION_NUMBER", INT2FIX(SQLITE_VERSION_NUMBER));
|
97
152
|
}
|
data/lib/sqlite3.rb
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/sqlite3/database.rb
CHANGED
@@ -98,6 +98,13 @@ in version 2.0.0.
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
# Returns the filename for the database named +db_name+. +db_name+ defaults
|
102
|
+
# to "main". Main return `nil` or an empty string if the database is
|
103
|
+
# temporary or in-memory.
|
104
|
+
def filename db_name = 'main'
|
105
|
+
db_filename db_name
|
106
|
+
end
|
107
|
+
|
101
108
|
# Executes the given SQL statement. If additional parameters are given,
|
102
109
|
# they are treated as bind variables, and are bound to the placeholders in
|
103
110
|
# the query.
|
@@ -113,10 +120,6 @@ in version 2.0.0.
|
|
113
120
|
# See also #execute2, #query, and #execute_batch for additional ways of
|
114
121
|
# executing statements.
|
115
122
|
def execute sql, bind_vars = [], *args, &block
|
116
|
-
# FIXME: This is a terrible hack and should be removed but is required
|
117
|
-
# for older versions of rails
|
118
|
-
hack = Object.const_defined?(:ActiveRecord) && sql =~ /^PRAGMA index_list/
|
119
|
-
|
120
123
|
if bind_vars.nil? || !args.empty?
|
121
124
|
if args.empty?
|
122
125
|
bind_vars = []
|
@@ -147,12 +150,7 @@ Support for bind parameters as *args will be removed in 2.0.0.
|
|
147
150
|
else
|
148
151
|
if @results_as_hash
|
149
152
|
stmt.map { |row|
|
150
|
-
|
151
|
-
|
152
|
-
# FIXME UGH TERRIBLE HACK!
|
153
|
-
h['unique'] = h['unique'].to_s if hack
|
154
|
-
|
155
|
-
h
|
153
|
+
type_translation ? row : ordered_map_for(columns, row)
|
156
154
|
}
|
157
155
|
else
|
158
156
|
stmt.to_a
|
@@ -395,6 +393,9 @@ Support for this will be removed in version 2.0.0.
|
|
395
393
|
|
396
394
|
def finalize
|
397
395
|
super(@ctx)
|
396
|
+
result = @ctx.result
|
397
|
+
@ctx = FunctionProxy.new
|
398
|
+
result
|
398
399
|
end
|
399
400
|
})
|
400
401
|
proxy.ctx = FunctionProxy.new
|
data/lib/sqlite3/pragmas.rb
CHANGED
@@ -13,7 +13,6 @@ module SQLite3
|
|
13
13
|
def get_boolean_pragma( name )
|
14
14
|
get_first_value( "PRAGMA #{name}" ) != "0"
|
15
15
|
end
|
16
|
-
private :get_boolean_pragma
|
17
16
|
|
18
17
|
# Sets the given pragma to the given boolean value. The value itself
|
19
18
|
# may be +true+ or +false+, or any other commonly used string or
|
@@ -39,7 +38,6 @@ module SQLite3
|
|
39
38
|
|
40
39
|
execute( "PRAGMA #{name}=#{mode}" )
|
41
40
|
end
|
42
|
-
private :set_boolean_pragma
|
43
41
|
|
44
42
|
# Requests the given pragma (and parameters), and if the block is given,
|
45
43
|
# each row of the result set will be yielded to it. Otherwise, the results
|
@@ -52,13 +50,11 @@ module SQLite3
|
|
52
50
|
execute( "PRAGMA #{name}( #{args} )", &block )
|
53
51
|
end
|
54
52
|
end
|
55
|
-
private :get_query_pragma
|
56
53
|
|
57
54
|
# Return the value of the given pragma.
|
58
55
|
def get_enum_pragma( name )
|
59
56
|
get_first_value( "PRAGMA #{name}" )
|
60
57
|
end
|
61
|
-
private :get_enum_pragma
|
62
58
|
|
63
59
|
# Set the value of the given pragma to +mode+. The +mode+ parameter must
|
64
60
|
# conform to one of the values in the given +enum+ array. Each entry in
|
@@ -71,20 +67,17 @@ module SQLite3
|
|
71
67
|
"unrecognized #{name} #{mode.inspect}" unless match
|
72
68
|
execute( "PRAGMA #{name}='#{match.first.upcase}'" )
|
73
69
|
end
|
74
|
-
private :set_enum_pragma
|
75
70
|
|
76
71
|
# Returns the value of the given pragma as an integer.
|
77
72
|
def get_int_pragma( name )
|
78
73
|
get_first_value( "PRAGMA #{name}" ).to_i
|
79
74
|
end
|
80
|
-
private :get_int_pragma
|
81
75
|
|
82
76
|
# Set the value of the given pragma to the integer value of the +value+
|
83
77
|
# parameter.
|
84
78
|
def set_int_pragma( name, value )
|
85
79
|
execute( "PRAGMA #{name}=#{value.to_i}" )
|
86
80
|
end
|
87
|
-
private :set_int_pragma
|
88
81
|
|
89
82
|
# The enumeration of valid synchronous modes.
|
90
83
|
SYNCHRONOUS_MODES = [ [ 'full', 2 ], [ 'normal', 1 ], [ 'off', 0 ] ]
|
@@ -92,6 +85,22 @@ module SQLite3
|
|
92
85
|
# The enumeration of valid temp store modes.
|
93
86
|
TEMP_STORE_MODES = [ [ 'default', 0 ], [ 'file', 1 ], [ 'memory', 2 ] ]
|
94
87
|
|
88
|
+
# The enumeration of valid auto vacuum modes.
|
89
|
+
AUTO_VACUUM_MODES = [ [ 'none', 0 ], [ 'full', 1 ], [ 'incremental', 2 ] ]
|
90
|
+
|
91
|
+
# The list of valid journaling modes.
|
92
|
+
JOURNAL_MODES = [ [ 'delete' ], [ 'truncate' ], [ 'persist' ], [ 'memory' ],
|
93
|
+
[ 'wal' ], [ 'off' ] ]
|
94
|
+
|
95
|
+
# The list of valid locking modes.
|
96
|
+
LOCKING_MODES = [ [ 'normal' ], [ 'exclusive' ] ]
|
97
|
+
|
98
|
+
# The list of valid encodings.
|
99
|
+
ENCODINGS = [ [ 'utf-8' ], [ 'utf-16' ], [ 'utf-16le' ], [ 'utf-16be ' ] ]
|
100
|
+
|
101
|
+
# The list of valid WAL checkpoints.
|
102
|
+
WAL_CHECKPOINTS = [ [ 'passive' ], [ 'full' ], [ 'restart' ], [ 'truncate' ] ]
|
103
|
+
|
95
104
|
# Does an integrity check on the database. If the check fails, a
|
96
105
|
# SQLite3::Exception will be raised. Otherwise it
|
97
106
|
# returns silently.
|
@@ -101,28 +110,36 @@ module SQLite3
|
|
101
110
|
end
|
102
111
|
end
|
103
112
|
|
113
|
+
def application_id
|
114
|
+
get_int_pragma "application_id"
|
115
|
+
end
|
116
|
+
|
117
|
+
def application_id=( integer )
|
118
|
+
set_int_pragma "application_id", integer
|
119
|
+
end
|
120
|
+
|
104
121
|
def auto_vacuum
|
105
|
-
|
122
|
+
get_enum_pragma "auto_vacuum"
|
106
123
|
end
|
107
124
|
|
108
125
|
def auto_vacuum=( mode )
|
109
|
-
|
126
|
+
set_enum_pragma "auto_vacuum", mode, AUTO_VACUUM_MODES
|
110
127
|
end
|
111
128
|
|
112
|
-
def
|
113
|
-
|
129
|
+
def automatic_index
|
130
|
+
get_boolean_pragma "automatic_index"
|
114
131
|
end
|
115
132
|
|
116
|
-
def
|
117
|
-
|
133
|
+
def automatic_index=( mode )
|
134
|
+
set_boolean_pragma "automatic_index", mode
|
118
135
|
end
|
119
136
|
|
120
|
-
def
|
121
|
-
get_int_pragma "
|
137
|
+
def busy_timeout
|
138
|
+
get_int_pragma "busy_timeout"
|
122
139
|
end
|
123
140
|
|
124
|
-
def
|
125
|
-
set_int_pragma "
|
141
|
+
def busy_timeout=( milliseconds )
|
142
|
+
set_int_pragma "busy_timeout", milliseconds
|
126
143
|
end
|
127
144
|
|
128
145
|
def cache_size
|
@@ -133,6 +150,58 @@ module SQLite3
|
|
133
150
|
set_int_pragma "cache_size", size
|
134
151
|
end
|
135
152
|
|
153
|
+
def cache_spill
|
154
|
+
get_boolean_pragma "cache_spill"
|
155
|
+
end
|
156
|
+
|
157
|
+
def cache_spill=( mode )
|
158
|
+
set_boolean_pragma "cache_spill", mode
|
159
|
+
end
|
160
|
+
|
161
|
+
def case_sensitive_like=( mode )
|
162
|
+
set_boolean_pragma "case_sensitive_like", mode
|
163
|
+
end
|
164
|
+
|
165
|
+
def cell_size_check
|
166
|
+
get_boolean_pragma "cell_size_check"
|
167
|
+
end
|
168
|
+
|
169
|
+
def cell_size_check=( mode )
|
170
|
+
set_boolean_pragma "cell_size_check", mode
|
171
|
+
end
|
172
|
+
|
173
|
+
def checkpoint_fullfsync
|
174
|
+
get_boolean_pragma "checkpoint_fullfsync"
|
175
|
+
end
|
176
|
+
|
177
|
+
def checkpoint_fullfsync=( mode )
|
178
|
+
set_boolean_pragma "checkpoint_fullfsync", mode
|
179
|
+
end
|
180
|
+
|
181
|
+
def collation_list( &block ) # :yields: row
|
182
|
+
get_query_pragma "collation_list", &block
|
183
|
+
end
|
184
|
+
|
185
|
+
def compile_options( &block ) # :yields: row
|
186
|
+
get_query_pragma "compile_options", &block
|
187
|
+
end
|
188
|
+
|
189
|
+
def count_changes
|
190
|
+
get_boolean_pragma "count_changes"
|
191
|
+
end
|
192
|
+
|
193
|
+
def count_changes=( mode )
|
194
|
+
set_boolean_pragma "count_changes", mode
|
195
|
+
end
|
196
|
+
|
197
|
+
def data_version
|
198
|
+
get_int_pragma "data_version"
|
199
|
+
end
|
200
|
+
|
201
|
+
def database_list( &block ) # :yields: row
|
202
|
+
get_query_pragma "database_list", &block
|
203
|
+
end
|
204
|
+
|
136
205
|
def default_cache_size
|
137
206
|
get_int_pragma "default_cache_size"
|
138
207
|
end
|
@@ -149,14 +218,6 @@ module SQLite3
|
|
149
218
|
set_enum_pragma "default_synchronous", mode, SYNCHRONOUS_MODES
|
150
219
|
end
|
151
220
|
|
152
|
-
def synchronous
|
153
|
-
get_enum_pragma "synchronous"
|
154
|
-
end
|
155
|
-
|
156
|
-
def synchronous=( mode )
|
157
|
-
set_enum_pragma "synchronous", mode, SYNCHRONOUS_MODES
|
158
|
-
end
|
159
|
-
|
160
221
|
def default_temp_store
|
161
222
|
get_enum_pragma "default_temp_store"
|
162
223
|
end
|
@@ -164,13 +225,41 @@ module SQLite3
|
|
164
225
|
def default_temp_store=( mode )
|
165
226
|
set_enum_pragma "default_temp_store", mode, TEMP_STORE_MODES
|
166
227
|
end
|
167
|
-
|
168
|
-
def
|
169
|
-
|
228
|
+
|
229
|
+
def defer_foreign_keys
|
230
|
+
get_boolean_pragma "defer_foreign_keys"
|
170
231
|
end
|
171
232
|
|
172
|
-
def
|
173
|
-
|
233
|
+
def defer_foreign_keys=( mode )
|
234
|
+
set_boolean_pragma "defer_foreign_keys", mode
|
235
|
+
end
|
236
|
+
|
237
|
+
def encoding
|
238
|
+
get_enum_pragma "encoding"
|
239
|
+
end
|
240
|
+
|
241
|
+
def encoding=( mode )
|
242
|
+
set_enum_pragma "encoding", mode, ENCODINGS
|
243
|
+
end
|
244
|
+
|
245
|
+
def foreign_key_check( *table, &block ) # :yields: row
|
246
|
+
get_query_pragma "foreign_key_check", *table, &block
|
247
|
+
end
|
248
|
+
|
249
|
+
def foreign_key_list( table, &block ) # :yields: row
|
250
|
+
get_query_pragma "foreign_key_list", table, &block
|
251
|
+
end
|
252
|
+
|
253
|
+
def foreign_keys
|
254
|
+
get_boolean_pragma "foreign_keys"
|
255
|
+
end
|
256
|
+
|
257
|
+
def foreign_keys=( mode )
|
258
|
+
set_boolean_pragma "foreign_keys", mode
|
259
|
+
end
|
260
|
+
|
261
|
+
def freelist_count
|
262
|
+
get_int_pragma "freelist_count"
|
174
263
|
end
|
175
264
|
|
176
265
|
def full_column_names
|
@@ -181,14 +270,238 @@ module SQLite3
|
|
181
270
|
set_boolean_pragma "full_column_names", mode
|
182
271
|
end
|
183
272
|
|
184
|
-
def
|
185
|
-
get_boolean_pragma "
|
273
|
+
def fullfsync
|
274
|
+
get_boolean_pragma "fullfsync"
|
275
|
+
end
|
276
|
+
|
277
|
+
def fullfsync=( mode )
|
278
|
+
set_boolean_pragma "fullfsync", mode
|
279
|
+
end
|
280
|
+
|
281
|
+
def ignore_check_constraints=( mode )
|
282
|
+
set_boolean_pragma "ignore_check_constraints", mode
|
283
|
+
end
|
284
|
+
|
285
|
+
def incremental_vacuum( pages, &block ) # :yields: row
|
286
|
+
get_query_pragma "incremental_vacuum", pages, &block
|
287
|
+
end
|
288
|
+
|
289
|
+
def index_info( index, &block ) # :yields: row
|
290
|
+
get_query_pragma "index_info", index, &block
|
291
|
+
end
|
292
|
+
|
293
|
+
def index_list( table, &block ) # :yields: row
|
294
|
+
get_query_pragma "index_list", table, &block
|
295
|
+
end
|
296
|
+
|
297
|
+
def index_xinfo( index, &block ) # :yields: row
|
298
|
+
get_query_pragma "index_xinfo", index, &block
|
299
|
+
end
|
300
|
+
|
301
|
+
def integrity_check( *num_errors, &block ) # :yields: row
|
302
|
+
get_query_pragma "integrity_check", *num_errors, &block
|
303
|
+
end
|
304
|
+
|
305
|
+
def journal_mode
|
306
|
+
get_enum_pragma "journal_mode"
|
307
|
+
end
|
308
|
+
|
309
|
+
def journal_mode=( mode )
|
310
|
+
set_enum_pragma "journal_mode", mode, JOURNAL_MODES
|
311
|
+
end
|
312
|
+
|
313
|
+
def journal_size_limit
|
314
|
+
get_int_pragma "journal_size_limit"
|
315
|
+
end
|
316
|
+
|
317
|
+
def journal_size_limit=( size )
|
318
|
+
set_int_pragma "journal_size_limit", size
|
319
|
+
end
|
320
|
+
|
321
|
+
def legacy_file_format
|
322
|
+
get_boolean_pragma "legacy_file_format"
|
323
|
+
end
|
324
|
+
|
325
|
+
def legacy_file_format=( mode )
|
326
|
+
set_boolean_pragma "legacy_file_format", mode
|
327
|
+
end
|
328
|
+
|
329
|
+
def locking_mode
|
330
|
+
get_enum_pragma "locking_mode"
|
331
|
+
end
|
332
|
+
|
333
|
+
def locking_mode=( mode )
|
334
|
+
set_enum_pragma "locking_mode", mode, LOCKING_MODES
|
335
|
+
end
|
336
|
+
|
337
|
+
def max_page_count
|
338
|
+
get_int_pragma "max_page_count"
|
339
|
+
end
|
340
|
+
|
341
|
+
def max_page_count=( size )
|
342
|
+
set_int_pragma "max_page_count", size
|
343
|
+
end
|
344
|
+
|
345
|
+
def mmap_size
|
346
|
+
get_int_pragma "mmap_size"
|
347
|
+
end
|
348
|
+
|
349
|
+
def mmap_size=( size )
|
350
|
+
set_int_pragma "mmap_size", size
|
351
|
+
end
|
352
|
+
|
353
|
+
def page_count
|
354
|
+
get_int_pragma "page_count"
|
355
|
+
end
|
356
|
+
|
357
|
+
def page_size
|
358
|
+
get_int_pragma "page_size"
|
359
|
+
end
|
360
|
+
|
361
|
+
def page_size=( size )
|
362
|
+
set_int_pragma "page_size", size
|
186
363
|
end
|
187
364
|
|
188
365
|
def parser_trace=( mode )
|
189
366
|
set_boolean_pragma "parser_trace", mode
|
190
367
|
end
|
191
368
|
|
369
|
+
def query_only
|
370
|
+
get_boolean_pragma "query_only"
|
371
|
+
end
|
372
|
+
|
373
|
+
def query_only=( mode )
|
374
|
+
set_boolean_pragma "query_only", mode
|
375
|
+
end
|
376
|
+
|
377
|
+
def quick_check( *num_errors, &block ) # :yields: row
|
378
|
+
get_query_pragma "quick_check", *num_errors, &block
|
379
|
+
end
|
380
|
+
|
381
|
+
def read_uncommitted
|
382
|
+
get_boolean_pragma "read_uncommitted"
|
383
|
+
end
|
384
|
+
|
385
|
+
def read_uncommitted=( mode )
|
386
|
+
set_boolean_pragma "read_uncommitted", mode
|
387
|
+
end
|
388
|
+
|
389
|
+
def recursive_triggers
|
390
|
+
get_boolean_pragma "recursive_triggers"
|
391
|
+
end
|
392
|
+
|
393
|
+
def recursive_triggers=( mode )
|
394
|
+
set_boolean_pragma "recursive_triggers", mode
|
395
|
+
end
|
396
|
+
|
397
|
+
def reverse_unordered_selects
|
398
|
+
get_boolean_pragma "reverse_unordered_selects"
|
399
|
+
end
|
400
|
+
|
401
|
+
def reverse_unordered_selects=( mode )
|
402
|
+
set_boolean_pragma "reverse_unordered_selects", mode
|
403
|
+
end
|
404
|
+
|
405
|
+
def schema_cookie
|
406
|
+
get_int_pragma "schema_cookie"
|
407
|
+
end
|
408
|
+
|
409
|
+
def schema_cookie=( cookie )
|
410
|
+
set_int_pragma "schema_cookie", cookie
|
411
|
+
end
|
412
|
+
|
413
|
+
def schema_version
|
414
|
+
get_int_pragma "schema_version"
|
415
|
+
end
|
416
|
+
|
417
|
+
def schema_version=( version )
|
418
|
+
set_int_pragma "schema_version", version
|
419
|
+
end
|
420
|
+
|
421
|
+
def secure_delete
|
422
|
+
get_boolean_pragma "secure_delete"
|
423
|
+
end
|
424
|
+
|
425
|
+
def secure_delete=( mode )
|
426
|
+
set_boolean_pragma "secure_delete", mode
|
427
|
+
end
|
428
|
+
|
429
|
+
def short_column_names
|
430
|
+
get_boolean_pragma "short_column_names"
|
431
|
+
end
|
432
|
+
|
433
|
+
def short_column_names=( mode )
|
434
|
+
set_boolean_pragma "short_column_names", mode
|
435
|
+
end
|
436
|
+
|
437
|
+
def shrink_memory
|
438
|
+
execute( "PRAGMA shrink_memory" )
|
439
|
+
end
|
440
|
+
|
441
|
+
def soft_heap_limit
|
442
|
+
get_int_pragma "soft_heap_limit"
|
443
|
+
end
|
444
|
+
|
445
|
+
def soft_heap_limit=( mode )
|
446
|
+
set_int_pragma "soft_heap_limit", mode
|
447
|
+
end
|
448
|
+
|
449
|
+
def stats( &block ) # :yields: row
|
450
|
+
get_query_pragma "stats", &block
|
451
|
+
end
|
452
|
+
|
453
|
+
def synchronous
|
454
|
+
get_enum_pragma "synchronous"
|
455
|
+
end
|
456
|
+
|
457
|
+
def synchronous=( mode )
|
458
|
+
set_enum_pragma "synchronous", mode, SYNCHRONOUS_MODES
|
459
|
+
end
|
460
|
+
|
461
|
+
def temp_store
|
462
|
+
get_enum_pragma "temp_store"
|
463
|
+
end
|
464
|
+
|
465
|
+
def temp_store=( mode )
|
466
|
+
set_enum_pragma "temp_store", mode, TEMP_STORE_MODES
|
467
|
+
end
|
468
|
+
|
469
|
+
def threads
|
470
|
+
get_int_pragma "threads"
|
471
|
+
end
|
472
|
+
|
473
|
+
def threads=( count )
|
474
|
+
set_int_pragma "threads", count
|
475
|
+
end
|
476
|
+
|
477
|
+
def user_cookie
|
478
|
+
get_int_pragma "user_cookie"
|
479
|
+
end
|
480
|
+
|
481
|
+
def user_cookie=( cookie )
|
482
|
+
set_int_pragma "user_cookie", cookie
|
483
|
+
end
|
484
|
+
|
485
|
+
def user_version
|
486
|
+
get_int_pragma "user_version"
|
487
|
+
end
|
488
|
+
|
489
|
+
def user_version=( version )
|
490
|
+
set_int_pragma "user_version", version
|
491
|
+
end
|
492
|
+
|
493
|
+
def vdbe_addoptrace=( mode )
|
494
|
+
set_boolean_pragma "vdbe_addoptrace", mode
|
495
|
+
end
|
496
|
+
|
497
|
+
def vdbe_debug=( mode )
|
498
|
+
set_boolean_pragma "vdbe_debug", mode
|
499
|
+
end
|
500
|
+
|
501
|
+
def vdbe_listing=( mode )
|
502
|
+
set_boolean_pragma "vdbe_listing", mode
|
503
|
+
end
|
504
|
+
|
192
505
|
def vdbe_trace
|
193
506
|
get_boolean_pragma "vdbe_trace"
|
194
507
|
end
|
@@ -197,20 +510,24 @@ module SQLite3
|
|
197
510
|
set_boolean_pragma "vdbe_trace", mode
|
198
511
|
end
|
199
512
|
|
200
|
-
def
|
201
|
-
|
513
|
+
def wal_autocheckpoint
|
514
|
+
get_int_pragma "wal_autocheckpoint"
|
202
515
|
end
|
203
516
|
|
204
|
-
def
|
205
|
-
|
517
|
+
def wal_autocheckpoint=( mode )
|
518
|
+
set_int_pragma "wal_autocheckpoint", mode
|
206
519
|
end
|
207
520
|
|
208
|
-
def
|
209
|
-
|
521
|
+
def wal_checkpoint
|
522
|
+
get_enum_pragma "wal_checkpoint"
|
210
523
|
end
|
211
524
|
|
212
|
-
def
|
213
|
-
|
525
|
+
def wal_checkpoint=( mode )
|
526
|
+
set_enum_pragma "wal_checkpoint", mode, WAL_CHECKPOINTS
|
527
|
+
end
|
528
|
+
|
529
|
+
def writable_schema=( mode )
|
530
|
+
set_boolean_pragma "writable_schema", mode
|
214
531
|
end
|
215
532
|
|
216
533
|
###
|
data/lib/sqlite3/version.rb
CHANGED
data/tasks/gem.rake
CHANGED
@@ -25,7 +25,7 @@ HOE = Hoe.spec 'sqlite3' do
|
|
25
25
|
spec_extras[:extensions] = ["ext/sqlite3/extconf.rb"]
|
26
26
|
|
27
27
|
extra_dev_deps << ['rake-compiler', "~> 0.9.3"]
|
28
|
-
extra_dev_deps << ['rake-compiler-dock', "~> 0.
|
28
|
+
extra_dev_deps << ['rake-compiler-dock', "~> 0.5.2"]
|
29
29
|
extra_dev_deps << ["mini_portile", "~> 0.6.2"]
|
30
30
|
extra_dev_deps << ["minitest", "~> 5.0"]
|
31
31
|
extra_dev_deps << ["hoe-bundler", "~> 1.0"]
|
data/test/test_database.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
module SQLite3
|
4
5
|
class TestDatabase < SQLite3::TestCase
|
@@ -6,12 +7,43 @@ module SQLite3
|
|
6
7
|
|
7
8
|
def setup
|
8
9
|
@db = SQLite3::Database.new(':memory:')
|
10
|
+
super
|
9
11
|
end
|
10
12
|
|
11
13
|
def test_segv
|
12
14
|
assert_raises(TypeError) { SQLite3::Database.new 1 }
|
13
15
|
end
|
14
16
|
|
17
|
+
def test_db_filename
|
18
|
+
tf = nil
|
19
|
+
assert_equal '', @db.filename('main')
|
20
|
+
tf = Tempfile.new 'thing'
|
21
|
+
@db = SQLite3::Database.new tf.path
|
22
|
+
assert_equal tf.path, @db.filename('main')
|
23
|
+
ensure
|
24
|
+
tf.unlink if tf
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_filename
|
28
|
+
tf = nil
|
29
|
+
assert_equal '', @db.filename
|
30
|
+
tf = Tempfile.new 'thing'
|
31
|
+
@db = SQLite3::Database.new tf.path
|
32
|
+
assert_equal tf.path, @db.filename
|
33
|
+
ensure
|
34
|
+
tf.unlink if tf
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_filename_with_attachment
|
38
|
+
tf = nil
|
39
|
+
assert_equal '', @db.filename
|
40
|
+
tf = Tempfile.new 'thing'
|
41
|
+
@db.execute "ATTACH DATABASE '#{tf.path}' AS 'testing'"
|
42
|
+
assert_equal tf.path, @db.filename('testing')
|
43
|
+
ensure
|
44
|
+
tf.unlink if tf
|
45
|
+
end
|
46
|
+
|
15
47
|
def test_bignum
|
16
48
|
num = 4907021672125087844
|
17
49
|
db.execute 'CREATE TABLE "employees" ("token" integer(8), "name" varchar(20) NOT NULL)'
|
@@ -109,6 +141,18 @@ module SQLite3
|
|
109
141
|
assert thing.closed?
|
110
142
|
end
|
111
143
|
|
144
|
+
def test_block_closes_self_even_raised
|
145
|
+
thing = nil
|
146
|
+
begin
|
147
|
+
SQLite3::Database.new(':memory:') do |db|
|
148
|
+
thing = db
|
149
|
+
raise
|
150
|
+
end
|
151
|
+
rescue
|
152
|
+
end
|
153
|
+
assert thing.closed?
|
154
|
+
end
|
155
|
+
|
112
156
|
def test_prepare
|
113
157
|
db = SQLite3::Database.new(':memory:')
|
114
158
|
stmt = db.prepare('select "hello world"')
|
@@ -261,12 +305,30 @@ module SQLite3
|
|
261
305
|
end
|
262
306
|
|
263
307
|
def test_function_return_types
|
264
|
-
[10, 2.2, nil, "foo"].each do |thing|
|
308
|
+
[10, 2.2, nil, "foo", Blob.new("foo\0bar")].each do |thing|
|
265
309
|
@db.define_function("hello") { |a| thing }
|
266
310
|
assert_equal [thing], @db.execute("select hello('world')").first
|
267
311
|
end
|
268
312
|
end
|
269
313
|
|
314
|
+
def test_function_gc_segfault
|
315
|
+
@db.create_function("bug", -1) { |func, *values| func.result = values.join }
|
316
|
+
# With a lot of data and a lot of threads, try to induce a GC segfault.
|
317
|
+
params = Array.new(127, "?" * 28000)
|
318
|
+
proc = Proc.new {
|
319
|
+
db.execute("select bug(#{Array.new(params.length, "?").join(",")})", params)
|
320
|
+
}
|
321
|
+
m = Mutex.new
|
322
|
+
30.times.map { Thread.new { m.synchronize { proc.call } } }.each(&:join)
|
323
|
+
end
|
324
|
+
|
325
|
+
def test_function_return_type_round_trip
|
326
|
+
[10, 2.2, nil, "foo", Blob.new("foo\0bar")].each do |thing|
|
327
|
+
@db.define_function("hello") { |a| a }
|
328
|
+
assert_equal [thing], @db.execute("select hello(hello(?))", [thing]).first
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
270
332
|
def test_define_function_closed
|
271
333
|
@db.close
|
272
334
|
assert_raise(SQLite3::Exception) do
|
@@ -3,7 +3,7 @@ require 'helper'
|
|
3
3
|
module SQLite3
|
4
4
|
class TestDatabaseReadonly < SQLite3::TestCase
|
5
5
|
def setup
|
6
|
-
File.unlink 'test-readonly.db' if File.
|
6
|
+
File.unlink 'test-readonly.db' if File.exist?('test-readonly.db')
|
7
7
|
@db = SQLite3::Database.new('test-readonly.db')
|
8
8
|
@db.execute("CREATE TABLE foos (id integer)")
|
9
9
|
@db.close
|
@@ -11,7 +11,7 @@ module SQLite3
|
|
11
11
|
|
12
12
|
def teardown
|
13
13
|
@db.close unless @db.closed?
|
14
|
-
File.unlink 'test-readonly.db'
|
14
|
+
File.unlink 'test-readonly.db' if File.exist?('test-readonly.db')
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_open_readonly_database
|
@@ -19,6 +19,13 @@ module SQLite3
|
|
19
19
|
assert @db.readonly?
|
20
20
|
end
|
21
21
|
|
22
|
+
def test_open_readonly_not_exists_database
|
23
|
+
File.unlink 'test-readonly.db'
|
24
|
+
assert_raise(SQLite3::CantOpenException) do
|
25
|
+
@db = SQLite3::Database.new('test-readonly.db', :readonly => true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
22
29
|
def test_insert_readonly_database
|
23
30
|
@db = SQLite3::Database.new('test-readonly.db', :readonly => true)
|
24
31
|
assert_raise(SQLite3::ReadOnlyException) do
|
data/test/test_integration.rb
CHANGED
@@ -499,6 +499,10 @@ class TC_Database_Integration < SQLite3::TestCase
|
|
499
499
|
|
500
500
|
value = @db.get_first_value( "select accumulate(a) from foo" )
|
501
501
|
assert_equal 6, value
|
502
|
+
|
503
|
+
# calling #get_first_value twice don't add up to the latest result
|
504
|
+
value = @db.get_first_value( "select accumulate(a) from foo" )
|
505
|
+
assert_equal 6, value
|
502
506
|
end
|
503
507
|
|
504
508
|
def test_create_aggregate_with_block
|
data/test/test_sqlite3.rb
CHANGED
@@ -5,5 +5,17 @@ module SQLite3
|
|
5
5
|
def test_libversion
|
6
6
|
assert_not_nil SQLite3.libversion
|
7
7
|
end
|
8
|
+
|
9
|
+
def test_threadsafe
|
10
|
+
assert_not_nil SQLite3.threadsafe
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_threadsafe?
|
14
|
+
if SQLite3.threadsafe > 0
|
15
|
+
assert SQLite3.threadsafe?
|
16
|
+
else
|
17
|
+
refute SQLite3.threadsafe?
|
18
|
+
end
|
19
|
+
end
|
8
20
|
end
|
9
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqlite3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.12
|
5
5
|
platform: x86-mingw32
|
6
6
|
authors:
|
7
7
|
- Jamis Buck
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2016-10-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '5.
|
21
|
+
version: '5.9'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '5.
|
28
|
+
version: '5.9'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rdoc
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,14 +60,14 @@ dependencies:
|
|
60
60
|
requirements:
|
61
61
|
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 0.
|
63
|
+
version: 0.5.2
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
68
|
- - "~>"
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version: 0.
|
70
|
+
version: 0.5.2
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: mini_portile
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,14 +102,14 @@ dependencies:
|
|
102
102
|
requirements:
|
103
103
|
- - "~>"
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version: '3.
|
105
|
+
version: '3.15'
|
106
106
|
type: :development
|
107
107
|
prerelease: false
|
108
108
|
version_requirements: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
110
|
- - "~>"
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version: '3.
|
112
|
+
version: '3.15'
|
113
113
|
description: |-
|
114
114
|
This module allows Ruby programs to interface with the SQLite3
|
115
115
|
database engine (http://www.sqlite.org). You must have the
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/sqlite3/2.0/sqlite3_native.so
|
161
161
|
- lib/sqlite3/2.1/sqlite3_native.so
|
162
162
|
- lib/sqlite3/2.2/sqlite3_native.so
|
163
|
+
- lib/sqlite3/2.3/sqlite3_native.so
|
163
164
|
- lib/sqlite3/constants.rb
|
164
165
|
- lib/sqlite3/database.rb
|
165
166
|
- lib/sqlite3/errors.rb
|
@@ -212,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
213
|
version: 1.3.5
|
213
214
|
requirements: []
|
214
215
|
rubyforge_project:
|
215
|
-
rubygems_version: 2.
|
216
|
+
rubygems_version: 2.5.1
|
216
217
|
signing_key:
|
217
218
|
specification_version: 4
|
218
219
|
summary: This module allows Ruby programs to interface with the SQLite3 database engine
|