mockley_crew 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mockley_crew/version.rb +1 -1
- data/vendor/gems/sqlite3/cache/sqlite3-1.3.13.gem +0 -0
- data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/gem.build_complete +0 -0
- data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/gem_make.out +33 -0
- data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/mkmf.log +592 -0
- data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/sqlite3/sqlite3_native.so +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/API_CHANGES.rdoc +50 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/CHANGELOG.rdoc +292 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ChangeLog.cvs +88 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/Gemfile +15 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/LICENSE +27 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/Manifest.txt +52 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/README.rdoc +118 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/Rakefile +10 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/Makefile +263 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/backup.c +168 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/backup.h +15 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/backup.o +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/database.c +888 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/database.h +15 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/database.o +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/exception.c +94 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/exception.h +8 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/exception.o +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/extconf.rb +71 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3.c +152 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3.o +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3_native.so +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3_ruby.h +52 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/statement.c +447 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/statement.h +16 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/statement.o +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/faq/faq.rb +145 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/faq/faq.yml +426 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/constants.rb +49 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/database.rb +591 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/errors.rb +44 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/pragmas.rb +588 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/resultset.rb +195 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/sqlite3_native.so +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb +144 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/translator.rb +118 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/value.rb +57 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/version.rb +25 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3.rb +15 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/setup.rb +1333 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/faq.rake +9 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/gem.rake +38 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/native.rake +52 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/vendor_sqlite3.rake +97 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/helper.rb +18 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_backup.rb +33 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_collation.rb +82 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_database.rb +430 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_database_readonly.rb +36 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_deprecated.rb +44 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_encoding.rb +155 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration.rb +576 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_open_close.rb +30 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_pending.rb +115 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_resultset.rb +159 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_statement.rb +194 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_result_set.rb +37 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_sqlite3.rb +21 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_statement.rb +260 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_statement_execute.rb +35 -0
- data/vendor/gems/sqlite3/specifications/sqlite3-1.3.13.gemspec +56 -0
- metadata +67 -1
@@ -0,0 +1,430 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module SQLite3
|
6
|
+
class TestDatabase < SQLite3::TestCase
|
7
|
+
attr_reader :db
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@db = SQLite3::Database.new(':memory:')
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_segv
|
15
|
+
assert_raises(TypeError) { SQLite3::Database.new 1 }
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_db_filename
|
19
|
+
tf = nil
|
20
|
+
assert_equal '', @db.filename('main')
|
21
|
+
tf = Tempfile.new 'thing'
|
22
|
+
@db = SQLite3::Database.new tf.path
|
23
|
+
assert_equal File.expand_path(tf.path), File.expand_path(@db.filename('main'))
|
24
|
+
ensure
|
25
|
+
tf.unlink if tf
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_filename
|
29
|
+
tf = nil
|
30
|
+
assert_equal '', @db.filename
|
31
|
+
tf = Tempfile.new 'thing'
|
32
|
+
@db = SQLite3::Database.new tf.path
|
33
|
+
assert_equal File.expand_path(tf.path), File.expand_path(@db.filename)
|
34
|
+
ensure
|
35
|
+
tf.unlink if tf
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_filename_with_attachment
|
39
|
+
tf = nil
|
40
|
+
assert_equal '', @db.filename
|
41
|
+
tf = Tempfile.new 'thing'
|
42
|
+
@db.execute "ATTACH DATABASE '#{tf.path}' AS 'testing'"
|
43
|
+
assert_equal File.expand_path(tf.path), File.expand_path(@db.filename('testing'))
|
44
|
+
ensure
|
45
|
+
tf.unlink if tf
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_bignum
|
49
|
+
num = 4907021672125087844
|
50
|
+
db.execute 'CREATE TABLE "employees" ("token" integer(8), "name" varchar(20) NOT NULL)'
|
51
|
+
db.execute "INSERT INTO employees(name, token) VALUES('employee-1', ?)", [num]
|
52
|
+
rows = db.execute 'select token from employees'
|
53
|
+
assert_equal num, rows.first.first
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_blob
|
57
|
+
@db.execute("CREATE TABLE blobs ( id INTEGER, hash BLOB(10) )")
|
58
|
+
blob = Blob.new("foo\0bar")
|
59
|
+
@db.execute("INSERT INTO blobs VALUES (0, ?)", [blob])
|
60
|
+
assert_equal [[0, blob, blob.length, blob.length*2]], @db.execute("SELECT id, hash, length(hash), length(hex(hash)) FROM blobs")
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_get_first_row
|
64
|
+
assert_equal [1], @db.get_first_row('SELECT 1')
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_get_first_row_with_type_translation_and_hash_results
|
68
|
+
@db.results_as_hash = true
|
69
|
+
assert_equal({0=>1, "1"=>1}, @db.get_first_row('SELECT 1'))
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_execute_with_type_translation_and_hash
|
73
|
+
@db.results_as_hash = true
|
74
|
+
rows = []
|
75
|
+
@db.execute('SELECT 1') { |row| rows << row }
|
76
|
+
|
77
|
+
assert_equal({0=>1, "1"=>1}, rows.first)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_encoding
|
81
|
+
assert @db.encoding, 'database has encoding'
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_changes
|
85
|
+
@db.execute("CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT, number integer)")
|
86
|
+
assert_equal 0, @db.changes
|
87
|
+
@db.execute("INSERT INTO items (number) VALUES (10)")
|
88
|
+
assert_equal 1, @db.changes
|
89
|
+
@db.execute_batch(
|
90
|
+
"UPDATE items SET number = (number + :nn) WHERE (number = :n)",
|
91
|
+
{"nn" => 20, "n" => 10})
|
92
|
+
assert_equal 1, @db.changes
|
93
|
+
assert_equal [[30]], @db.execute("select number from items")
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_batch_last_comment_is_processed
|
97
|
+
# FIXME: nil as a successful return value is kinda dumb
|
98
|
+
assert_nil @db.execute_batch <<-eosql
|
99
|
+
CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT);
|
100
|
+
-- omg
|
101
|
+
eosql
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_new
|
105
|
+
db = SQLite3::Database.new(':memory:')
|
106
|
+
assert db
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_new_yields_self
|
110
|
+
thing = nil
|
111
|
+
SQLite3::Database.new(':memory:') do |db|
|
112
|
+
thing = db
|
113
|
+
end
|
114
|
+
assert_instance_of(SQLite3::Database, thing)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_new_with_options
|
118
|
+
# determine if Ruby is running on Big Endian platform
|
119
|
+
utf16 = ([1].pack("I") == [1].pack("N")) ? "UTF-16BE" : "UTF-16LE"
|
120
|
+
|
121
|
+
if RUBY_VERSION >= "1.9"
|
122
|
+
db = SQLite3::Database.new(':memory:'.encode(utf16), :utf16 => true)
|
123
|
+
else
|
124
|
+
db = SQLite3::Database.new(Iconv.conv(utf16, 'UTF-8', ':memory:'),
|
125
|
+
:utf16 => true)
|
126
|
+
end
|
127
|
+
assert db
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_close
|
131
|
+
db = SQLite3::Database.new(':memory:')
|
132
|
+
db.close
|
133
|
+
assert db.closed?
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_block_closes_self
|
137
|
+
thing = nil
|
138
|
+
SQLite3::Database.new(':memory:') do |db|
|
139
|
+
thing = db
|
140
|
+
assert !thing.closed?
|
141
|
+
end
|
142
|
+
assert thing.closed?
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_block_closes_self_even_raised
|
146
|
+
thing = nil
|
147
|
+
begin
|
148
|
+
SQLite3::Database.new(':memory:') do |db|
|
149
|
+
thing = db
|
150
|
+
raise
|
151
|
+
end
|
152
|
+
rescue
|
153
|
+
end
|
154
|
+
assert thing.closed?
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_prepare
|
158
|
+
db = SQLite3::Database.new(':memory:')
|
159
|
+
stmt = db.prepare('select "hello world"')
|
160
|
+
assert_instance_of(SQLite3::Statement, stmt)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_block_prepare_does_not_double_close
|
164
|
+
db = SQLite3::Database.new(':memory:')
|
165
|
+
r = db.prepare('select "hello world"') do |stmt|
|
166
|
+
stmt.close
|
167
|
+
:foo
|
168
|
+
end
|
169
|
+
assert_equal :foo, r
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_total_changes
|
173
|
+
db = SQLite3::Database.new(':memory:')
|
174
|
+
db.execute("create table foo ( a integer primary key, b text )")
|
175
|
+
db.execute("insert into foo (b) values ('hello')")
|
176
|
+
assert_equal 1, db.total_changes
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_execute_returns_list_of_hash
|
180
|
+
db = SQLite3::Database.new(':memory:', :results_as_hash => true)
|
181
|
+
db.execute("create table foo ( a integer primary key, b text )")
|
182
|
+
db.execute("insert into foo (b) values ('hello')")
|
183
|
+
rows = db.execute("select * from foo")
|
184
|
+
assert_equal [{0=>1, "a"=>1, "b"=>"hello", 1=>"hello"}], rows
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_execute_yields_hash
|
188
|
+
db = SQLite3::Database.new(':memory:', :results_as_hash => true)
|
189
|
+
db.execute("create table foo ( a integer primary key, b text )")
|
190
|
+
db.execute("insert into foo (b) values ('hello')")
|
191
|
+
db.execute("select * from foo") do |row|
|
192
|
+
assert_equal({0=>1, "a"=>1, "b"=>"hello", 1=>"hello"}, row)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_table_info
|
197
|
+
db = SQLite3::Database.new(':memory:', :results_as_hash => true)
|
198
|
+
db.execute("create table foo ( a integer primary key, b text )")
|
199
|
+
info = [{
|
200
|
+
"name" => "a",
|
201
|
+
"pk" => 1,
|
202
|
+
"notnull" => 0,
|
203
|
+
"type" => "integer",
|
204
|
+
"dflt_value" => nil,
|
205
|
+
"cid" => 0
|
206
|
+
},
|
207
|
+
{
|
208
|
+
"name" => "b",
|
209
|
+
"pk" => 0,
|
210
|
+
"notnull" => 0,
|
211
|
+
"type" => "text",
|
212
|
+
"dflt_value" => nil,
|
213
|
+
"cid" => 1
|
214
|
+
}]
|
215
|
+
assert_equal info, db.table_info('foo')
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_total_changes_closed
|
219
|
+
db = SQLite3::Database.new(':memory:')
|
220
|
+
db.close
|
221
|
+
assert_raise(SQLite3::Exception) do
|
222
|
+
db.total_changes
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_trace_requires_opendb
|
227
|
+
@db.close
|
228
|
+
assert_raise(SQLite3::Exception) do
|
229
|
+
@db.trace { |x| }
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_trace_with_block
|
234
|
+
result = nil
|
235
|
+
@db.trace { |sql| result = sql }
|
236
|
+
@db.execute "select 'foo'"
|
237
|
+
assert_equal "select 'foo'", result
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_trace_with_object
|
241
|
+
obj = Class.new {
|
242
|
+
attr_accessor :result
|
243
|
+
def call sql; @result = sql end
|
244
|
+
}.new
|
245
|
+
|
246
|
+
@db.trace(obj)
|
247
|
+
@db.execute "select 'foo'"
|
248
|
+
assert_equal "select 'foo'", obj.result
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_trace_takes_nil
|
252
|
+
@db.trace(nil)
|
253
|
+
@db.execute "select 'foo'"
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_last_insert_row_id_closed
|
257
|
+
@db.close
|
258
|
+
assert_raise(SQLite3::Exception) do
|
259
|
+
@db.last_insert_row_id
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_define_function
|
264
|
+
called_with = nil
|
265
|
+
@db.define_function("hello") do |value|
|
266
|
+
called_with = value
|
267
|
+
end
|
268
|
+
@db.execute("select hello(10)")
|
269
|
+
assert_equal 10, called_with
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_call_func_arg_type
|
273
|
+
called_with = nil
|
274
|
+
@db.define_function("hello") do |b, c, d|
|
275
|
+
called_with = [b, c, d]
|
276
|
+
nil
|
277
|
+
end
|
278
|
+
@db.execute("select hello(2.2, 'foo', NULL)")
|
279
|
+
assert_equal [2.2, 'foo', nil], called_with
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_define_varargs
|
283
|
+
called_with = nil
|
284
|
+
@db.define_function("hello") do |*args|
|
285
|
+
called_with = args
|
286
|
+
nil
|
287
|
+
end
|
288
|
+
@db.execute("select hello(2.2, 'foo', NULL)")
|
289
|
+
assert_equal [2.2, 'foo', nil], called_with
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_call_func_blob
|
293
|
+
called_with = nil
|
294
|
+
@db.define_function("hello") do |a, b|
|
295
|
+
called_with = [a, b, a.length]
|
296
|
+
nil
|
297
|
+
end
|
298
|
+
blob = Blob.new("a\0fine\0kettle\0of\0fish")
|
299
|
+
@db.execute("select hello(?, length(?))", [blob, blob])
|
300
|
+
assert_equal [blob, blob.length, 21], called_with
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_function_return
|
304
|
+
@db.define_function("hello") { |a| 10 }
|
305
|
+
assert_equal [10], @db.execute("select hello('world')").first
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_function_return_types
|
309
|
+
[10, 2.2, nil, "foo", Blob.new("foo\0bar")].each do |thing|
|
310
|
+
@db.define_function("hello") { |a| thing }
|
311
|
+
assert_equal [thing], @db.execute("select hello('world')").first
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_function_gc_segfault
|
316
|
+
@db.create_function("bug", -1) { |func, *values| func.result = values.join }
|
317
|
+
# With a lot of data and a lot of threads, try to induce a GC segfault.
|
318
|
+
params = Array.new(127, "?" * 28000)
|
319
|
+
proc = Proc.new {
|
320
|
+
db.execute("select bug(#{Array.new(params.length, "?").join(",")})", params)
|
321
|
+
}
|
322
|
+
m = Mutex.new
|
323
|
+
30.times.map { Thread.new { m.synchronize { proc.call } } }.each(&:join)
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_function_return_type_round_trip
|
327
|
+
[10, 2.2, nil, "foo", Blob.new("foo\0bar")].each do |thing|
|
328
|
+
@db.define_function("hello") { |a| a }
|
329
|
+
assert_equal [thing], @db.execute("select hello(hello(?))", [thing]).first
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_define_function_closed
|
334
|
+
@db.close
|
335
|
+
assert_raise(SQLite3::Exception) do
|
336
|
+
@db.define_function('foo') { }
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_inerrupt_closed
|
341
|
+
@db.close
|
342
|
+
assert_raise(SQLite3::Exception) do
|
343
|
+
@db.interrupt
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_define_aggregate
|
348
|
+
@db.execute "create table foo ( a integer primary key, b text )"
|
349
|
+
@db.execute "insert into foo ( b ) values ( 'foo' )"
|
350
|
+
@db.execute "insert into foo ( b ) values ( 'bar' )"
|
351
|
+
@db.execute "insert into foo ( b ) values ( 'baz' )"
|
352
|
+
|
353
|
+
acc = Class.new {
|
354
|
+
attr_reader :sum
|
355
|
+
alias :finalize :sum
|
356
|
+
def initialize
|
357
|
+
@sum = 0
|
358
|
+
end
|
359
|
+
|
360
|
+
def step a
|
361
|
+
@sum += a
|
362
|
+
end
|
363
|
+
}.new
|
364
|
+
|
365
|
+
@db.define_aggregator("accumulate", acc)
|
366
|
+
value = @db.get_first_value( "select accumulate(a) from foo" )
|
367
|
+
assert_equal 6, value
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_authorizer_ok
|
371
|
+
@db.authorizer = Class.new {
|
372
|
+
def call action, a, b, c, d; true end
|
373
|
+
}.new
|
374
|
+
@db.prepare("select 'fooooo'")
|
375
|
+
|
376
|
+
@db.authorizer = Class.new {
|
377
|
+
def call action, a, b, c, d; 0 end
|
378
|
+
}.new
|
379
|
+
@db.prepare("select 'fooooo'")
|
380
|
+
end
|
381
|
+
|
382
|
+
def test_authorizer_ignore
|
383
|
+
@db.authorizer = Class.new {
|
384
|
+
def call action, a, b, c, d; nil end
|
385
|
+
}.new
|
386
|
+
stmt = @db.prepare("select 'fooooo'")
|
387
|
+
assert_equal nil, stmt.step
|
388
|
+
end
|
389
|
+
|
390
|
+
def test_authorizer_fail
|
391
|
+
@db.authorizer = Class.new {
|
392
|
+
def call action, a, b, c, d; false end
|
393
|
+
}.new
|
394
|
+
assert_raises(SQLite3::AuthorizationException) do
|
395
|
+
@db.prepare("select 'fooooo'")
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_remove_auth
|
400
|
+
@db.authorizer = Class.new {
|
401
|
+
def call action, a, b, c, d; false end
|
402
|
+
}.new
|
403
|
+
assert_raises(SQLite3::AuthorizationException) do
|
404
|
+
@db.prepare("select 'fooooo'")
|
405
|
+
end
|
406
|
+
|
407
|
+
@db.authorizer = nil
|
408
|
+
@db.prepare("select 'fooooo'")
|
409
|
+
end
|
410
|
+
|
411
|
+
def test_close_with_open_statements
|
412
|
+
@db.prepare("select 'foo'")
|
413
|
+
assert_raises(SQLite3::BusyException) do
|
414
|
+
@db.close
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
def test_execute_with_empty_bind_params
|
419
|
+
assert_equal [['foo']], @db.execute("select 'foo'", [])
|
420
|
+
end
|
421
|
+
|
422
|
+
def test_query_with_named_bind_params
|
423
|
+
assert_equal [['foo']], @db.query("select :n", {'n' => 'foo'}).to_a
|
424
|
+
end
|
425
|
+
|
426
|
+
def test_execute_with_named_bind_params
|
427
|
+
assert_equal [['foo']], @db.execute("select :n", {'n' => 'foo'})
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module SQLite3
|
4
|
+
class TestDatabaseReadonly < SQLite3::TestCase
|
5
|
+
def setup
|
6
|
+
File.unlink 'test-readonly.db' if File.exist?('test-readonly.db')
|
7
|
+
@db = SQLite3::Database.new('test-readonly.db')
|
8
|
+
@db.execute("CREATE TABLE foos (id integer)")
|
9
|
+
@db.close
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@db.close unless @db.closed?
|
14
|
+
File.unlink 'test-readonly.db' if File.exist?('test-readonly.db')
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_open_readonly_database
|
18
|
+
@db = SQLite3::Database.new('test-readonly.db', :readonly => true)
|
19
|
+
assert @db.readonly?
|
20
|
+
end
|
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
|
+
|
29
|
+
def test_insert_readonly_database
|
30
|
+
@db = SQLite3::Database.new('test-readonly.db', :readonly => true)
|
31
|
+
assert_raise(SQLite3::ReadOnlyException) do
|
32
|
+
@db.execute("INSERT INTO foos (id) VALUES (12)")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module SQLite3
|
4
|
+
class TestDeprecated < SQLite3::TestCase
|
5
|
+
attr_reader :db
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
@warn_before = $-w
|
10
|
+
$-w = false
|
11
|
+
@db = SQLite3::Database.new(':memory:')
|
12
|
+
@db.execute 'CREATE TABLE test_table (name text, age int)'
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
super
|
17
|
+
$-w = @warn_before
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_query_with_many_bind_params_not_nil
|
21
|
+
assert_equal [[1, 2]], db.query('select ?, ?', 1, 2).to_a
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_execute_with_many_bind_params_not_nil
|
25
|
+
assert_equal [[1, 2]], @db.execute("select ?, ?", 1, 2).to_a
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_query_with_many_bind_params
|
29
|
+
assert_equal [[nil, 1]], @db.query("select ?, ?", nil, 1).to_a
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_query_with_nil_bind_params
|
33
|
+
assert_equal [['foo']], @db.query("select 'foo'", nil).to_a
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_execute_with_many_bind_params
|
37
|
+
assert_equal [[nil, 1]], @db.execute("select ?, ?", nil, 1)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_execute_with_nil_bind_params
|
41
|
+
assert_equal [['foo']], @db.execute("select 'foo'", nil)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
module SQLite3
|
6
|
+
class TestEncoding < SQLite3::TestCase
|
7
|
+
def setup
|
8
|
+
@db = SQLite3::Database.new(':memory:')
|
9
|
+
@create = "create table ex(id int, data string)"
|
10
|
+
@insert = "insert into ex(id, data) values (?, ?)"
|
11
|
+
@db.execute(@create);
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_select_encoding_on_utf_16
|
15
|
+
str = "foo"
|
16
|
+
utf16 = ([1].pack("I") == [1].pack("N")) ? "UTF-16BE" : "UTF-16LE"
|
17
|
+
db = SQLite3::Database.new(':memory:'.encode(utf16))
|
18
|
+
db.execute @create
|
19
|
+
db.execute "insert into ex (id, data) values (1, \"#{str}\")"
|
20
|
+
|
21
|
+
stmt = db.prepare 'select * from ex where data = ?'
|
22
|
+
['US-ASCII', utf16, 'EUC-JP', 'UTF-8'].each do |enc|
|
23
|
+
stmt.bind_param 1, str.encode(enc)
|
24
|
+
assert_equal 1, stmt.to_a.length
|
25
|
+
stmt.reset!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_insert_encoding
|
30
|
+
str = "foo"
|
31
|
+
utf16 = ([1].pack("I") == [1].pack("N")) ? "UTF-16BE" : "UTF-16LE"
|
32
|
+
db = SQLite3::Database.new(':memory:'.encode(utf16))
|
33
|
+
db.execute @create
|
34
|
+
stmt = db.prepare @insert
|
35
|
+
|
36
|
+
['US-ASCII', utf16, 'EUC-JP', 'UTF-8'].each_with_index do |enc,i|
|
37
|
+
stmt.bind_param 1, i
|
38
|
+
stmt.bind_param 2, str.encode(enc)
|
39
|
+
stmt.to_a
|
40
|
+
stmt.reset!
|
41
|
+
end
|
42
|
+
|
43
|
+
db.execute('select data from ex').flatten.each do |s|
|
44
|
+
assert_equal str, s
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_default_internal_is_honored
|
49
|
+
warn_before = $-w
|
50
|
+
$-w = false
|
51
|
+
|
52
|
+
before_enc = Encoding.default_internal
|
53
|
+
|
54
|
+
str = "壁に耳あり、障子に目あり"
|
55
|
+
stmt = @db.prepare('insert into ex(data) values (?)')
|
56
|
+
stmt.bind_param 1, str
|
57
|
+
stmt.step
|
58
|
+
|
59
|
+
Encoding.default_internal = 'EUC-JP'
|
60
|
+
string = @db.execute('select data from ex').first.first
|
61
|
+
|
62
|
+
assert_equal Encoding.default_internal, string.encoding
|
63
|
+
assert_equal str.encode('EUC-JP'), string
|
64
|
+
assert_equal str, string.encode(str.encoding)
|
65
|
+
ensure
|
66
|
+
Encoding.default_internal = before_enc
|
67
|
+
$-w = warn_before
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_blob_is_binary
|
71
|
+
str = "猫舌"
|
72
|
+
@db.execute('create table foo(data text)')
|
73
|
+
stmt = @db.prepare('insert into foo(data) values (?)')
|
74
|
+
stmt.bind_param(1, SQLite3::Blob.new(str))
|
75
|
+
stmt.step
|
76
|
+
|
77
|
+
string = @db.execute('select data from foo').first.first
|
78
|
+
assert_equal Encoding.find('ASCII-8BIT'), string.encoding
|
79
|
+
assert_equal str, string.force_encoding('UTF-8')
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_blob_is_ascii8bit
|
83
|
+
str = "猫舌"
|
84
|
+
@db.execute('create table foo(data text)')
|
85
|
+
stmt = @db.prepare('insert into foo(data) values (?)')
|
86
|
+
stmt.bind_param(1, str.dup.force_encoding("ASCII-8BIT"))
|
87
|
+
stmt.step
|
88
|
+
|
89
|
+
string = @db.execute('select data from foo').first.first
|
90
|
+
assert_equal Encoding.find('ASCII-8BIT'), string.encoding
|
91
|
+
assert_equal str, string.force_encoding('UTF-8')
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_blob_with_eucjp
|
95
|
+
str = "猫舌".encode("EUC-JP")
|
96
|
+
@db.execute('create table foo(data text)')
|
97
|
+
stmt = @db.prepare('insert into foo(data) values (?)')
|
98
|
+
stmt.bind_param(1, SQLite3::Blob.new(str))
|
99
|
+
stmt.step
|
100
|
+
|
101
|
+
string = @db.execute('select data from foo').first.first
|
102
|
+
assert_equal Encoding.find('ASCII-8BIT'), string.encoding
|
103
|
+
assert_equal str, string.force_encoding('EUC-JP')
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_db_with_eucjp
|
107
|
+
db = SQLite3::Database.new(':memory:'.encode('EUC-JP'))
|
108
|
+
assert_equal(Encoding.find('UTF-8'), db.encoding)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_db_with_utf16
|
112
|
+
utf16 = ([1].pack("I") == [1].pack("N")) ? "UTF-16BE" : "UTF-16LE"
|
113
|
+
|
114
|
+
db = SQLite3::Database.new(':memory:'.encode(utf16))
|
115
|
+
assert_equal(Encoding.find(utf16), db.encoding)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_statement_eucjp
|
119
|
+
str = "猫舌"
|
120
|
+
@db.execute("insert into ex(data) values ('#{str}')".encode('EUC-JP'))
|
121
|
+
row = @db.execute("select data from ex")
|
122
|
+
assert_equal @db.encoding, row.first.first.encoding
|
123
|
+
assert_equal str, row.first.first
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_statement_utf8
|
127
|
+
str = "猫舌"
|
128
|
+
@db.execute("insert into ex(data) values ('#{str}')")
|
129
|
+
row = @db.execute("select data from ex")
|
130
|
+
assert_equal @db.encoding, row.first.first.encoding
|
131
|
+
assert_equal str, row.first.first
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_encoding
|
135
|
+
assert_equal Encoding.find("UTF-8"), @db.encoding
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_utf_8
|
139
|
+
str = "猫舌"
|
140
|
+
@db.execute(@insert, [10, str])
|
141
|
+
row = @db.execute("select data from ex")
|
142
|
+
assert_equal @db.encoding, row.first.first.encoding
|
143
|
+
assert_equal str, row.first.first
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_euc_jp
|
147
|
+
str = "猫舌".encode('EUC-JP')
|
148
|
+
@db.execute(@insert, [10, str])
|
149
|
+
row = @db.execute("select data from ex")
|
150
|
+
assert_equal @db.encoding, row.first.first.encoding
|
151
|
+
assert_equal str.encode('UTF-8'), row.first.first
|
152
|
+
end
|
153
|
+
|
154
|
+
end if RUBY_VERSION >= '1.9.1'
|
155
|
+
end
|