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/database.h
CHANGED
|
@@ -3,15 +3,37 @@
|
|
|
3
3
|
|
|
4
4
|
#include <sqlite3_ruby.h>
|
|
5
5
|
|
|
6
|
+
/* bits in the `flags` field */
|
|
7
|
+
#define SQLITE3_RB_DATABASE_READONLY 0x01
|
|
8
|
+
#define SQLITE3_RB_DATABASE_DISCARDED 0x02
|
|
9
|
+
|
|
6
10
|
struct _sqlite3Ruby {
|
|
7
|
-
|
|
11
|
+
sqlite3 *db;
|
|
12
|
+
VALUE busy_handler;
|
|
13
|
+
/* sqlite holds raw pointers to everything in these arrays. functions and
|
|
14
|
+
* aggregators are append-only, so redefining a name keeps the old object
|
|
15
|
+
* for the life of the connection: sqlite keys them by name and arity, and
|
|
16
|
+
* releasing on name alone was GHSA-28hh-pr2h-2w89. collations is rebuilt
|
|
17
|
+
* from a private hash keyed by name without regard to ASCII case, as
|
|
18
|
+
* sqlite keys them, so it releases a replaced comparator. */
|
|
19
|
+
VALUE functions;
|
|
20
|
+
VALUE collations;
|
|
21
|
+
VALUE aggregators;
|
|
22
|
+
VALUE trace_handler;
|
|
23
|
+
VALUE authorizer;
|
|
24
|
+
int stmt_timeout;
|
|
25
|
+
struct timespec stmt_deadline;
|
|
26
|
+
rb_pid_t owner;
|
|
27
|
+
int flags;
|
|
8
28
|
};
|
|
9
29
|
|
|
10
30
|
typedef struct _sqlite3Ruby sqlite3Ruby;
|
|
11
|
-
typedef sqlite3Ruby *
|
|
31
|
+
typedef sqlite3Ruby *sqlite3RubyPtr;
|
|
12
32
|
|
|
13
33
|
void init_sqlite3_database();
|
|
14
|
-
void set_sqlite3_func_result(sqlite3_context *
|
|
15
|
-
|
|
34
|
+
void set_sqlite3_func_result(sqlite3_context *ctx, VALUE result);
|
|
35
|
+
|
|
36
|
+
sqlite3RubyPtr sqlite3_database_unwrap(VALUE database);
|
|
37
|
+
VALUE sqlite3val2rb(sqlite3_value *val);
|
|
16
38
|
|
|
17
39
|
#endif
|
data/ext/sqlite3/exception.c
CHANGED
|
@@ -1,98 +1,217 @@
|
|
|
1
1
|
#include <sqlite3_ruby.h>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
static VALUE
|
|
4
|
+
status2klass(int status)
|
|
4
5
|
{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
6
|
+
/* Consider only lower 8 bits, to work correctly when
|
|
7
|
+
extended result codes are enabled. */
|
|
8
|
+
switch (status & 0xff) {
|
|
9
|
+
case SQLITE_OK:
|
|
10
|
+
return Qnil;
|
|
11
|
+
case SQLITE_ERROR:
|
|
12
|
+
return rb_path2class("SQLite3::SQLException");
|
|
13
|
+
case SQLITE_INTERNAL:
|
|
14
|
+
return rb_path2class("SQLite3::InternalException");
|
|
15
|
+
case SQLITE_PERM:
|
|
16
|
+
return rb_path2class("SQLite3::PermissionException");
|
|
17
|
+
case SQLITE_ABORT:
|
|
18
|
+
return rb_path2class("SQLite3::AbortException");
|
|
19
|
+
case SQLITE_BUSY:
|
|
20
|
+
return rb_path2class("SQLite3::BusyException");
|
|
21
|
+
case SQLITE_LOCKED:
|
|
22
|
+
return rb_path2class("SQLite3::LockedException");
|
|
23
|
+
case SQLITE_NOMEM:
|
|
24
|
+
return rb_path2class("SQLite3::MemoryException");
|
|
25
|
+
case SQLITE_READONLY:
|
|
26
|
+
return rb_path2class("SQLite3::ReadOnlyException");
|
|
27
|
+
case SQLITE_INTERRUPT:
|
|
28
|
+
return rb_path2class("SQLite3::InterruptException");
|
|
29
|
+
case SQLITE_IOERR:
|
|
30
|
+
return rb_path2class("SQLite3::IOException");
|
|
31
|
+
case SQLITE_CORRUPT:
|
|
32
|
+
return rb_path2class("SQLite3::CorruptException");
|
|
33
|
+
case SQLITE_NOTFOUND:
|
|
34
|
+
return rb_path2class("SQLite3::NotFoundException");
|
|
35
|
+
case SQLITE_FULL:
|
|
36
|
+
return rb_path2class("SQLite3::FullException");
|
|
37
|
+
case SQLITE_CANTOPEN:
|
|
38
|
+
return rb_path2class("SQLite3::CantOpenException");
|
|
39
|
+
case SQLITE_PROTOCOL:
|
|
40
|
+
return rb_path2class("SQLite3::ProtocolException");
|
|
41
|
+
case SQLITE_EMPTY:
|
|
42
|
+
return rb_path2class("SQLite3::EmptyException");
|
|
43
|
+
case SQLITE_SCHEMA:
|
|
44
|
+
return rb_path2class("SQLite3::SchemaChangedException");
|
|
45
|
+
case SQLITE_TOOBIG:
|
|
46
|
+
return rb_path2class("SQLite3::TooBigException");
|
|
47
|
+
case SQLITE_CONSTRAINT:
|
|
48
|
+
return rb_path2class("SQLite3::ConstraintException");
|
|
49
|
+
case SQLITE_MISMATCH:
|
|
50
|
+
return rb_path2class("SQLite3::MismatchException");
|
|
51
|
+
case SQLITE_MISUSE:
|
|
52
|
+
return rb_path2class("SQLite3::MisuseException");
|
|
53
|
+
case SQLITE_NOLFS:
|
|
54
|
+
return rb_path2class("SQLite3::UnsupportedException");
|
|
55
|
+
case SQLITE_AUTH:
|
|
56
|
+
return rb_path2class("SQLite3::AuthorizationException");
|
|
57
|
+
case SQLITE_FORMAT:
|
|
58
|
+
return rb_path2class("SQLite3::FormatException");
|
|
59
|
+
case SQLITE_RANGE:
|
|
60
|
+
return rb_path2class("SQLite3::RangeException");
|
|
61
|
+
case SQLITE_NOTADB:
|
|
62
|
+
return rb_path2class("SQLite3::NotADatabaseException");
|
|
63
|
+
default:
|
|
64
|
+
return rb_path2class("SQLite3::Exception");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void
|
|
69
|
+
rb_sqlite3_raise(sqlite3 *db, int status)
|
|
70
|
+
{
|
|
71
|
+
VALUE klass = status2klass(status);
|
|
72
|
+
if (NIL_P(klass)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
VALUE exception = rb_exc_new2(klass, sqlite3_errmsg(db));
|
|
77
|
+
rb_iv_set(exception, "@code", INT2FIX(status));
|
|
78
|
+
|
|
79
|
+
rb_exc_raise(exception);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* accepts a sqlite3 error message as the final argument, which will be `sqlite3_free`d
|
|
84
|
+
*/
|
|
85
|
+
void
|
|
86
|
+
rb_sqlite3_raise_msg(sqlite3 *db, int status, const char *msg)
|
|
87
|
+
{
|
|
88
|
+
VALUE klass = status2klass(status);
|
|
89
|
+
if (NIL_P(klass)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
VALUE exception = rb_exc_new2(klass, msg);
|
|
94
|
+
rb_iv_set(exception, "@code", INT2FIX(status));
|
|
95
|
+
sqlite3_free((void *)msg);
|
|
96
|
+
|
|
97
|
+
rb_exc_raise(exception);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
void
|
|
101
|
+
rb_sqlite3_raise_with_sql(sqlite3 *db, int status, const char *sql)
|
|
102
|
+
{
|
|
103
|
+
VALUE klass = status2klass(status);
|
|
104
|
+
if (NIL_P(klass)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const char *error_msg = sqlite3_errmsg(db);
|
|
109
|
+
int error_offset = -1;
|
|
110
|
+
#ifdef HAVE_SQLITE3_ERROR_OFFSET
|
|
111
|
+
error_offset = sqlite3_error_offset(db);
|
|
112
|
+
#endif
|
|
113
|
+
|
|
114
|
+
VALUE exception = rb_exc_new2(klass, error_msg);
|
|
115
|
+
rb_iv_set(exception, "@code", INT2FIX(status));
|
|
116
|
+
if (sql) {
|
|
117
|
+
rb_iv_set(exception, "@sql", rb_str_new2(sql));
|
|
118
|
+
rb_iv_set(exception, "@sql_offset", INT2FIX(error_offset));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
rb_exc_raise(exception);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* Each call into sqlite that can run callbacks pushes a frame on the current
|
|
125
|
+
* fiber's chain. A callback that fails records its rb_protect state in the top
|
|
126
|
+
* frame, and the call resumes Ruby's pending jump once sqlite returns. Ruby
|
|
127
|
+
* code that runs in between, such as a finalizer during an allocation, pushes
|
|
128
|
+
* its own frame for any nested call, so it never takes the outer call's jump.
|
|
129
|
+
* The chain is fiber-local because Ruby code inside a callback can switch
|
|
130
|
+
* threads or fibers, and a Ruby thread can move between native threads inside
|
|
131
|
+
* rb_protect. */
|
|
132
|
+
typedef struct {
|
|
133
|
+
rb_sqlite3_callback_frame_t *top;
|
|
134
|
+
} callback_frames_t;
|
|
135
|
+
|
|
136
|
+
static const rb_data_type_t callback_frames_type = {
|
|
137
|
+
.wrap_struct_name = "SQLite3::CallbackFrames",
|
|
138
|
+
.function = {
|
|
139
|
+
.dfree = RUBY_TYPED_DEFAULT_FREE,
|
|
140
|
+
},
|
|
141
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
static ID id_callback_frames;
|
|
145
|
+
|
|
146
|
+
/* Ruby code can overwrite or delete the fiber-local, so check its type. */
|
|
147
|
+
static VALUE
|
|
148
|
+
current_callback_frames_holder(void)
|
|
149
|
+
{
|
|
150
|
+
VALUE holder = rb_thread_local_aref(rb_thread_current(), id_callback_frames);
|
|
151
|
+
return rb_typeddata_is_kind_of(holder, &callback_frames_type) ? holder : Qnil;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static callback_frames_t *
|
|
155
|
+
current_callback_frames(void)
|
|
156
|
+
{
|
|
157
|
+
VALUE holder = current_callback_frames_holder();
|
|
158
|
+
return NIL_P(holder) ? NULL : (callback_frames_t *)RTYPEDDATA_DATA(holder);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
void
|
|
162
|
+
rb_sqlite3_push_callback_frame(rb_sqlite3_callback_frame_t *frame)
|
|
163
|
+
{
|
|
164
|
+
VALUE holder = current_callback_frames_holder();
|
|
165
|
+
callback_frames_t *frames;
|
|
166
|
+
|
|
167
|
+
if (NIL_P(holder)) {
|
|
168
|
+
holder = TypedData_Make_Struct(rb_cObject, callback_frames_t, &callback_frames_type, frames);
|
|
169
|
+
rb_thread_local_aset(rb_thread_current(), id_callback_frames, holder);
|
|
170
|
+
}
|
|
171
|
+
frames = (callback_frames_t *)RTYPEDDATA_DATA(holder);
|
|
172
|
+
|
|
173
|
+
frame->state = 0;
|
|
174
|
+
frame->prev = frames->top;
|
|
175
|
+
frame->holder = holder;
|
|
176
|
+
frames->top = frame;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
int
|
|
180
|
+
rb_sqlite3_pop_callback_frame(rb_sqlite3_callback_frame_t *frame)
|
|
181
|
+
{
|
|
182
|
+
((callback_frames_t *)RTYPEDDATA_DATA(frame->holder))->top = frame->prev;
|
|
183
|
+
return frame->state;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
VALUE
|
|
187
|
+
rb_sqlite3_protect_callback(VALUE (*body)(VALUE), VALUE data, int *failed)
|
|
188
|
+
{
|
|
189
|
+
callback_frames_t *frames = current_callback_frames();
|
|
190
|
+
rb_sqlite3_callback_frame_t *frame = frames ? frames->top : NULL;
|
|
191
|
+
VALUE result;
|
|
192
|
+
int state;
|
|
193
|
+
|
|
194
|
+
if (frame && frame->state) {
|
|
195
|
+
*failed = 1;
|
|
196
|
+
return Qnil;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
result = rb_protect(body, data, &state);
|
|
200
|
+
*failed = state != 0;
|
|
201
|
+
|
|
202
|
+
if (frame) {
|
|
203
|
+
frame->state = state;
|
|
204
|
+
} else if (state) {
|
|
205
|
+
/* sqlite ran the callback from a call that cannot resume the jump, such
|
|
206
|
+
* as Statement#reset!, so the error is dropped */
|
|
207
|
+
rb_set_errinfo(Qnil);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
void
|
|
214
|
+
init_sqlite3_exception(void)
|
|
215
|
+
{
|
|
216
|
+
id_callback_frames = rb_intern("__sqlite3_callback_frames__");
|
|
98
217
|
}
|
data/ext/sqlite3/exception.h
CHANGED
|
@@ -2,7 +2,32 @@
|
|
|
2
2
|
#define SQLITE3_EXCEPTION_RUBY
|
|
3
3
|
|
|
4
4
|
#define CHECK(_db, _status) rb_sqlite3_raise(_db, _status);
|
|
5
|
+
#define CHECK_MSG(_db, _status, _msg) rb_sqlite3_raise_msg(_db, _status, _msg);
|
|
6
|
+
#define CHECK_PREPARE(_db, _status, _sql) rb_sqlite3_raise_with_sql(_db, _status, _sql)
|
|
5
7
|
|
|
6
|
-
void rb_sqlite3_raise(sqlite3 *
|
|
8
|
+
void rb_sqlite3_raise(sqlite3 *db, int status);
|
|
9
|
+
void rb_sqlite3_raise_msg(sqlite3 *db, int status, const char *msg);
|
|
10
|
+
void rb_sqlite3_raise_with_sql(sqlite3 *db, int status, const char *sql);
|
|
11
|
+
|
|
12
|
+
typedef struct rb_sqlite3_callback_frame {
|
|
13
|
+
int state;
|
|
14
|
+
struct rb_sqlite3_callback_frame *prev;
|
|
15
|
+
/* the frame lives on the C stack, so GC marks and pins this */
|
|
16
|
+
VALUE holder;
|
|
17
|
+
} rb_sqlite3_callback_frame_t;
|
|
18
|
+
|
|
19
|
+
/* A call into sqlite that can run callbacks is wrapped in a frame. sqlite
|
|
20
|
+
* cannot carry a raise or a throw, so a failed callback records its rb_protect
|
|
21
|
+
* state in the frame, and later callbacks skip their Ruby code. Pop the frame
|
|
22
|
+
* when sqlite returns, then resume the jump with rb_jump_tag if the returned
|
|
23
|
+
* state is nonzero. Run nothing but the sqlite call in between, because a
|
|
24
|
+
* raise there would skip the pop. */
|
|
25
|
+
void rb_sqlite3_push_callback_frame(rb_sqlite3_callback_frame_t *frame);
|
|
26
|
+
int rb_sqlite3_pop_callback_frame(rb_sqlite3_callback_frame_t *frame);
|
|
27
|
+
|
|
28
|
+
/* Runs a callback's Ruby code for sqlite. Sets *failed if it did not complete. */
|
|
29
|
+
VALUE rb_sqlite3_protect_callback(VALUE (*body)(VALUE), VALUE data, int *failed);
|
|
30
|
+
|
|
31
|
+
void init_sqlite3_exception(void);
|
|
7
32
|
|
|
8
33
|
#endif
|
data/ext/sqlite3/extconf.rb
CHANGED
|
@@ -19,7 +19,7 @@ module Sqlite3
|
|
|
19
19
|
|
|
20
20
|
configure_extension
|
|
21
21
|
|
|
22
|
-
create_makefile(
|
|
22
|
+
create_makefile("sqlite3/sqlite3_native")
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def configure_cross_compiler
|
|
@@ -49,16 +49,28 @@ module Sqlite3
|
|
|
49
49
|
|
|
50
50
|
def configure_packaged_libraries
|
|
51
51
|
minimal_recipe.tap do |recipe|
|
|
52
|
-
recipe.configure_options += [
|
|
52
|
+
recipe.configure_options += [
|
|
53
|
+
"--disable-shared",
|
|
54
|
+
"--enable-static",
|
|
55
|
+
"--enable-fts5"
|
|
56
|
+
]
|
|
53
57
|
ENV.to_h.tap do |env|
|
|
54
|
-
|
|
58
|
+
user_cflags = with_config("sqlite-cflags")
|
|
59
|
+
more_cflags = [
|
|
55
60
|
"-fPIC", # needed for linking the static library into a shared library
|
|
56
61
|
"-O2", # see https://github.com/sparklemotion/sqlite3-ruby/issues/335 for some benchmarks
|
|
57
62
|
"-fvisibility=hidden", # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
|
|
63
|
+
"-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1",
|
|
64
|
+
"-DSQLITE_USE_URI=1",
|
|
65
|
+
"-DSQLITE_ENABLE_DBPAGE_VTAB=1",
|
|
66
|
+
"-DSQLITE_ENABLE_DBSTAT_VTAB=1"
|
|
58
67
|
]
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
# sqlite >= 3.54 requires Vista APIs, same as ruby's default target. Placed first so a
|
|
69
|
+
# user-defined _WIN32_WINNT takes precedence.
|
|
70
|
+
windows_cflags = windows? ? ["-D_WIN32_WINNT=0x0600"] : []
|
|
71
|
+
env["CFLAGS"] = [windows_cflags, user_cflags, env["CFLAGS"], more_cflags].flatten.join(" ")
|
|
72
|
+
recipe.configure_options += env.slice(*ENV_ALLOWLIST)
|
|
73
|
+
.map { |key, value| "#{key}=#{value.strip}" }
|
|
62
74
|
end
|
|
63
75
|
|
|
64
76
|
unless File.exist?(File.join(recipe.target, recipe.host, recipe.name, recipe.version))
|
|
@@ -87,46 +99,55 @@ module Sqlite3
|
|
|
87
99
|
end
|
|
88
100
|
|
|
89
101
|
ldflags.each { |ldflag| append_ldflags(ldflag) }
|
|
102
|
+
|
|
103
|
+
append_cppflags("-DUSING_PACKAGED_LIBRARIES")
|
|
104
|
+
append_cppflags("-DUSING_PRECOMPILED_LIBRARIES") if cross_build?
|
|
90
105
|
end
|
|
91
106
|
end
|
|
92
107
|
|
|
93
108
|
def configure_extension
|
|
94
|
-
if Gem::Requirement.new("< 2.7").satisfied_by?(Gem::Version.new(RUBY_VERSION))
|
|
95
|
-
append_cppflags("-DTAINTING_SUPPORT")
|
|
96
|
-
end
|
|
97
|
-
|
|
98
109
|
append_cflags("-fvisibility=hidden") # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
|
|
99
110
|
|
|
100
|
-
if find_header("sqlite3.h")
|
|
101
|
-
# noop
|
|
102
|
-
elsif sqlcipher? && find_header("sqlcipher/sqlite3.h")
|
|
111
|
+
if sqlcipher? && find_header("sqlcipher/sqlite3.h")
|
|
103
112
|
append_cppflags("-DUSING_SQLCIPHER_INC_SUBDIR")
|
|
113
|
+
elsif find_header("sqlite3.h")
|
|
114
|
+
# noop
|
|
104
115
|
else
|
|
105
116
|
abort_could_not_find("sqlite3.h")
|
|
106
117
|
end
|
|
107
118
|
|
|
108
119
|
abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")
|
|
109
120
|
|
|
121
|
+
# Ruby 3.0+, but not on every implementation:
|
|
122
|
+
# https://github.com/oracle/truffleruby/issues/3408
|
|
123
|
+
have_func("rb_enc_interned_str_cstr")
|
|
124
|
+
have_func("rb_enc_interned_str")
|
|
125
|
+
|
|
110
126
|
# Functions defined in 1.9 but not 1.8
|
|
111
|
-
have_func(
|
|
127
|
+
have_func("rb_proc_arity")
|
|
112
128
|
|
|
113
129
|
# Functions defined in 2.1 but not 2.0
|
|
114
|
-
have_func(
|
|
130
|
+
have_func("rb_integer_pack")
|
|
115
131
|
|
|
116
132
|
# These functions may not be defined
|
|
117
|
-
have_func(
|
|
118
|
-
have_func(
|
|
119
|
-
have_func(
|
|
120
|
-
have_func(
|
|
121
|
-
have_func(
|
|
133
|
+
have_func("sqlite3_initialize")
|
|
134
|
+
have_func("sqlite3_backup_init")
|
|
135
|
+
have_func("sqlite3_column_database_name")
|
|
136
|
+
have_func("sqlite3_enable_load_extension")
|
|
137
|
+
have_func("sqlite3_load_extension")
|
|
122
138
|
|
|
123
|
-
unless have_func(
|
|
139
|
+
unless have_func("sqlite3_open_v2") # https://www.sqlite.org/releaselog/3_5_0.html
|
|
124
140
|
abort("\nPlease use a version of SQLite3 >= 3.5.0\n\n")
|
|
125
141
|
end
|
|
126
142
|
|
|
127
|
-
have_func(
|
|
128
|
-
|
|
129
|
-
|
|
143
|
+
have_func("sqlite3_prepare_v2")
|
|
144
|
+
have_func("sqlite3_db_name", "sqlite3.h") # v3.39.0
|
|
145
|
+
have_func("sqlite3_error_offset", "sqlite3.h") # v3.38.0
|
|
146
|
+
have_func("sqlite3_serialize", "sqlite3.h") # v3.23.0
|
|
147
|
+
have_func("sqlite3_deserialize", "sqlite3.h") # v3.23.0
|
|
148
|
+
|
|
149
|
+
have_type("sqlite3_int64", "sqlite3.h")
|
|
150
|
+
have_type("sqlite3_uint64", "sqlite3.h")
|
|
130
151
|
end
|
|
131
152
|
|
|
132
153
|
def minimal_recipe
|
|
@@ -152,8 +173,7 @@ module Sqlite3
|
|
|
152
173
|
end
|
|
153
174
|
|
|
154
175
|
def mini_portile_config
|
|
155
|
-
|
|
156
|
-
YAML.load_file(File.join(package_root_dir, "dependencies.yml"))
|
|
176
|
+
YAML.load_file(File.join(package_root_dir, "dependencies.yml"), symbolize_names: true)
|
|
157
177
|
end
|
|
158
178
|
|
|
159
179
|
def abort_could_not_find(missing)
|
|
@@ -161,7 +181,7 @@ module Sqlite3
|
|
|
161
181
|
end
|
|
162
182
|
|
|
163
183
|
def abort_pkg_config(id)
|
|
164
|
-
abort("\nCould not configure the build properly (#{id}). Please install
|
|
184
|
+
abort("\nCould not configure the build properly (#{id}). Please install the `pkg-config` utility.\n\n")
|
|
165
185
|
end
|
|
166
186
|
|
|
167
187
|
def cross_build?
|
|
@@ -180,6 +200,10 @@ module Sqlite3
|
|
|
180
200
|
RbConfig::CONFIG["target_os"].include?("darwin")
|
|
181
201
|
end
|
|
182
202
|
|
|
203
|
+
def windows?
|
|
204
|
+
RbConfig::CONFIG["target_os"].match?(/mingw|mswin/)
|
|
205
|
+
end
|
|
206
|
+
|
|
183
207
|
def print_help
|
|
184
208
|
print(<<~TEXT)
|
|
185
209
|
USAGE: ruby #{$PROGRAM_NAME} [options]
|
|
@@ -234,17 +258,23 @@ module Sqlite3
|
|
|
234
258
|
|
|
235
259
|
Flags only used when building and using the packaged libraries:
|
|
236
260
|
|
|
261
|
+
--with-sqlite-cflags=CFLAGS
|
|
262
|
+
Explicitly pass compiler flags to the sqlite library build. These flags will
|
|
263
|
+
appear on the commandline before any flags set in the CFLAGS environment
|
|
264
|
+
variable. This is useful for setting compilation options in your project's
|
|
265
|
+
bundler config. See INSTALLATION.md for more information.
|
|
266
|
+
|
|
237
267
|
--enable-cross-build
|
|
238
268
|
Enable cross-build mode. (You probably do not want to set this manually.)
|
|
239
269
|
|
|
240
270
|
|
|
241
|
-
Environment variables used for compiling the C extension:
|
|
271
|
+
Environment variables used for compiling the gem's C extension:
|
|
242
272
|
|
|
243
273
|
CC
|
|
244
274
|
Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']`
|
|
245
275
|
|
|
246
276
|
|
|
247
|
-
Environment variables passed through to the compilation of
|
|
277
|
+
Environment variables passed through to the compilation of sqlite:
|
|
248
278
|
|
|
249
279
|
CC
|
|
250
280
|
CPPFLAGS
|