Class: SQLite3::TestDatabase

Inherits:
TestCase
  • Object
show all
Defined in:
lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb,
lib/sqlite3-1.5.3-x86_64-darwin/test/test_database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TestCase

#assert_nothing_raised

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



7
8
9
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 7

def db
  @db
end

Instance Method Details

#setupObject



9
10
11
12
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 9

def setup
  @db = SQLite3::Database.new(':memory:')
  super
end

#test_authorizer_failObject



481
482
483
484
485
486
487
488
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 481

def test_authorizer_fail
  @db.authorizer = Class.new {
    def call action, a, b, c, d; false end
  }.new
  assert_raises(SQLite3::AuthorizationException) do
    @db.prepare("select 'fooooo'")
  end
end

#test_authorizer_ignoreObject



473
474
475
476
477
478
479
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 473

def test_authorizer_ignore
  @db.authorizer = Class.new {
    def call action, a, b, c, d; nil end
  }.new
  stmt = @db.prepare("select 'fooooo'")
  assert_nil stmt.step
end

#test_authorizer_okObject



461
462
463
464
465
466
467
468
469
470
471
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 461

def test_authorizer_ok
  @db.authorizer = Class.new {
    def call action, a, b, c, d; true end
  }.new
  @db.prepare("select 'fooooo'")

  @db.authorizer = Class.new {
    def call action, a, b, c, d; 0 end
  }.new
  @db.prepare("select 'fooooo'")
end

#test_batch_last_comment_is_processedObject



128
129
130
131
132
133
134
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 128

def test_batch_last_comment_is_processed
  # FIXME: nil as a successful return value is kinda dumb
  assert_nil @db.execute_batch <<-eosql
    CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT);
    -- omg
  eosql
end

#test_bignumObject



78
79
80
81
82
83
84
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 78

def test_bignum
  num = 4907021672125087844
  db.execute 'CREATE TABLE "employees" ("token" integer(8), "name" varchar(20) NOT NULL)'
  db.execute "INSERT INTO employees(name, token) VALUES('employee-1', ?)", [num]
  rows = db.execute 'select token from employees'
  assert_equal num, rows.first.first
end

#test_blobObject



86
87
88
89
90
91
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 86

def test_blob
  @db.execute("CREATE TABLE blobs ( id INTEGER, hash BLOB(10) )")
  blob = Blob.new("foo\0bar")
  @db.execute("INSERT INTO blobs VALUES (0, ?)", [blob])
  assert_equal [[0, blob, blob.length, blob.length*2]], @db.execute("SELECT id, hash, length(hash), length(hex(hash)) FROM blobs")
end

#test_block_closes_selfObject



221
222
223
224
225
226
227
228
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 221

def test_block_closes_self
  thing = nil
  SQLite3::Database.new(':memory:') do |db|
    thing = db
    assert !thing.closed?
  end
  assert thing.closed?
end

#test_block_closes_self_even_raisedObject



230
231
232
233
234
235
236
237
238
239
240
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 230

def test_block_closes_self_even_raised
  thing = nil
  begin
    SQLite3::Database.new(':memory:') do |db|
      thing = db
      raise
    end
  rescue
  end
  assert thing.closed?
end

#test_block_prepare_does_not_double_closeObject



248
249
250
251
252
253
254
255
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 248

def test_block_prepare_does_not_double_close
  db = SQLite3::Database.new(':memory:')
  r = db.prepare('select "hello world"') do |stmt|
    stmt.close
    :foo
  end
  assert_equal :foo, r
end

#test_call_func_arg_typeObject



357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 357

def test_call_func_arg_type
  called_with = nil
  @db.define_function("hello") do |b, c, d|
    called_with = [b, c, d]
    nil
  end
  @db.execute("select hello(2.2, 'foo', NULL)")

  assert_in_delta(2.2, called_with[0], 0.0001)
  assert_equal("foo", called_with[1])
  assert_nil(called_with[2])
end

#test_call_func_blobObject



383
384
385
386
387
388
389
390
391
392
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 383

