mockley_crew 1.1.9 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mockley_crew/version.rb +1 -1
  3. data/lib/mockley_crew.rb +2 -1
  4. metadata +1 -67
  5. data/vendor/gems/sqlite3/cache/sqlite3-1.3.13.gem +0 -0
  6. data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/gem.build_complete +0 -0
  7. data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/gem_make.out +0 -33
  8. data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/mkmf.log +0 -592
  9. data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/sqlite3/sqlite3_native.so +0 -0
  10. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/API_CHANGES.rdoc +0 -50
  11. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/CHANGELOG.rdoc +0 -292
  12. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ChangeLog.cvs +0 -88
  13. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/Gemfile +0 -15
  14. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/LICENSE +0 -27
  15. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/Manifest.txt +0 -52
  16. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/README.rdoc +0 -118
  17. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/Rakefile +0 -10
  18. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/Makefile +0 -263
  19. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/backup.c +0 -168
  20. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/backup.h +0 -15
  21. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/backup.o +0 -0
  22. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/database.c +0 -888
  23. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/database.h +0 -15
  24. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/database.o +0 -0
  25. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/exception.c +0 -94
  26. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/exception.h +0 -8
  27. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/exception.o +0 -0
  28. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/extconf.rb +0 -71
  29. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3.c +0 -152
  30. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3.o +0 -0
  31. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3_native.so +0 -0
  32. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3_ruby.h +0 -52
  33. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/statement.c +0 -447
  34. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/statement.h +0 -16
  35. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/statement.o +0 -0
  36. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/faq/faq.rb +0 -145
  37. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/faq/faq.yml +0 -426
  38. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/constants.rb +0 -49
  39. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/database.rb +0 -591
  40. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/errors.rb +0 -44
  41. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/pragmas.rb +0 -588
  42. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/resultset.rb +0 -195
  43. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/sqlite3_native.so +0 -0
  44. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb +0 -144
  45. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/translator.rb +0 -118
  46. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/value.rb +0 -57
  47. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/version.rb +0 -25
  48. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3.rb +0 -15
  49. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/setup.rb +0 -1333
  50. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/faq.rake +0 -9
  51. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/gem.rake +0 -38
  52. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/native.rake +0 -52
  53. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/vendor_sqlite3.rake +0 -97
  54. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/helper.rb +0 -18
  55. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_backup.rb +0 -33
  56. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_collation.rb +0 -82
  57. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_database.rb +0 -430
  58. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_database_readonly.rb +0 -36
  59. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_deprecated.rb +0 -44
  60. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_encoding.rb +0 -155
  61. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration.rb +0 -576
  62. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_open_close.rb +0 -30
  63. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_pending.rb +0 -115
  64. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_resultset.rb +0 -159
  65. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_statement.rb +0 -194
  66. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_result_set.rb +0 -37
  67. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_sqlite3.rb +0 -21
  68. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_statement.rb +0 -260
  69. data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_statement_execute.rb +0 -35
  70. data/vendor/gems/sqlite3/specifications/sqlite3-1.3.13.gemspec +0 -56
