sqlite3 1.4.2 → 1.7.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/{API_CHANGES.rdoc → API_CHANGES.md} +3 -4
- data/CHANGELOG.md +641 -0
- data/CONTRIBUTING.md +34 -0
- data/FAQ.md +431 -0
- data/Gemfile +7 -14
- data/INSTALLATION.md +259 -0
- data/LICENSE-DEPENDENCIES +20 -0
- data/README.md +110 -0
- data/dependencies.yml +14 -0
- data/ext/sqlite3/aggregator.c +10 -10
- data/ext/sqlite3/backup.c +26 -13
- data/ext/sqlite3/database.c +89 -38
- data/ext/sqlite3/database.h +2 -0
- data/ext/sqlite3/extconf.rb +269 -84
- data/ext/sqlite3/sqlite3.c +5 -2
- data/ext/sqlite3/sqlite3_ruby.h +5 -2
- data/ext/sqlite3/statement.c +37 -28
- data/lib/sqlite3/constants.rb +1 -1
- data/lib/sqlite3/database.rb +55 -30
- data/lib/sqlite3/pragmas.rb +13 -6
- data/lib/sqlite3/resultset.rb +4 -12
- data/lib/sqlite3/statement.rb +2 -1
- data/lib/sqlite3/translator.rb +2 -3
- data/lib/sqlite3/version.rb +3 -5
- data/ports/archives/sqlite-autoconf-3450100.tar.gz +0 -0
- data/test/helper.rb +9 -0
- data/test/test_database.rb +182 -17
- data/test/test_deprecated.rb +10 -5
- data/test/test_encoding.rb +10 -0
- data/test/test_integration_resultset.rb +2 -2
- data/test/test_integration_statement.rb +2 -2
- data/test/test_pragmas.rb +22 -0
- data/test/test_result_set.rb +18 -8
- data/test/test_sqlite3.rb +9 -0
- data/test/test_statement.rb +28 -1
- data/test/test_statement_execute.rb +4 -0
- metadata +36 -144
- data/.travis.yml +0 -33
- data/CHANGELOG.rdoc +0 -318
- data/Manifest.txt +0 -60
- data/README.rdoc +0 -118
- data/Rakefile +0 -8
- data/appveyor.yml +0 -36
- data/faq/faq.rb +0 -145
- data/faq/faq.yml +0 -426
- data/rakelib/faq.rake +0 -9
- data/rakelib/gem.rake +0 -40
- data/rakelib/native.rake +0 -56
- data/rakelib/vendor_sqlite3.rake +0 -97
- data/setup.rb +0 -1333
data/ext/sqlite3/database.c
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
#include <sqlite3_ruby.h>
|
2
2
|
#include <aggregator.h>
|
3
3
|
|
4
|
+
#ifdef _MSC_VER
|
5
|
+
#pragma warning( push )
|
6
|
+
#pragma warning( disable : 4028 )
|
7
|
+
#endif
|
8
|
+
|
4
9
|
#define REQUIRE_OPEN_DB(_ctxt) \
|
5
10
|
if(!_ctxt->db) \
|
6
11
|
rb_raise(rb_path2class("SQLite3::Exception"), "cannot use a closed database");
|
@@ -16,37 +21,61 @@ static void deallocate(void * ctx)
|
|
16
21
|
xfree(c);
|
17
22
|
}
|
18
23
|
|
24
|
+
static size_t database_memsize(const void *ctx)
|
25
|
+
{
|
26
|
+
const sqlite3RubyPtr c = (const sqlite3RubyPtr)ctx;
|
27
|
+
// NB: can't account for ctx->db because the type is incomplete.
|
28
|
+
return sizeof(*c);
|
29
|
+
}
|
30
|
+
|
31
|
+
static const rb_data_type_t database_type = {
|
32
|
+
"SQLite3::Backup",
|
33
|
+
{
|
34
|
+
NULL,
|
35
|
+
deallocate,
|
36
|
+
database_memsize,
|
37
|
+
},
|
38
|
+
0,
|
39
|
+
0,
|
40
|
+
RUBY_TYPED_WB_PROTECTED, // Not freed immediately because the dfree function do IOs.
|
41
|
+
};
|
42
|
+
|
19
43
|
static VALUE allocate(VALUE klass)
|
20
44
|
{
|
21
|
-
sqlite3RubyPtr ctx
|
22
|
-
return
|
45
|
+
sqlite3RubyPtr ctx;
|
46
|
+
return TypedData_Make_Struct(klass, sqlite3Ruby, &database_type, ctx);
|
23
47
|
}
|
24
48
|
|
25
49
|
static char *
|
26
50
|
utf16_string_value_ptr(VALUE str)
|
27
51
|
{
|
28
52
|
StringValue(str);
|
29
|
-
rb_str_buf_cat(str, "\x00",
|
53
|
+
rb_str_buf_cat(str, "\x00\x00", 2L);
|
30
54
|
return RSTRING_PTR(str);
|
31
55
|
}
|
32
56
|
|
33
57
|
static VALUE sqlite3_rb_close(VALUE self);
|
34
58
|
|
59
|
+
sqlite3RubyPtr sqlite3_database_unwrap(VALUE database){
|
60
|
+
sqlite3RubyPtr ctx;
|
61
|
+
TypedData_Get_Struct(database, sqlite3Ruby, &database_type, ctx);
|
62
|
+
return ctx;
|
63
|
+
}
|
64
|
+
|
35
65
|
static VALUE rb_sqlite3_open_v2(VALUE self, VALUE file, VALUE mode, VALUE zvfs)
|
36
66
|
{
|
37
67
|
sqlite3RubyPtr ctx;
|
38
|
-
VALUE flags;
|
39
68
|
int status;
|
40
69
|
|
41
|
-
|
70
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
42
71
|
|
43
72
|
#if defined TAINTING_SUPPORT
|
44
|
-
#if defined StringValueCStr
|
73
|
+
# if defined StringValueCStr
|
45
74
|
StringValuePtr(file);
|
46
75
|
rb_check_safe_obj(file);
|
47
|
-
#else
|
76
|
+
# else
|
48
77
|
Check_SafeStr(file);
|
49
|
-
#endif
|
78
|
+
# endif
|
50
79
|
#endif
|
51
80
|
|
52
81
|
status = sqlite3_open_v2(
|
@@ -61,6 +90,23 @@ static VALUE rb_sqlite3_open_v2(VALUE self, VALUE file, VALUE mode, VALUE zvfs)
|
|
61
90
|
return self;
|
62
91
|
}
|
63
92
|
|
93
|
+
static VALUE rb_sqlite3_disable_quirk_mode(VALUE self)
|
94
|
+
{
|
95
|
+
#if defined SQLITE_DBCONFIG_DQS_DDL
|
96
|
+
sqlite3RubyPtr ctx;
|
97
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
98
|
+
|
99
|
+
if(!ctx->db) return Qfalse;
|
100
|
+
|
101
|
+
sqlite3_db_config(ctx->db, SQLITE_DBCONFIG_DQS_DDL, 0, (void*)0);
|
102
|
+
sqlite3_db_config(ctx->db, SQLITE_DBCONFIG_DQS_DML, 0, (void*)0);
|
103
|
+
|
104
|
+
return Qtrue;
|
105
|
+
#else
|
106
|
+
return Qfalse;
|
107
|
+
#endif
|
108
|
+
}
|
109
|
+
|
64
110
|
/* call-seq: db.close
|
65
111
|
*
|
66
112
|
* Closes this database.
|
@@ -69,7 +115,7 @@ static VALUE sqlite3_rb_close(VALUE self)
|
|
69
115
|
{
|
70
116
|
sqlite3RubyPtr ctx;
|
71
117
|
sqlite3 * db;
|
72
|
-
|
118
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
73
119
|
|
74
120
|
db = ctx->db;
|
75
121
|
CHECK(db, sqlite3_close(ctx->db));
|
@@ -88,7 +134,7 @@ static VALUE sqlite3_rb_close(VALUE self)
|
|
88
134
|
static VALUE closed_p(VALUE self)
|
89
135
|
{
|
90
136
|
sqlite3RubyPtr ctx;
|
91
|
-
|
137
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
92
138
|
|
93
139
|
if(!ctx->db) return Qtrue;
|
94
140
|
|
@@ -103,10 +149,10 @@ static VALUE closed_p(VALUE self)
|
|
103
149
|
static VALUE total_changes(VALUE self)
|
104
150
|
{
|
105
151
|
sqlite3RubyPtr ctx;
|
106
|
-
|
152
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
107
153
|
REQUIRE_OPEN_DB(ctx);
|
108
154
|
|
109
|
-
return INT2NUM(
|
155
|
+
return INT2NUM(sqlite3_total_changes(ctx->db));
|
110
156
|
}
|
111
157
|
|
112
158
|
static void tracefunc(void * data, const char *sql)
|
@@ -129,7 +175,7 @@ static VALUE trace(int argc, VALUE *argv, VALUE self)
|
|
129
175
|
sqlite3RubyPtr ctx;
|
130
176
|
VALUE block;
|
131
177
|
|
132
|
-
|
178
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
133
179
|
REQUIRE_OPEN_DB(ctx);
|
134
180
|
|
135
181
|
rb_scan_args(argc, argv, "01", &block);
|
@@ -147,7 +193,7 @@ static int rb_sqlite3_busy_handler(void * ctx, int count)
|
|
147
193
|
{
|
148
194
|
VALUE self = (VALUE)(ctx);
|
149
195
|
VALUE handle = rb_iv_get(self, "@busy_handler");
|
150
|
-
VALUE result = rb_funcall(handle, rb_intern("call"), 1, INT2NUM(
|
196
|
+
VALUE result = rb_funcall(handle, rb_intern("call"), 1, INT2NUM(count));
|
151
197
|
|
152
198
|
if(Qfalse == result) return 0;
|
153
199
|
|
@@ -174,7 +220,7 @@ static VALUE busy_handler(int argc, VALUE *argv, VALUE self)
|
|
174
220
|
VALUE block;
|
175
221
|
int status;
|
176
222
|
|
177
|
-
|
223
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
178
224
|
REQUIRE_OPEN_DB(ctx);
|
179
225
|
|
180
226
|
rb_scan_args(argc, argv, "01", &block);
|
@@ -199,7 +245,7 @@ static VALUE busy_handler(int argc, VALUE *argv, VALUE self)
|
|
199
245
|
static VALUE last_insert_row_id(VALUE self)
|
200
246
|
{
|
201
247
|
sqlite3RubyPtr ctx;
|
202
|
-
|
248
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
203
249
|
REQUIRE_OPEN_DB(ctx);
|
204
250
|
|
205
251
|
return LL2NUM(sqlite3_last_insert_rowid(ctx->db));
|
@@ -319,7 +365,7 @@ static VALUE define_function_with_flags(VALUE self, VALUE name, VALUE flags)
|
|
319
365
|
VALUE block;
|
320
366
|
int status;
|
321
367
|
|
322
|
-
|
368
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
323
369
|
REQUIRE_OPEN_DB(ctx);
|
324
370
|
|
325
371
|
block = rb_block_proc();
|
@@ -359,7 +405,7 @@ static VALUE define_function(VALUE self, VALUE name)
|
|
359
405
|
static VALUE interrupt(VALUE self)
|
360
406
|
{
|
361
407
|
sqlite3RubyPtr ctx;
|
362
|
-
|
408
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
363
409
|
REQUIRE_OPEN_DB(ctx);
|
364
410
|
|
365
411
|
sqlite3_interrupt(ctx->db);
|
@@ -375,7 +421,7 @@ static VALUE interrupt(VALUE self)
|
|
375
421
|
static VALUE errmsg(VALUE self)
|
376
422
|
{
|
377
423
|
sqlite3RubyPtr ctx;
|
378
|
-
|
424
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
379
425
|
REQUIRE_OPEN_DB(ctx);
|
380
426
|
|
381
427
|
return rb_str_new2(sqlite3_errmsg(ctx->db));
|
@@ -389,10 +435,10 @@ static VALUE errmsg(VALUE self)
|
|
389
435
|
static VALUE errcode_(VALUE self)
|
390
436
|
{
|
391
437
|
sqlite3RubyPtr ctx;
|
392
|
-
|
438
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
393
439
|
REQUIRE_OPEN_DB(ctx);
|
394
440
|
|
395
|
-
return INT2NUM(
|
441
|
+
return INT2NUM(sqlite3_errcode(ctx->db));
|
396
442
|
}
|
397
443
|
|
398
444
|
/* call-seq: complete?(sql)
|
@@ -417,7 +463,7 @@ static VALUE complete_p(VALUE UNUSED(self), VALUE sql)
|
|
417
463
|
static VALUE changes(VALUE self)
|
418
464
|
{
|
419
465
|
sqlite3RubyPtr ctx;
|
420
|
-
|
466
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
421
467
|
REQUIRE_OPEN_DB(ctx);
|
422
468
|
|
423
469
|
return INT2NUM(sqlite3_changes(ctx->db));
|
@@ -462,7 +508,7 @@ static VALUE set_authorizer(VALUE self, VALUE authorizer)
|
|
462
508
|
sqlite3RubyPtr ctx;
|
463
509
|
int status;
|
464
510
|
|
465
|
-
|
511
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
466
512
|
REQUIRE_OPEN_DB(ctx);
|
467
513
|
|
468
514
|
status = sqlite3_set_authorizer(
|
@@ -489,7 +535,7 @@ static VALUE set_authorizer(VALUE self, VALUE authorizer)
|
|
489
535
|
static VALUE set_busy_timeout(VALUE self, VALUE timeout)
|
490
536
|
{
|
491
537
|
sqlite3RubyPtr ctx;
|
492
|
-
|
538
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
493
539
|
REQUIRE_OPEN_DB(ctx);
|
494
540
|
|
495
541
|
CHECK(ctx->db, sqlite3_busy_timeout(ctx->db, (int)NUM2INT(timeout)));
|
@@ -505,7 +551,7 @@ static VALUE set_busy_timeout(VALUE self, VALUE timeout)
|
|
505
551
|
static VALUE set_extended_result_codes(VALUE self, VALUE enable)
|
506
552
|
{
|
507
553
|
sqlite3RubyPtr ctx;
|
508
|
-
|
554
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
509
555
|
REQUIRE_OPEN_DB(ctx);
|
510
556
|
|
511
557
|
CHECK(ctx->db, sqlite3_extended_result_codes(ctx->db, RTEST(enable) ? 1 : 0));
|
@@ -550,7 +596,7 @@ int rb_comparator_func(void * ctx, int a_len, const void * a, int b_len, const v
|
|
550
596
|
static VALUE collation(VALUE self, VALUE name, VALUE comparator)
|
551
597
|
{
|
552
598
|
sqlite3RubyPtr ctx;
|
553
|
-
|
599
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
554
600
|
REQUIRE_OPEN_DB(ctx);
|
555
601
|
|
556
602
|
CHECK(ctx->db, sqlite3_create_collation(
|
@@ -579,10 +625,10 @@ static VALUE load_extension(VALUE self, VALUE file)
|
|
579
625
|
int status;
|
580
626
|
char *errMsg;
|
581
627
|
VALUE errexp;
|
582
|
-
|
628
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
583
629
|
REQUIRE_OPEN_DB(ctx);
|
584
630
|
|
585
|
-
status = sqlite3_load_extension(ctx->db,
|
631
|
+
status = sqlite3_load_extension(ctx->db, StringValuePtr(file), 0, &errMsg);
|
586
632
|
if (status != SQLITE_OK)
|
587
633
|
{
|
588
634
|
errexp = rb_exc_new2(rb_eRuntimeError, errMsg);
|
@@ -603,7 +649,7 @@ static VALUE enable_load_extension(VALUE self, VALUE onoff)
|
|
603
649
|
{
|
604
650
|
sqlite3RubyPtr ctx;
|
605
651
|
int onoffparam;
|
606
|
-
|
652
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
607
653
|
REQUIRE_OPEN_DB(ctx);
|
608
654
|
|
609
655
|
if (Qtrue == onoff) {
|
@@ -640,7 +686,7 @@ static VALUE db_encoding(VALUE self)
|
|
640
686
|
sqlite3RubyPtr ctx;
|
641
687
|
VALUE enc;
|
642
688
|
|
643
|
-
|
689
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
644
690
|
REQUIRE_OPEN_DB(ctx);
|
645
691
|
|
646
692
|
enc = rb_iv_get(self, "@encoding");
|
@@ -660,7 +706,7 @@ static VALUE db_encoding(VALUE self)
|
|
660
706
|
static VALUE transaction_active_p(VALUE self)
|
661
707
|
{
|
662
708
|
sqlite3RubyPtr ctx;
|
663
|
-
|
709
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
664
710
|
REQUIRE_OPEN_DB(ctx);
|
665
711
|
|
666
712
|
return sqlite3_get_autocommit(ctx->db) ? Qfalse : Qtrue;
|
@@ -705,7 +751,7 @@ static int regular_callback_function(VALUE callback_ary, int count, char **data,
|
|
705
751
|
|
706
752
|
/* Is invoked by calling db.execute_batch2(sql, &block)
|
707
753
|
*
|
708
|
-
* Executes all
|
754
|
+
* Executes all statements in a given string separated by semicolons.
|
709
755
|
* If a query is made, all values returned are strings
|
710
756
|
* (except for 'NULL' values which return nil),
|
711
757
|
* so the user may parse values with a block.
|
@@ -719,13 +765,13 @@ static VALUE exec_batch(VALUE self, VALUE sql, VALUE results_as_hash)
|
|
719
765
|
char *errMsg;
|
720
766
|
VALUE errexp;
|
721
767
|
|
722
|
-
|
768
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
723
769
|
REQUIRE_OPEN_DB(ctx);
|
724
770
|
|
725
771
|
if(results_as_hash == Qtrue) {
|
726
|
-
status = sqlite3_exec(ctx->db, StringValuePtr(sql), hash_callback_function, callback_ary, &errMsg);
|
772
|
+
status = sqlite3_exec(ctx->db, StringValuePtr(sql), (sqlite3_callback)hash_callback_function, (void*)callback_ary, &errMsg);
|
727
773
|
} else {
|
728
|
-
status = sqlite3_exec(ctx->db, StringValuePtr(sql), regular_callback_function, callback_ary, &errMsg);
|
774
|
+
status = sqlite3_exec(ctx->db, StringValuePtr(sql), (sqlite3_callback)regular_callback_function, (void*)callback_ary, &errMsg);
|
729
775
|
}
|
730
776
|
|
731
777
|
if (status != SQLITE_OK)
|
@@ -747,7 +793,7 @@ static VALUE db_filename(VALUE self, VALUE db_name)
|
|
747
793
|
{
|
748
794
|
sqlite3RubyPtr ctx;
|
749
795
|
const char * fname;
|
750
|
-
|
796
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
751
797
|
REQUIRE_OPEN_DB(ctx);
|
752
798
|
|
753
799
|
fname = sqlite3_db_filename(ctx->db, StringValueCStr(db_name));
|
@@ -761,7 +807,7 @@ static VALUE rb_sqlite3_open16(VALUE self, VALUE file)
|
|
761
807
|
int status;
|
762
808
|
sqlite3RubyPtr ctx;
|
763
809
|
|
764
|
-
|
810
|
+
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);
|
765
811
|
|
766
812
|
#if defined TAINTING_SUPPORT
|
767
813
|
#if defined StringValueCStr
|
@@ -779,7 +825,7 @@ static VALUE rb_sqlite3_open16(VALUE self, VALUE file)
|
|
779
825
|
return INT2NUM(status);
|
780
826
|
}
|
781
827
|
|
782
|
-
void init_sqlite3_database()
|
828
|
+
void init_sqlite3_database(void)
|
783
829
|
{
|
784
830
|
#if 0
|
785
831
|
VALUE mSqlite3 = rb_define_module("SQLite3");
|
@@ -800,6 +846,7 @@ void init_sqlite3_database()
|
|
800
846
|
/* public "define_aggregator" is now a shim around define_aggregator2
|
801
847
|
* implemented in Ruby */
|
802
848
|
rb_define_private_method(cSqlite3Database, "define_aggregator2", rb_sqlite3_define_aggregator2, 2);
|
849
|
+
rb_define_private_method(cSqlite3Database, "disable_quirk_mode", rb_sqlite3_disable_quirk_mode, 0);
|
803
850
|
rb_define_method(cSqlite3Database, "interrupt", interrupt, 0);
|
804
851
|
rb_define_method(cSqlite3Database, "errmsg", errmsg, 0);
|
805
852
|
rb_define_method(cSqlite3Database, "errcode", errcode_, 0);
|
@@ -825,3 +872,7 @@ void init_sqlite3_database()
|
|
825
872
|
|
826
873
|
rb_sqlite3_aggregator_init();
|
827
874
|
}
|
875
|
+
|
876
|
+
#ifdef _MSC_VER
|
877
|
+
#pragma warning( pop )
|
878
|
+
#endif
|
data/ext/sqlite3/database.h
CHANGED
@@ -12,6 +12,8 @@ typedef sqlite3Ruby * sqlite3RubyPtr;
|
|
12
12
|
|
13
13
|
void init_sqlite3_database();
|
14
14
|
void set_sqlite3_func_result(sqlite3_context * ctx, VALUE result);
|
15
|
+
|
16
|
+
sqlite3RubyPtr sqlite3_database_unwrap(VALUE database);
|
15
17
|
VALUE sqlite3val2rb(sqlite3_value * val);
|
16
18
|
|
17
19
|
#endif
|