def test_call_func_blob
  called_with = nil
  @db.define_function("hello") do |a, b|
    called_with = [a, b, a.length]
    nil
  end
  blob = Blob.new("a\0fine\0kettle\0of\0fish")
  @db.execute("select hello(?, length(?))", [blob, blob])
  assert_equal [blob, blob.length, 21], called_with
end

#test_changesObject



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 116

def test_changes
  @db.execute("CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT, number integer)")
  assert_equal 0, @db.changes
  @db.execute("INSERT INTO items (number) VALUES (10)")
  assert_equal 1, @db.changes
  @db.execute_batch(
    "UPDATE items SET number = (number + :nn) WHERE (number = :n)",
    {"nn" => 20, "n" => 10})
  assert_equal 1, @db.changes
  assert_equal [[30]], @db.execute("select number from items")
end

#test_closeObject



215
216
217
218
219
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 215

def test_close
  db = SQLite3::Database.new(':memory:')
  db.close
  assert db.closed?
end

#test_close_with_open_statementsObject



502
503
504
505
506
507
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 502

def test_close_with_open_statements
  @db.prepare("select 'foo'")
  assert_raises(SQLite3::BusyException) do
    @db.close
  end
end

#test_db_filenameObject



18
19
20
21
22
23
24
25
26
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 18

def test_db_filename
  tf = nil
  assert_equal '', @db.filename('main')
  tf = Tempfile.new 'thing'
  @db = SQLite3::Database.new tf.path
  assert_equal File.realdirpath(tf.path), File.realdirpath(@db.filename('main'))
ensure
  tf.unlink if tf
end

#test_define_aggregateObject



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 438

def test_define_aggregate
  @db.execute "create table foo ( a integer primary key, b text )"
  @db.execute "insert into foo ( b ) values ( 'foo' )"
  @db.execute "insert into foo ( b ) values ( 'bar' )"
  @db.execute "insert into foo ( b ) values ( 'baz' )"

  acc = Class.new {
    attr_reader :sum
    alias :finalize :sum
    def initialize
      @sum = 0
    end

    def step a
      @sum += a
    end
  }.new

  @db.define_aggregator("accumulate", acc)
  value = @db.get_first_value( "select accumulate(a) from foo" )
  assert_equal 6, value
end

#test_define_functionObject



348
349
350
351
352
353
354
355
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 348

def test_define_function
  called_with = nil
  @db.define_function("hello") do |value|
    called_with = value
  end
  @db.execute("select hello(10)")
  assert_equal 10, called_with
end

#test_define_function_closedObject



424
425
426
427
428
429
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 424

def test_define_function_closed
  @db.close
  assert_raise(SQLite3::Exception) do
    @db.define_function('foo') {  }
  end
end

#test_define_varargsObject



370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 370

def test_define_varargs
  called_with = nil
  @db.define_function("hello") do |*args|
    called_with = args
    nil
  end
  @db.execute("select hello(2.2, 'foo', NULL)")

  assert_in_delta(2.2, called_with[0], 0.0001)
  assert_equal("foo", called_with[1])
  assert_nil(called_with[2])
end

#test_encodingObject



112
113
114
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 112

def test_encoding
  assert @db.encoding, 'database has encoding'
end

#test_error_codeObject



60
61
62
63
64
65
66
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 60

def test_error_code
  begin
    db.execute 'SELECT'
  rescue SQLite3::SQLException => e
  end
  assert_equal 1, e.code
end

#test_execute_batch2Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 136