@@ -1,576 +0,0 @@
1
- require 'helper'
2
-
3
- class TC_Database_Integration < SQLite3::TestCase
4
- def setup
5
- @db = SQLite3::Database.new(":memory:")
6
- @db.transaction do
7
- @db.execute "create table foo ( a integer primary key, b text )"
8
- @db.execute "insert into foo ( b ) values ( 'foo' )"
9
- @db.execute "insert into foo ( b ) values ( 'bar' )"
10
- @db.execute "insert into foo ( b ) values ( 'baz' )"
11
- end
12
- end
13
-
14
- def teardown
15
- @db.close
16
- end
17
-
18
- def test_table_info_with_type_translation_active
19
- assert_nothing_raised { @db.table_info("foo") }
20
- end
21
-
22
- def test_table_info_with_defaults_for_version_3_3_8_and_higher
23
- @db.transaction do
24
- @db.execute "create table defaults_test ( a string default NULL, b string default 'Hello', c string default '--- []\n' )"
25
- data = @db.table_info( "defaults_test" )
26
- assert_equal({"name" => "a", "type" => "string", "dflt_value" => nil, "notnull" => 0, "cid" => 0, "pk" => 0},
27
- data[0])
28
- assert_equal({"name" => "b", "type" => "string", "dflt_value" => "Hello", "notnull" => 0, "cid" => 1, "pk" => 0},
29
- data[1])
30
- assert_equal({"name" => "c", "type" => "string", "dflt_value" => "--- []\n", "notnull" => 0, "cid" => 2, "pk" => 0},
31
- data[2])
32
- end
33
- end
34
-
35
- def test_table_info_without_defaults_for_version_3_3_8_and_higher
36
- @db.transaction do
37
- @db.execute "create table no_defaults_test ( a integer default 1, b integer )"
38
- data = @db.table_info( "no_defaults_test" )
39
- assert_equal({"name" => "a", "type" => "integer", "dflt_value" => "1", "notnull" => 0, "cid" => 0, "pk" => 0},
40
- data[0])
41
- assert_equal({"name" => "b", "type" => "integer", "dflt_value" => nil, "notnull" => 0, "cid" => 1, "pk" => 0},
42
- data[1])
43
- end
44
- end
45
-
46
- def test_complete_fail
47
- assert !@db.complete?( "select * from foo" )
48
- end
49
- def test_complete_success
50
- assert @db.complete?( "select * from foo;" )
51
- end
52
-
53
- # FIXME: do people really need UTF16 sql statements?
54
- #def test_complete_fail_utf16
55
- # assert !@db.complete?( "select * from foo".to_utf16(false), true )
56
- #end
57
-
58
- # FIXME: do people really need UTF16 sql statements?
59
- #def test_complete_success_utf16
60
- # assert @db.complete?( "select * from foo;".to_utf16(true), true )
61
- #end
62
-
63
- def test_errmsg
64
- assert_equal "not an error", @db.errmsg
65
- end
66
-
67
- # FIXME: do people really need UTF16 error messages?
68
- #def test_errmsg_utf16
69
- # msg = Iconv.conv('UTF-16', 'UTF-8', 'not an error')
70
- # assert_equal msg, @db.errmsg(true)
71
- #end
72
-
73
- def test_errcode
74
- assert_equal 0, @db.errcode
75
- end
76
-
77
- def test_trace
78
- result = nil
79
- @db.trace { |sql| result = sql }
80
- @db.execute "select * from foo"
81
- assert_equal "select * from foo", result
82
- end
83
-
84
- def test_authorizer_okay
85
- @db.authorizer { |type,a,b,c,d| 0 }
86
- rows = @db.execute "select * from foo"
87
- assert_equal 3, rows.length
88
- end
89
-
90
- def test_authorizer_error
91
- @db.authorizer { |type,a,b,c,d| 1 }
92
- assert_raise( SQLite3::AuthorizationException ) do
93
- @db.execute "select * from foo"
94
- end
95
- end
96
-
97
- def test_authorizer_silent
98
- @db.authorizer { |type,a,b,c,d| 2 }
99
- rows = @db.execute "select * from foo"
100
- assert rows.empty?
101
- end
102
-
103
- def test_prepare_invalid_syntax
104
- assert_raise( SQLite3::SQLException ) do
105
- @db.prepare "select from foo"
106
- end
107
- end
108
-
109
- def test_prepare_invalid_column
110
- assert_raise( SQLite3::SQLException ) do
111
- @db.prepare "select k from foo"
112
- end
113
- end
114
-
115
- def test_prepare_invalid_table
116
- assert_raise( SQLite3::SQLException ) do
117
- @db.prepare "select * from barf"
118
- end
119
- end
120
-
121
- def test_prepare_no_block
122
- stmt = @db.prepare "select * from foo"
123
- assert stmt.respond_to?(:execute)
124
- stmt.close
125
- end
126
-
127
- def test_prepare_with_block
128
- called = false
129
- @db.prepare "select * from foo" do |stmt|
130
- called = true
131
- assert stmt.respond_to?(:execute)
132
- end
133
- assert called
134
- end
135
-
136
- def test_execute_no_block_no_bind_no_match
137
- rows = @db.execute( "select * from foo where a > 100" )
138
- assert rows.empty?
139
- end
140
-
141
- def test_execute_with_block_no_bind_no_match
142
- called = false
143
- @db.execute( "select * from foo where a > 100" ) do |row|
144
- called = true
145
- end
146
- assert !called
147
- end
148
-
149
- def test_execute_no_block_with_bind_no_match
150
- rows = @db.execute( "select * from foo where a > ?", 100 )
151
- assert rows.empty?
152
- end
153
-
154
- def test_execute_with_block_with_bind_no_match
155
- called = false
156
- @db.execute( "select * from foo where a > ?", 100 ) do |row|
157
- called = true
158
- end
159
- assert !called
160
- end
161
-
162
- def test_execute_no_block_no_bind_with_match
163
- rows = @db.execute( "select * from foo where a = 1" )
164
- assert_equal 1, rows.length
165
- end
166
-
167
- def test_execute_with_block_no_bind_with_match
168
- called = 0
169
- @db.execute( "select * from foo where a = 1" ) do |row|
170
- called += 1
171
- end
172
- assert_equal 1, called
173
- end
174
-
175
- def test_execute_no_block_with_bind_with_match
176
- rows = @db.execute( "select * from foo where a = ?", 1 )
177
- assert_equal 1, rows.length
178
- end
179
-
180
- def test_execute_with_block_with_bind_with_match
181
- called = 0
182
- @db.execute( "select * from foo where a = ?", 1 ) do |row|
183
- called += 1
184
- end
185
- assert_equal 1, called
186
- end
187
-
188
- def test_execute2_no_block_no_bind_no_match
189
- columns, *rows = @db.execute2( "select * from foo where a > 100" )
190
- assert rows.empty?
191
- assert_equal [ "a", "b" ], columns
192
- end
193
-
194
- def test_execute2_with_block_no_bind_no_match
195
- called = 0
196
- @db.execute2( "select * from foo where a > 100" ) do |row|
197
- assert [ "a", "b" ], row unless called == 0
198
- called += 1
199
- end
200
- assert_equal 1, called
201
- end
202
-
203
- def test_execute2_no_block_with_bind_no_match
204
- columns, *rows = @db.execute2( "select * from foo where a > ?", 100 )
205
- assert rows.empty?
206
- assert_equal [ "a", "b" ], columns
207
- end
208
-
209
- def test_execute2_with_block_with_bind_no_match
210
- called = 0
211
- @db.execute2( "select * from foo where a > ?", 100 ) do |row|
212
- assert_equal [ "a", "b" ], row unless called == 0
213
- called += 1
214
- end
215
- assert_equal 1, called
216
- end
217
-
218
- def test_execute2_no_block_no_bind_with_match
219
- columns, *rows = @db.execute2( "select * from foo where a = 1" )
220
- assert_equal 1, rows.length
221
- assert_equal [ "a", "b" ], columns
222
- end
223
-
224
- def test_execute2_with_block_no_bind_with_match
225
- called = 0
226
- @db.execute2( "select * from foo where a = 1" ) do |row|
227
- assert_equal [ 1, "foo" ], row unless called == 0
228
- called += 1
229
- end
230
- assert_equal 2, called
231
- end
232
-
233
- def test_execute2_no_block_with_bind_with_match
234
- columns, *rows = @db.execute2( "select * from foo where a = ?", 1 )
235
- assert_equal 1, rows.length
236
- assert_equal [ "a", "b" ], columns
237
- end
238
-
239
- def test_execute2_with_block_with_bind_with_match
240
- called = 0
241
- @db.execute2( "select * from foo where a = ?", 1 ) do
242
- called += 1
243
- end
244
- assert_equal 2, called
245
- end
246
-
247
- def test_execute_batch_empty
248
- assert_nothing_raised { @db.execute_batch "" }
249
- end
250
-
251
- def test_execute_batch_no_bind
252
- @db.transaction do
253
- @db.execute_batch <<-SQL
254
- create table bar ( a, b, c );
255
- insert into bar values ( 'one', 2, 'three' );
256
- insert into bar values ( 'four', 5, 'six' );
257
- insert into bar values ( 'seven', 8, 'nine' );
258
- SQL
259
- end
260
- rows = @db.execute( "select * from bar" )
261
- assert_equal 3, rows.length
262
- end
263
-
264
- def test_execute_batch_with_bind
265
- @db.execute_batch( <<-SQL, [1] )
266
- create table bar ( a, b, c );
267
- insert into bar values ( 'one', 2, ? );
268
- insert into bar values ( 'four', 5, ? );
269
- insert into bar values ( 'seven', 8, ? );
270
- SQL
271
- rows = @db.execute( "select * from bar" ).map { |a,b,c| c }
272
- assert_equal [1, 1, 1], rows
273
- end
274
-
275
- def test_query_no_block_no_bind_no_match
276
- result = @db.query( "select * from foo where a > 100" )
277
- assert_nil result.next
278
- result.close
279
- end
280
-
281
- def test_query_with_block_no_bind_no_match
282
- r = nil
283
- @db.query( "select * from foo where a > 100" ) do |result|
284
- assert_nil result.next
285
- r = result
286
- end
287
- assert r.closed?
288
- end
289
-
290
- def test_query_no_block_with_bind_no_match
291
- result = @db.query( "select * from foo where a > ?", 100 )
292
- assert_nil result.next
293
- result.close
294
- end
295
-
296
- def test_query_with_block_with_bind_no_match
297
- r = nil
298
- @db.query( "select * from foo where a > ?", 100 ) do |result|
299
- assert_nil result.next
300
- r = result
301
- end
302
- assert r.closed?
303
- end
304
-
305
- def test_query_no_block_no_bind_with_match
306
- result = @db.query( "select * from foo where a = 1" )
307
- assert_not_nil result.next
308
- assert_nil result.next
309
- result.close
310
- end
311
-
312
- def test_query_with_block_no_bind_with_match
313
- r = nil
314
- @db.query( "select * from foo where a = 1" ) do |result|
315
- assert_not_nil result.next
316
- assert_nil result.next
317
- r = result
318
- end
319
- assert r.closed?
320
- end
321
-
322
- def test_query_no_block_with_bind_with_match
323
- result = @db.query( "select * from foo where a = ?", 1 )
324
- assert_not_nil result.next
325
- assert_nil result.next
326
- result.close
327
- end
328
-
329
- def test_query_with_block_with_bind_with_match
330
- r = nil
331
- @db.query( "select * from foo where a = ?", 1 ) do |result|
332
- assert_not_nil result.next
333
- assert_nil result.next
334
- r = result
335
- end
336
- assert r.closed?
337
- end
338
-
339
- def test_get_first_row_no_bind_no_match
340
- result = @db.get_first_row( "select * from foo where a=100" )
341
- assert_nil result
342
- end
343
-
344
- def test_get_first_row_no_bind_with_match
345
- result = @db.get_first_row( "select * from foo where a=1" )
346
- assert_equal [ 1, "foo" ], result
347
- end
348
-
349
- def test_get_first_row_with_bind_no_match
350
- result = @db.get_first_row( "select * from foo where a=?", 100 )
351
- assert_nil result
352
- end
353
-
354
- def test_get_first_row_with_bind_with_match
355
- result = @db.get_first_row( "select * from foo where a=?", 1 )
356
- assert_equal [ 1, "foo" ], result
357
- end
358
-
359
- def test_get_first_value_no_bind_no_match
360
- result = @db.get_first_value( "select b, a from foo where a=100" )
361
- assert_nil result
362
- end
363
-
364
- def test_get_first_value_no_bind_with_match
365
- result = @db.get_first_value( "select b, a from foo where a=1" )
366
- assert_equal "foo", result
367
- end
368
-
369
- def test_get_first_value_with_bind_no_match
370
- result = @db.get_first_value( "select b, a from foo where a=?", 100 )
371
- assert_nil result
372
- end
373
-
374
- def test_get_first_value_with_bind_with_match
375
- result = @db.get_first_value( "select b, a from foo where a=?", 1 )
376
- assert_equal "foo", result
377
- end
378
-
379
- def test_last_insert_row_id
380
- @db.execute "insert into foo ( b ) values ( 'test' )"
381
- assert_equal 4, @db.last_insert_row_id
382
- @db.execute "insert into foo ( b ) values ( 'again' )"
383
- assert_equal 5, @db.last_insert_row_id
384
- end
385
-
386
- def test_changes
387
- @db.execute "insert into foo ( b ) values ( 'test' )"
388
- assert_equal 1, @db.changes
389
- @db.execute "delete from foo where 1=1"
390
- assert_equal 4, @db.changes
391
- end
392
-
393
- def test_total_changes
394
- assert_equal 3, @db.total_changes
395
- @db.execute "insert into foo ( b ) values ( 'test' )"
396
- @db.execute "delete from foo where 1=1"
397
- assert_equal 8, @db.total_changes
398
- end
399
-
400
- def test_transaction_nest
401
- assert_raise( SQLite3::SQLException ) do
402
- @db.transaction do
403
- @db.transaction do
404
- end
405
- end
406
- end
407
- end
408
-
409
- def test_transaction_rollback
410
- @db.transaction
411
- @db.execute_batch <<-SQL
412
- insert into foo (b) values ( 'test1' );
413
- insert into foo (b) values ( 'test2' );
414
- insert into foo (b) values ( 'test3' );
415
- insert into foo (b) values ( 'test4' );
416
- SQL
417
- assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
418
- @db.rollback
419
- assert_equal 3, @db.get_first_value("select count(*) from foo").to_i
420
- end
421
-
422
- def test_transaction_commit
423
- @db.transaction
424
- @db.execute_batch <<-SQL
425
- insert into foo (b) values ( 'test1' );
426
- insert into foo (b) values ( 'test2' );
427
- insert into foo (b) values ( 'test3' );
428
- insert into foo (b) values ( 'test4' );
429
- SQL
430
- assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
431
- @db.commit
432
- assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
433
- end
434
-
435
- def test_transaction_rollback_in_block
436
- assert_raise( SQLite3::SQLException ) do
437
- @db.transaction do
438
- @db.rollback
439
- end
440
- end
441
- end
442
-
443
- def test_transaction_commit_in_block
444
- assert_raise( SQLite3::SQLException ) do
445
- @db.transaction do
446
- @db.commit
447
- end
448
- end
449
- end
450
-
451
- def test_transaction_active
452
- assert !@db.transaction_active?
453
- @db.transaction
454
- assert @db.transaction_active?
455
- @db.commit
456
- assert !@db.transaction_active?
457
- end
458
-
459
- def test_transaction_implicit_rollback
460
- assert !@db.transaction_active?
461
- @db.transaction
462
- @db.execute('create table bar (x CHECK(1 = 0))')
463
- assert @db.transaction_active?
464
- assert_raises( SQLite3::ConstraintException ) do
465
- @db.execute("insert or rollback into bar (x) VALUES ('x')")
466
- end
467
- assert !@db.transaction_active?
468
- end
469
-
470
- def test_interrupt
471
- @db.create_function( "abort", 1 ) do |func,x|
472
- @db.interrupt
473
- func.result = x
474
- end
475
-
476
- assert_raise( SQLite3::InterruptException ) do
477
- @db.execute "select abort(a) from foo"
478
- end
479
- end
480
-
481
- def test_create_function
482
- @db.create_function( "munge", 1 ) do |func,x|
483
- func.result = ">>>#{x}<<<"
484
- end
485
-
486
- value = @db.get_first_value( "select munge(b) from foo where a=1" )
487
- assert_match( />>>.*<<</, value )
488
- end
489
-
490
- def test_create_aggregate_without_block
491
- step = proc do |ctx,a|
492
- ctx[:sum] ||= 0
493
- ctx[:sum] += a.to_i
494
- end
495
-
496
- final = proc { |ctx| ctx.result = ctx[:sum] }
497
-
498
- @db.create_aggregate( "accumulate", 1, step, final )
499
-
500
- value = @db.get_first_value( "select accumulate(a) from foo" )
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
506
- end
507
-
508
- def test_create_aggregate_with_block
509
- @db.create_aggregate( "accumulate", 1 ) do
510
- step do |ctx,a|
511
- ctx[:sum] ||= 0
512
- ctx[:sum] += a.to_i
513
- end
514
-
515
- finalize { |ctx| ctx.result = ctx[:sum] }
516
- end
517
-
518
- value = @db.get_first_value( "select accumulate(a) from foo" )
519
- assert_equal 6, value
520
- end
521
-
522
- def test_create_aggregate_with_no_data
523
- @db.create_aggregate( "accumulate", 1 ) do
524
- step do |ctx,a|
525
- ctx[:sum] ||= 0
526
- ctx[:sum] += a.to_i
527
- end
528
-
529
- finalize { |ctx| ctx.result = ctx[:sum] || 0 }
530
- end
531
-
532
- value = @db.get_first_value(
533
- "select accumulate(a) from foo where a = 100" )
534
- assert_equal 0, value
535
- end
536
-
537
- class AggregateHandler
538
- class << self
539
- def arity; 1; end
540
- def text_rep; SQLite3::Constants::TextRep::ANY; end
541
- def name; "multiply"; end
542
- end
543
- def step(ctx, a)
544
- ctx[:buffer] ||= 1
545
- ctx[:buffer] *= a.to_i
546
- end
547
- def finalize(ctx); ctx.result = ctx[:buffer]; end
548
- end
549
-
550
- def test_aggregate_initialized_twice
551
- initialized = 0
552
- handler = Class.new(AggregateHandler) do
553
- define_method(:initialize) do
554
- initialized += 1
555
- super()
556
- end
557
- end
558
-
559
- @db.create_aggregate_handler handler
560
- @db.get_first_value( "select multiply(a) from foo" )
561
- @db.get_first_value( "select multiply(a) from foo" )
562
- assert_equal 2, initialized
563
- end
564
-
565
- def test_create_aggregate_handler
566
- @db.create_aggregate_handler AggregateHandler
567
- value = @db.get_first_value( "select multiply(a) from foo" )
568
- assert_equal 6, value
569
- end
570
-
571
- def test_bind_array_parameter
572
- result = @db.get_first_value( "select b from foo where a=? and b=?",
573
- [ 1, "foo" ] )
574
- assert_equal "foo", result
575
- end
576
- end
@@ -1,30 +0,0 @@
1
- require 'helper'
2
-
3
- class TC_OpenClose < SQLite3::TestCase
4
- def test_create_close
5
- begin
6
- db = SQLite3::Database.new( "test-create.db" )
7
- assert File.exist?( "test-create.db" )
8
- assert_nothing_raised { db.close }
9
- ensure
10
- File.delete( "test-create.db" ) rescue nil
11
- end
12
- end
13
-
14
- def test_open_close
15
- begin
16
- File.open( "test-open.db", "w" ) { |f| }
17
- assert File.exist?( "test-open.db" )
18
- db = SQLite3::Database.new( "test-open.db" )
19
- assert_nothing_raised { db.close }
20
- ensure
21
- File.delete( "test-open.db" ) rescue nil
22
- end
23
- end
24
-
25
- def test_bad_open
26
- assert_raise( SQLite3::CantOpenException ) do
27
- SQLite3::Database.new( "." )
28
- end
29
- end
30
- end
@@ -1,115 +0,0 @@
1
- require 'helper'
2
-
3
- require 'thread'
4
- require 'benchmark'
5
-
6
- class TC_Integration_Pending < SQLite3::TestCase
7
- def setup
8
- @db = SQLite3::Database.new("test.db")
9
- @db.transaction do
10
- @db.execute "create table foo ( a integer primary key, b text )"
11
- @db.execute "insert into foo ( b ) values ( 'foo' )"
12
- @db.execute "insert into foo ( b ) values ( 'bar' )"
13
- @db.execute "insert into foo ( b ) values ( 'baz' )"
14
- end
15
- end
16
-
17
- def teardown
18
- @db.close
19
- File.delete( "test.db" )
20
- end
21
-
22
- def test_busy_handler_outwait
23
- skip("not working in 1.9") if RUBY_VERSION >= '1.9'
24
-
25
- busy = Mutex.new
26
- busy.lock
27
- handler_call_count = 0
28
-
29
- t = Thread.new(busy) do |locker|
30
- begin
31
- db2 = SQLite3::Database.open( "test.db" )
32
- db2.transaction( :exclusive ) do
33
- locker.lock
34
- end
35
- ensure
36
- db2.close if db2
37
- end
38
- end
39
-
40
- @db.busy_handler do |data,count|
41
- handler_call_count += 1
42
- busy.unlock
43
- true
44
- end
45
-
46
- assert_nothing_raised do
47
- @db.execute "insert into foo (b) values ( 'from 2' )"
48
- end
49
-
50
- t.join
51
-
52
- assert_equal 1, handler_call_count
53
- end
54
-
55
- def test_busy_handler_impatient
56
- busy = Mutex.new
57
- busy.lock
58
- handler_call_count = 0
59
-
60
- t = Thread.new do
61
- begin
62
- db2 = SQLite3::Database.open( "test.db" )
63
- db2.transaction( :exclusive ) do
64
- busy.lock
65
- end
66
- ensure
67
- db2.close if db2
68
- end
69
- end
70
- sleep 1
71
-
72
- @db.busy_handler do
73
- handler_call_count += 1
74
- false
75
- end
76
-
77
- assert_raise( SQLite3::BusyException ) do
78
- @db.execute "insert into foo (b) values ( 'from 2' )"
79
- end
80
-
81
- busy.unlock
82
- t.join
83
-
84
- assert_equal 1, handler_call_count
85
- end
86
-
87
- def test_busy_timeout
88
- @db.busy_timeout 1000
89
- busy = Mutex.new
90
- busy.lock
91
-
92
- t = Thread.new do
93
- begin
94
- db2 = SQLite3::Database.open( "test.db" )
95
- db2.transaction( :exclusive ) do
96
- busy.lock
97
- end
98
- ensure
99
- db2.close if db2
100
- end
101
- end
102
-
103
- sleep 1
104
- time = Benchmark.measure do
105
- assert_raise( SQLite3::BusyException ) do
106
- @db.execute "insert into foo (b) values ( 'from 2' )"
107
- end
108
- end
109
-
110
- busy.unlock
111
- t.join
112
-
113
- assert time.real*1000 >= 1000
114
- end
115
- end