sqlite3 1.3.7 → 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 +45 -1
- data/Gemfile +15 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +29 -6
- data/ext/sqlite3/database.c +95 -22
- data/ext/sqlite3/extconf.rb +27 -7
- data/ext/sqlite3/sqlite3.c +112 -0
- data/ext/sqlite3/sqlite3_ruby.h +3 -4
- data/ext/sqlite3/statement.c +27 -18
- data/faq/faq.yml +1 -1
- data/lib/sqlite3/database.rb +34 -22
- data/lib/sqlite3/pragmas.rb +357 -49
- data/lib/sqlite3/resultset.rb +1 -1
- data/lib/sqlite3/version.rb +2 -2
- data/lib/sqlite3.rb +5 -0
- data/setup.rb +2 -2
- data/tasks/gem.rake +12 -6
- data/tasks/native.rake +22 -7
- data/tasks/vendor_sqlite3.rake +66 -20
- data/test/helper.rb +8 -4
- data/test/test_database.rb +95 -4
- data/test/test_database_readonly.rb +9 -2
- data/test/test_encoding.rb +34 -0
- data/test/test_integration.rb +35 -14
- data/test/test_integration_pending.rb +1 -1
- data/test/test_sqlite3.rb +12 -0
- data/test/test_statement.rb +14 -3
- metadata +120 -118
- data/.gemtest +0 -0
data/ext/sqlite3/statement.c
CHANGED
|
@@ -79,7 +79,6 @@ static VALUE initialize(VALUE self, VALUE db, VALUE sql)
|
|
|
79
79
|
static VALUE sqlite3_rb_close(VALUE self)
|
|
80
80
|
{
|
|
81
81
|
sqlite3StmtRubyPtr ctx;
|
|
82
|
-
sqlite3 * db;
|
|
83
82
|
|
|
84
83
|
Data_Get_Struct(self, sqlite3StmtRuby, ctx);
|
|
85
84
|
|
|
@@ -113,7 +112,6 @@ static VALUE step(VALUE self)
|
|
|
113
112
|
VALUE list;
|
|
114
113
|
#ifdef HAVE_RUBY_ENCODING_H
|
|
115
114
|
rb_encoding * internal_encoding;
|
|
116
|
-
int enc_index;
|
|
117
115
|
#endif
|
|
118
116
|
|
|
119
117
|
Data_Get_Struct(self, sqlite3StmtRuby, ctx);
|
|
@@ -125,8 +123,7 @@ static VALUE step(VALUE self)
|
|
|
125
123
|
#ifdef HAVE_RUBY_ENCODING_H
|
|
126
124
|
{
|
|
127
125
|
VALUE db = rb_iv_get(self, "@connection");
|
|
128
|
-
|
|
129
|
-
enc_index = NIL_P(encoding) ? rb_utf8_encindex() : rb_to_encoding_index(encoding);
|
|
126
|
+
rb_funcall(db, rb_intern("encoding"), 0);
|
|
130
127
|
internal_encoding = rb_default_internal_encoding();
|
|
131
128
|
}
|
|
132
129
|
#endif
|
|
@@ -156,7 +153,7 @@ static VALUE step(VALUE self)
|
|
|
156
153
|
(long)sqlite3_column_bytes(stmt, i)
|
|
157
154
|
);
|
|
158
155
|
#ifdef HAVE_RUBY_ENCODING_H
|
|
159
|
-
rb_enc_associate_index(str,
|
|
156
|
+
rb_enc_associate_index(str, rb_utf8_encindex());
|
|
160
157
|
if(internal_encoding)
|
|
161
158
|
str = rb_str_export_to_enc(str, internal_encoding);
|
|
162
159
|
#endif
|
|
@@ -186,6 +183,8 @@ static VALUE step(VALUE self)
|
|
|
186
183
|
return Qnil;
|
|
187
184
|
break;
|
|
188
185
|
default:
|
|
186
|
+
sqlite3_reset(stmt);
|
|
187
|
+
ctx->done_p = 0;
|
|
189
188
|
CHECK(sqlite3_db_handle(ctx->st), value);
|
|
190
189
|
}
|
|
191
190
|
|
|
@@ -238,15 +237,22 @@ static VALUE bind_param(VALUE self, VALUE key, VALUE value)
|
|
|
238
237
|
SQLITE_TRANSIENT
|
|
239
238
|
);
|
|
240
239
|
} else {
|
|
240
|
+
|
|
241
|
+
|
|
241
242
|
#ifdef HAVE_RUBY_ENCODING_H
|
|
242
|
-
if(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
if (UTF16_LE_P(value) || UTF16_BE_P(value)) {
|
|
244
|
+
status = sqlite3_bind_text16(
|
|
245
|
+
ctx->st,
|
|
246
|
+
index,
|
|
247
|
+
(const char *)StringValuePtr(value),
|
|
248
|
+
(int)RSTRING_LEN(value),
|
|
249
|
+
SQLITE_TRANSIENT
|
|
250
|
+
);
|
|
251
|
+
} else {
|
|
252
|
+
if (!UTF8_P(value) || !USASCII_P(value)) {
|
|
253
|
+
value = rb_str_encode(value, rb_enc_from_encoding(rb_utf8_encoding()), 0, Qnil);
|
|
247
254
|
}
|
|
248
255
|
#endif
|
|
249
|
-
|
|
250
256
|
status = sqlite3_bind_text(
|
|
251
257
|
ctx->st,
|
|
252
258
|
index,
|
|
@@ -254,13 +260,18 @@ static VALUE bind_param(VALUE self, VALUE key, VALUE value)
|
|
|
254
260
|
(int)RSTRING_LEN(value),
|
|
255
261
|
SQLITE_TRANSIENT
|
|
256
262
|
);
|
|
263
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
|
264
|
+
}
|
|
265
|
+
#endif
|
|
257
266
|
}
|
|
258
267
|
break;
|
|
259
|
-
case T_BIGNUM:
|
|
260
|
-
|
|
261
|
-
|
|
268
|
+
case T_BIGNUM: {
|
|
269
|
+
sqlite3_int64 num64;
|
|
270
|
+
if (bignum_to_int64(value, &num64)) {
|
|
271
|
+
status = sqlite3_bind_int64(ctx->st, index, num64);
|
|
262
272
|
break;
|
|
263
273
|
}
|
|
274
|
+
}
|
|
264
275
|
case T_FLOAT:
|
|
265
276
|
status = sqlite3_bind_double(ctx->st, index, NUM2DBL(value));
|
|
266
277
|
break;
|
|
@@ -289,12 +300,11 @@ static VALUE bind_param(VALUE self, VALUE key, VALUE value)
|
|
|
289
300
|
static VALUE reset_bang(VALUE self)
|
|
290
301
|
{
|
|
291
302
|
sqlite3StmtRubyPtr ctx;
|
|
292
|
-
int status;
|
|
293
303
|
|
|
294
304
|
Data_Get_Struct(self, sqlite3StmtRuby, ctx);
|
|
295
305
|
REQUIRE_OPEN_STMT(ctx);
|
|
296
306
|
|
|
297
|
-
|
|
307
|
+
sqlite3_reset(ctx->st);
|
|
298
308
|
|
|
299
309
|
ctx->done_p = 0;
|
|
300
310
|
|
|
@@ -309,12 +319,11 @@ static VALUE reset_bang(VALUE self)
|
|
|
309
319
|
static VALUE clear_bindings(VALUE self)
|
|
310
320
|
{
|
|
311
321
|
sqlite3StmtRubyPtr ctx;
|
|
312
|
-
int status;
|
|
313
322
|
|
|
314
323
|
Data_Get_Struct(self, sqlite3StmtRuby, ctx);
|
|
315
324
|
REQUIRE_OPEN_STMT(ctx);
|
|
316
325
|
|
|
317
|
-
|
|
326
|
+
sqlite3_clear_bindings(ctx->st);
|
|
318
327
|
|
|
319
328
|
ctx->done_p = 0;
|
|
320
329
|
|
data/faq/faq.yml
CHANGED
data/lib/sqlite3/database.rb
CHANGED
|
@@ -94,10 +94,17 @@ in version 2.0.0.
|
|
|
94
94
|
begin
|
|
95
95
|
yield stmt
|
|
96
96
|
ensure
|
|
97
|
-
stmt.close
|
|
97
|
+
stmt.close unless stmt.closed?
|
|
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
|
|
@@ -221,15 +219,18 @@ Support for this behavior will be removed in version 2.0.0.
|
|
|
221
219
|
sql = sql.strip
|
|
222
220
|
until sql.empty? do
|
|
223
221
|
prepare( sql ) do |stmt|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
stmt.
|
|
222
|
+
unless stmt.closed?
|
|
223
|
+
# FIXME: this should probably use sqlite3's api for batch execution
|
|
224
|
+
# This implementation requires stepping over the results.
|
|
225
|
+
if bind_vars.length == stmt.bind_parameter_count
|
|
226
|
+
stmt.bind_params(bind_vars)
|
|
227
|
+
end
|
|
228
|
+
stmt.step
|
|
228
229
|
end
|
|
229
|
-
stmt.step
|
|
230
230
|
sql = stmt.remainder.strip
|
|
231
231
|
end
|
|
232
232
|
end
|
|
233
|
+
# FIXME: we should not return `nil` as a success return value
|
|
233
234
|
nil
|
|
234
235
|
end
|
|
235
236
|
|
|
@@ -392,6 +393,9 @@ Support for this will be removed in version 2.0.0.
|
|
|
392
393
|
|
|
393
394
|
def finalize
|
|
394
395
|
super(@ctx)
|
|
396
|
+
result = @ctx.result
|
|
397
|
+
@ctx = FunctionProxy.new
|
|
398
|
+
result
|
|
395
399
|
end
|
|
396
400
|
})
|
|
397
401
|
proxy.ctx = FunctionProxy.new
|
|
@@ -428,6 +432,7 @@ Support for this will be removed in version 2.0.0.
|
|
|
428
432
|
#
|
|
429
433
|
# class LengthsAggregateHandler
|
|
430
434
|
# def self.arity; 1; end
|
|
435
|
+
# def self.name; 'lengths'; end
|
|
431
436
|
#
|
|
432
437
|
# def initialize
|
|
433
438
|
# @total = 0
|
|
@@ -446,21 +451,28 @@ Support for this will be removed in version 2.0.0.
|
|
|
446
451
|
# puts db.get_first_value( "select lengths(name) from A" )
|
|
447
452
|
def create_aggregate_handler( handler )
|
|
448
453
|
proxy = Class.new do
|
|
449
|
-
def initialize
|
|
450
|
-
@
|
|
451
|
-
@fp
|
|
454
|
+
def initialize klass
|
|
455
|
+
@klass = klass
|
|
456
|
+
@fp = FunctionProxy.new
|
|
452
457
|
end
|
|
453
458
|
|
|
454
459
|
def step( *args )
|
|
455
|
-
|
|
460
|
+
instance.step(@fp, *args)
|
|
456
461
|
end
|
|
457
462
|
|
|
458
463
|
def finalize
|
|
459
|
-
|
|
464
|
+
instance.finalize @fp
|
|
465
|
+
@instance = nil
|
|
460
466
|
@fp.result
|
|
461
467
|
end
|
|
468
|
+
|
|
469
|
+
private
|
|
470
|
+
|
|
471
|
+
def instance
|
|
472
|
+
@instance ||= @klass.new
|
|
473
|
+
end
|
|
462
474
|
end
|
|
463
|
-
define_aggregator(handler.name, proxy.new(handler
|
|
475
|
+
define_aggregator(handler.name, proxy.new(handler))
|
|
464
476
|
self
|
|
465
477
|
end
|
|
466
478
|
|