def test_execute_batch2
  @db.results_as_hash = true
  return_value = @db.execute_batch2 <<-eosql
    CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT, name string);
    INSERT INTO items (name) VALUES ("foo");
    INSERT INTO items (name) VALUES ("bar");
    SELECT * FROM items;
    eosql
  assert_equal return_value, [{"id"=>"1","name"=>"foo"}, {"id"=>"2", "name"=>"bar"}]

  return_value = @db.execute_batch2('SELECT * FROM items;') do |result|
    result["id"] = result["id"].to_i
    result
  end
  assert_equal return_value, [{"id"=>1,"name"=>"foo"}, {"id"=>2, "name"=>"bar"}]

  return_value = @db.execute_batch2('INSERT INTO items (name) VALUES ("oof")')
  assert_equal return_value, []

  return_value = @db.execute_batch2(
   'CREATE TABLE employees (id integer PRIMARY KEY AUTOINCREMENT, name string, age integer(3));
    INSERT INTO employees (age) VALUES (30);
    INSERT INTO employees (age) VALUES (40);
    INSERT INTO employees (age) VALUES (20);
    SELECT age FROM employees;') do |result|
      result["age"] = result["age"].to_i
      result
    end
  assert_equal return_value, [{"age"=>30}, {"age"=>40}, {"age"=>20}]

  return_value = @db.execute_batch2('SELECT name FROM employees');
  assert_equal return_value, [{"name"=>nil}, {"name"=>nil}, {"name"=>nil}]

  @db.results_as_hash = false
  return_value = @db.execute_batch2(
    'CREATE TABLE managers (id integer PRIMARY KEY AUTOINCREMENT, age integer(3));
    INSERT INTO managers (age) VALUES (50);
    INSERT INTO managers (age) VALUES (60);
    SELECT id, age from managers;') do |result|
      result = result.map do |res|
        res.to_i
      end
      result
    end
  assert_equal return_value, [[1, 50], [2, 60]]

  assert_raises (RuntimeError) do
    # "names" is not a valid column
    @db.execute_batch2 'INSERT INTO items (names) VALUES ("bazz")'
  end

end

#test_execute_returns_list_of_hashObject



264
265
266
267
268
269
270
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 264

def test_execute_returns_list_of_hash
  db = SQLite3::Database.new(':memory:', :results_as_hash => true)
  db.execute("create table foo ( a integer primary key, b text )")
  db.execute("insert into foo (b) values ('hello')")
  rows = db.execute("select * from foo")
  assert_equal [{"a"=>1, "b"=>"hello"}], rows
end

#test_execute_with_empty_bind_paramsObject



509
510
511
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 509

def test_execute_with_empty_bind_params
  assert_equal [['foo']], @db.execute("select 'foo'", [])
end

#test_execute_with_named_bind_paramsObject



517
518
519
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 517

def test_execute_with_named_bind_params
  assert_equal [['foo']], @db.execute("select :n", {'n' => 'foo'})
end

#test_execute_with_type_translation_and_hashObject



103
104
105
106
107
108
109
110
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 103

def test_execute_with_type_translation_and_hash
  @db.results_as_hash = true
  @db.type_translation = true
  rows = []
  @db.execute('SELECT 1') { |row| rows << row }

  assert_equal({"1"=>1}, rows.first)
end

#test_execute_yields_hashObject



272
273
274
275
276
277
278
279
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 272

def test_execute_yields_hash
  db = SQLite3::Database.new(':memory:', :results_as_hash => true)
  db.execute("create table foo ( a integer primary key, b text )")
  db.execute("insert into foo (b) values ('hello')")
  db.execute("select * from foo") do |row|
    assert_equal({"a"=>1, "b"=>"hello"}, row)
  end
end

#test_extended_error_codeObject



68
69
70
71
72
73
74
75
76
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 68

def test_extended_error_code
  db.extended_result_codes = true
  db.execute 'CREATE TABLE "employees" ("token" integer NOT NULL)'
  begin
    db.execute 'INSERT INTO employees (token) VALUES (NULL)'
  rescue SQLite3::ConstraintException => e
  end
  assert_equal 1299, e.code
end

#test_filenameObject



28
29
30
31
32
33
34
35
36
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 28

def test_filename
  tf = nil
  assert_equal '', @db.filename
  tf = Tempfile.new 'thing'
  @db = SQLite3::Database.new tf.path
  assert_equal File.realdirpath(tf.path), File.realdirpath(@db.filename)
ensure
  tf.unlink if tf
end

#test_filename_to_pathObject



50
51
52
53
54
55
56
57
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 50

def test_filename_to_path
  tf = Tempfile.new 'thing'
  pn = Pathname tf.path
  db = SQLite3::Database.new pn
  assert_equal pn.realdirpath.to_s, File.realdirpath(db.filename)
ensure
  tf.close! if tf
end

#test_filename_with_attachmentObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 38

def test_filename_with_attachment
  tf = nil
  assert_equal '', @db.filename
  tf = Tempfile.new 'thing'
  @db.execute "ATTACH DATABASE '#{tf.path}' AS 'testing'"

  assert_equal File.realdirpath(tf.path), File.realdirpath(@db.filename('testing'))
ensure
  tf.unlink if tf
end

#test_function_gc_segfaultObject



406
407
408
409
410
411
412
413
414
415
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 406

def test_function_gc_segfault
  @db.create_function("bug", -1) { |func, *values| func.result = values.join }
  # With a lot of data and a lot of threads, try to induce a GC segfault.
  params = Array.new(127, "?" * 28000)
  proc = Proc.new {
    db.execute("select bug(#{Array.new(params.length, "?").join(",")})", params)
  }
  m = Mutex.new
  30.times.map { Thread.new { m.synchronize { proc.call } } }.each(&:join)
end

#test_function_returnObject



394
395
396
397
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 394

def test_function_return
  @db.define_function("hello") { |a| 10 }
  assert_equal [10], @db.execute("select hello('world')").first
end

#test_function_return_type_round_tripObject



417
418
419
420
421
422
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 417

def test_function_return_type_round_trip
  [10, 2.2, nil, "foo", Blob.new("foo\0bar")].each do |thing|
    @db.define_function("hello") { |a| a }
    assert_equal [thing], @db.execute("select hello(hello(?))", [thing]).first
  end
end

#test_function_return_typesObject



399
400
401
402
403
404
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 399

def test_function_return_types
  [10, 2.2, nil, "foo", Blob.new("foo\0bar")].each do |thing|
    @db.define_function("hello") { |a| thing }
    assert_equal [thing], @db.execute("select hello('world')").first
  end
end

#test_get_first_rowObject



93
94
95
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 93

def test_get_first_row
  assert_equal [1], @db.get_first_row('SELECT 1')
end

#test_get_first_row_with_type_translation_and_hash_resultsObject



97
98
99
100
101
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 97

def test_get_first_row_with_type_translation_and_hash_results
  @db.results_as_hash = true
  @db.type_translation = true
  assert_equal({"1"=>1}, @db.get_first_row('SELECT 1'))
end

#test_inerrupt_closedObject



431
432
433
434
435
436
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 431

def test_inerrupt_closed
  @db.close
  assert_raise(SQLite3::Exception) do
    @db.interrupt
  end
end

#test_last_insert_row_id_closedObject



341
342
343
344
345
346
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 341

def test_last_insert_row_id_closed
  @db.close
  assert_raise(SQLite3::Exception) do
    @db.last_insert_row_id
  end
end

#test_load_extension_with_nonstring_argumentObject



538
539
540
541
542
543
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 538

def test_load_extension_with_nonstring_argument
  db = SQLite3::Database.new(':memory:')
  skip("extensions are not enabled") unless db.respond_to?(:load_extension)
  assert_raises(TypeError) { db.load_extension(1) }
  assert_raises(TypeError) { db.load_extension(Pathname.new("foo.so")) }
end

#test_newObject



189
190
191
192
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 189

def test_new
  db = SQLite3::Database.new(':memory:')
  assert db
end

#test_new_with_optionsObject



202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 202

def test_new_with_options
  # determine if Ruby is running on Big Endian platform
  utf16 = ([1].pack("I") == [1].pack("N")) ? "UTF-16BE" : "UTF-16LE"

  if RUBY_VERSION >= "1.9"
    db = SQLite3::Database.new(':memory:'.encode(utf16), :utf16 => true)
  else
    db = SQLite3::Database.new(Iconv.conv(utf16, 'UTF-8', ':memory:'),
                               :utf16 => true)
  end
  assert db
end

#test_new_yields_selfObject



194
195
196
197
198
199
200
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 194

def test_new_yields_self
  thing = nil
  SQLite3::Database.new(':memory:') do |db|
    thing = db
  end
  assert_instance_of(SQLite3::Database, thing)
end

#test_prepareObject



242
243
244
245
246
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 242

def test_prepare
  db = SQLite3::Database.new(':memory:')
  stmt = db.prepare('select "hello world"')
  assert_instance_of(SQLite3::Statement, stmt)
end

#test_query_with_named_bind_paramsObject



513
514
515
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 513

def test_query_with_named_bind_params
  assert_equal [['foo']], @db.query("select :n", {'n' => 'foo'}).to_a
end

#test_remove_authObject



490
491
492
493
494
495
496
497
498
499
500
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 490

def test_remove_auth
  @db.authorizer = Class.new {
    def call action, a, b, c, d; false end
  }.new
  assert_raises(SQLite3::AuthorizationException) do
    @db.prepare("select 'fooooo'")
  end

  @db.authorizer = nil
  @db.prepare("select 'fooooo'")
end

#test_segvObject



14
15
16
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 14

def test_segv
  assert_raises { SQLite3::Database.new 1 }
end

#test_strict_modeObject



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 521

def test_strict_mode
  unless Gem::Requirement.new(">= 3.29.0").satisfied_by?(Gem::Version.new(SQLite3::SQLITE_VERSION))
    skip("strict mode feature not available in #{SQLite3::SQLITE_VERSION}")
  end

  db = SQLite3::Database.new(':memory:')
  db.execute('create table numbers (val int);')
  db.execute('create index index_numbers_nope ON numbers ("nope");') # nothing raised

  db = SQLite3::Database.new(':memory:', :strict => true)
  db.execute('create table numbers (val int);')
  error = assert_raises SQLite3::SQLException do
    db.execute('create index index_numbers_nope ON numbers ("nope");')
  end
  assert_includes error.message, "no such column: nope"
end

#test_table_infoObject



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 281

def test_table_info
  db = SQLite3::Database.new(':memory:', :results_as_hash => true)
  db.execute("create table foo ( a integer primary key, b text )")
  info = [{
    "name"       => "a",
    "pk"         => 1,
    "notnull"    => 0,
    "type"       => "integer",
    "dflt_value" => nil,
    "cid"        => 0
  },
  {
    "name"       => "b",
    "pk"         => 0,
    "notnull"    => 0,
    "type"       => "text",
    "dflt_value" => nil,
    "cid"        => 1
  }]
  assert_equal info, db.table_info('foo')
end

#test_total_changesObject



257
258
259
260
261
262
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 257

def test_total_changes
  db = SQLite3::Database.new(':memory:')
  db.execute("create table foo ( a integer primary key, b text )")
  db.execute("insert into foo (b) values ('hello')")
  assert_equal 1, db.total_changes
end

#test_total_changes_closedObject



303
304
305
306
307
308
309
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 303

def test_total_changes_closed
  db = SQLite3::Database.new(':memory:')
  db.close
  assert_raise(SQLite3::Exception) do
    db.total_changes
  end
end

#test_trace_requires_opendbObject



311
312
313
314
315
316
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 311

def test_trace_requires_opendb
  @db.close
  assert_raise(SQLite3::Exception) do
    @db.trace { |x| }
  end
end

#test_trace_takes_nilObject



336
337
338
339
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 336

def test_trace_takes_nil
  @db.trace(nil)
  @db.execute "select 'foo'"
end

#test_trace_with_blockObject



318
319
320
321
322
323
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 318

def test_trace_with_block
  result = nil
  @db.trace { |sql| result = sql }
  @db.execute "select 'foo'"
  assert_equal "select 'foo'", result
end

#test_trace_with_objectObject



325
326
327
328
329
330
331
332
333
334
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb', line 325

def test_trace_with_object
  obj = Class.new {
    attr_accessor :result
    def call sql; @result = sql end
  }.new

  @db.trace(obj)
  @db.execute "select 'foo'"
  assert_equal "select 'foo'", obj.result
end