Class: TC_Database_Integration

Inherits:
SQLite3::TestCase show all
Defined in:
lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb,
lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration.rb

Instance Method Summary collapse

Methods inherited from SQLite3::TestCase

#assert_nothing_raised

Instance Method Details

#setupObject



4
5
6
7
8
9
10
11
12
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 4

def setup
  @db = SQLite3::Database.new(":memory:")
  @db.transaction do
    @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' )"
  end
end

#teardownObject



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

def teardown
  @db.close
end

#test_authorizer_errorObject



90
91
92
93
94
95
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 90

def test_authorizer_error
  @db.authorizer { |type,a,b,c,d| 1 }
  assert_raise( SQLite3::AuthorizationException ) do
    @db.execute "select * from foo"
  end
end

#test_authorizer_okayObject



84
85
86
87
88
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 84

def test_authorizer_okay
  @db.authorizer { |type,a,b,c,d| 0 }
  rows = @db.execute "select * from foo"
  assert_equal 3, rows.length
end

#test_authorizer_silentObject



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

def test_authorizer_silent
  @db.authorizer { |type,a,b,c,d| 2 }
  rows = @db.execute "select * from foo"
  assert rows.empty?
end

#test_bind_array_parameterObject



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

def test_bind_array_parameter
  result = @db.get_first_value( "select b from foo where a=? and b=?",
    [ 1, "foo" ] )
  assert_equal "foo", result
end

#test_changesObject



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

def test_changes
  @db.execute "insert into foo ( b ) values ( 'test' )"
  assert_equal 1, @db.changes
  @db.execute "delete from foo where 1=1"
  assert_equal 4, @db.changes
end

#test_complete_failObject



46
47
48
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 46

def test_complete_fail
  assert !@db.complete?( "select * from foo" )
end

#test_complete_successObject



49
50
51
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 49

def test_complete_success
  assert @db.complete?( "select * from foo;" )
end

#test_create_functionObject



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

def test_create_function
  @db.create_function( "munge", 1 ) do |func,x|
    func.result = ">>>#{x}<<<"
  end

  value = @db.get_first_value( "select munge(b) from foo where a=1" )
  assert_match( />>>.*<<</, value )
end

#test_errcodeObject

FIXME: do people really need UTF16 error messages? def test_errmsg_utf16

msg = Iconv.conv('UTF-16', 'UTF-8', 'not an error')
assert_equal msg, @db.errmsg(true)

end



73
74
75
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 73

def test_errcode
  assert_equal 0, @db.errcode
end

#test_errmsgObject

FIXME: do people really need UTF16 sql statements? def test_complete_success_utf16

assert @db.complete?( "select * from foo;".to_utf16(true), true )

end



63
64
65
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 63

def test_errmsg
  assert_equal "not an error", @db.errmsg
end

#test_execute2_no_block_no_bind_no_matchObject



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

def test_execute2_no_block_no_bind_no_match
  columns, *rows = @db.execute2( "select * from foo where a > 100" )
  assert rows.empty?
  assert_equal [ "a", "b" ], columns
end

#test_execute2_no_block_no_bind_with_matchObject



218
219
220
221
222
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 218

def test_execute2_no_block_no_bind_with_match
  columns, *rows = @db.execute2( "select * from foo where a = 1" )
  assert_equal 1, rows.length
  assert_equal [ "a", "b" ], columns
end

#test_execute2_no_block_with_bind_no_matchObject



203
204
205
206
207
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 203

def test_execute2_no_block_with_bind_no_match
  columns, *rows = @db.execute2( "select * from foo where a > ?", 100 )
  assert rows.empty?
  assert_equal [ "a", "b" ], columns
end

#test_execute2_no_block_with_bind_with_matchObject



233
234
235
236
237
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 233

def test_execute2_no_block_with_bind_with_match
  columns, *rows = @db.execute2( "select * from foo where a = ?", 1 )
  assert_equal 1, rows.length
  assert_equal [ "a", "b" ], columns
end

#test_execute2_with_block_no_bind_no_matchObject



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

def test_execute2_with_block_no_bind_no_match
  called = 0
  @db.execute2( "select * from foo where a > 100" ) do |row|
    assert [ "a", "b" ], row unless called == 0
    called += 1
  end
  assert_equal 1, called
end

#test_execute2_with_block_no_bind_with_matchObject



224
225
226
227
228
229
230
231
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 224

def test_execute2_with_block_no_bind_with_match
  called = 0
  @db.execute2( "select * from foo where a = 1" ) do |row|
    assert_equal [ 1, "foo" ], row unless called == 0
    called += 1
  end
  assert_equal 2, called
end

#test_execute2_with_block_with_bind_no_matchObject



209
210
211
212
213
214
215
216
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 209

def test_execute2_with_block_with_bind_no_match
  called = 0
  @db.execute2( "select * from foo where a > ?", 100 ) do |row|
    assert_equal [ "a", "b" ], row unless called == 0
    called += 1
  end
  assert_equal 1, called
end

#test_execute2_with_block_with_bind_with_matchObject



239
240
241
242
243
244
245
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 239

def test_execute2_with_block_with_bind_with_match
  called = 0
  @db.execute2( "select * from foo where a = ?", 1 ) do
    called += 1
  end
  assert_equal 2, called
end

#test_execute_batch_emptyObject



247
248
249
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 247

def test_execute_batch_empty
  assert_nothing_raised { @db.execute_batch "" }
end

#test_execute_batch_no_bindObject



251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 251

def test_execute_batch_no_bind
  @db.transaction do
    @db.execute_batch <<-SQL
      create table bar ( a, b, c );
      insert into bar values ( 'one', 2, 'three' );
      insert into bar values ( 'four', 5, 'six' );
      insert into bar values ( 'seven', 8, 'nine' );
    SQL
  end
  rows = @db.execute( "select * from bar" )
  assert_equal 3, rows.length
end

#test_execute_batch_with_bindObject



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

def test_execute_batch_with_bind
  @db.execute_batch( <<-SQL, [1] )
    create table bar ( a, b, c );
    insert into bar values ( 'one', 2, ? );
    insert into bar values ( 'four', 5, ? );
    insert into bar values ( 'seven', 8, ? );
  SQL
  rows = @db.execute( "select * from bar" ).map { |a,b,c| c }
  assert_equal [1, 1, 1], rows
end

#test_execute_no_block_no_bind_no_matchObject



136
137
138
139
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 136

def test_execute_no_block_no_bind_no_match
  rows = @db.execute( "select * from foo where a > 100" )
  assert rows.empty?
end

#test_execute_no_block_no_bind_with_matchObject



162
163
164
165
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 162

def test_execute_no_block_no_bind_with_match
  rows = @db.execute( "select * from foo where a = 1" )
  assert_equal 1, rows.length
end

#test_execute_no_block_with_bind_no_matchObject



149
150
151
152
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 149

def test_execute_no_block_with_bind_no_match
  rows = @db.execute( "select * from foo where a > ?", 100 )
  assert rows.empty?
end

#test_execute_no_block_with_bind_with_matchObject



175
176
177
178
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 175

def test_execute_no_block_with_bind_with_match
  rows = @db.execute( "select * from foo where a = ?", 1 )
  assert_equal 1, rows.length
end

#test_execute_with_block_no_bind_no_matchObject



141
142
143
144
145
146
147
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 141

def test_execute_with_block_no_bind_no_match
  called = false
  @db.execute( "select * from foo where a > 100" ) do |row|
    called = true
  end
  assert !called
end

#test_execute_with_block_no_bind_with_matchObject



167
168
169
170
171
172
173
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 167

def test_execute_with_block_no_bind_with_match
  called = 0
  @db.execute( "select * from foo where a = 1" ) do |row|
    called += 1
  end
  assert_equal 1, called
end

#test_execute_with_block_with_bind_no_matchObject



154
155
156
157
158
159
160
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 154

def test_execute_with_block_with_bind_no_match
  called = false
  @db.execute( "select * from foo where a > ?", 100 ) do |row|
    called = true
  end
  assert !called
end

#test_execute_with_block_with_bind_with_matchObject



180
181
182
183
184
185
186
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 180

def test_execute_with_block_with_bind_with_match
  called = 0
  @db.execute( "select * from foo where a = ?", 1 ) do |row|
    called += 1
  end
  assert_equal 1, called
end

#test_get_first_row_no_bind_no_matchObject



339
340
341
342
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 339

def test_get_first_row_no_bind_no_match
  result = @db.get_first_row( "select * from foo where a=100" )
  assert_nil result
end

#test_get_first_row_no_bind_with_matchObject



344
345
346
347
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 344

def test_get_first_row_no_bind_with_match
  result = @db.get_first_row( "select * from foo where a=1" )
  assert_equal [ 1, "foo" ], result
end

#test_get_first_row_with_bind_no_matchObject



349
350
351
352
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 349

def test_get_first_row_with_bind_no_match
  result = @db.get_first_row( "select * from foo where a=?", 100 )
  assert_nil result
end

#test_get_first_row_with_bind_with_matchObject



354
355
356
357
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 354

def test_get_first_row_with_bind_with_match
  result = @db.get_first_row( "select * from foo where a=?", 1 )
  assert_equal [ 1, "foo" ], result
end

#test_get_first_value_no_bind_no_matchObject



359
360
361
362
363
364
365
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 359

def test_get_first_value_no_bind_no_match
  result = @db.get_first_value( "select b, a from foo where a=100" )
  assert_nil result
  @db.results_as_hash = true
  result = @db.get_first_value( "select b, a from foo where a=100" )
  assert_nil result
end

#test_get_first_value_no_bind_with_matchObject



367
368
369
370
371
372
373
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 367

def test_get_first_value_no_bind_with_match
  result = @db.get_first_value( "select b, a from foo where a=1" )
  assert_equal "foo", result
  @db.results_as_hash = true
  result = @db.get_first_value( "select b, a from foo where a=1" )
  assert_equal "foo", result
end

#test_get_first_value_with_bind_no_matchObject



375
376
377
378
379
380
381
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 375

def test_get_first_value_with_bind_no_match
  result = @db.get_first_value( "select b, a from foo where a=?", 100 )
  assert_nil result
  @db.results_as_hash = true
  result = @db.get_first_value( "select b, a from foo where a=?", 100 )
  assert_nil result
end

#test_get_first_value_with_bind_with_matchObject



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

def test_get_first_value_with_bind_with_match
  result = @db.get_first_value( "select b, a from foo where a=?", 1 )
  assert_equal "foo", result
  @db.results_as_hash = true
  result = @db.get_first_value( "select b, a from foo where a=?", 1 )
  assert_equal "foo", result
end

#test_interruptObject



482
483
484
485
486
487
488
489
490
491
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 482

def test_interrupt
  @db.create_function( "abort", 1 ) do |func,x|
    @db.interrupt
    func.result = x
  end

  assert_raise( SQLite3::InterruptException ) do
    @db.execute "select abort(a) from foo"
  end
end

#test_last_insert_row_idObject



391
392
393
394
395
396
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 391

def test_last_insert_row_id
  @db.execute "insert into foo ( b ) values ( 'test' )"
  assert_equal 4, @db.last_insert_row_id
  @db.execute "insert into foo ( b ) values ( 'again' )"
  assert_equal 5, @db.last_insert_row_id
end

#test_prepare_invalid_columnObject



109
110
111
112
113
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 109

def test_prepare_invalid_column
  assert_raise( SQLite3::SQLException ) do
    @db.prepare "select k from foo"
  end
end

#test_prepare_invalid_syntaxObject



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

def test_prepare_invalid_syntax
  assert_raise( SQLite3::SQLException ) do
    @db.prepare "select from foo"
  end
end

#test_prepare_invalid_tableObject



115
116
117
118
119
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 115

def test_prepare_invalid_table
  assert_raise( SQLite3::SQLException ) do
    @db.prepare "select * from barf"
  end
end

#test_prepare_no_blockObject



121
122
123
124
125
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 121

def test_prepare_no_block
  stmt = @db.prepare "select * from foo"
  assert stmt.respond_to?(:execute)
  stmt.close
end

#test_prepare_with_blockObject



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

def test_prepare_with_block
  called = false
  @db.prepare "select * from foo" do |stmt|
    called = true
    assert stmt.respond_to?(:execute)
  end
  assert called
end

#test_query_no_block_no_bind_no_matchObject



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

def test_query_no_block_no_bind_no_match
  result = @db.query( "select * from foo where a > 100" )
  assert_nil result.next
  result.close
end

#test_query_no_block_no_bind_with_matchObject



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

def test_query_no_block_no_bind_with_match
  result = @db.query( "select * from foo where a = 1" )
  assert_not_nil result.next
  assert_nil result.next
  result.close
end

#test_query_no_block_with_bind_no_matchObject



290
291
292
293
294
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 290

def test_query_no_block_with_bind_no_match
  result = @db.query( "select * from foo where a > ?", 100 )
  assert_nil result.next
  result.close
end

#test_query_no_block_with_bind_with_matchObject



322
323
324
325
326
327
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 322

def test_query_no_block_with_bind_with_match
  result = @db.query( "select * from foo where a = ?", 1 )
  assert_not_nil result.next
  assert_nil result.next
  result.close
end

#test_query_with_block_no_bind_no_matchObject



281
282
283
284
285
286
287
288
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 281

def test_query_with_block_no_bind_no_match
  r = nil
  @db.query( "select * from foo where a > 100" ) do |result|
    assert_nil result.next
    r = result
  end
  assert r.closed?
end

#test_query_with_block_no_bind_with_matchObject



312
313
314
315
316
317
318
319
320
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 312

def test_query_with_block_no_bind_with_match
  r = nil
  @db.query( "select * from foo where a = 1" ) do |result|
    assert_not_nil result.next
    assert_nil result.next
    r = result
  end
  assert r.closed?
end

#test_query_with_block_with_bind_no_matchObject



296
297
298
299
300
301
302
303
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 296

def test_query_with_block_with_bind_no_match
  r = nil
  @db.query( "select * from foo where a > ?", 100 ) do |result|
    assert_nil result.next
    r = result
  end
  assert r.closed?
end

#test_query_with_block_with_bind_with_matchObject



329
330
331
332
333
334
335
336
337
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 329

def test_query_with_block_with_bind_with_match
  r = nil
  @db.query( "select * from foo where a = ?", 1 ) do |result|
    assert_not_nil result.next
    assert_nil result.next
    r = result
  end
  assert r.closed?
end

#test_table_info_with_defaults_for_version_3_3_8_and_higherObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 22

def test_table_info_with_defaults_for_version_3_3_8_and_higher
  @db.transaction do
    @db.execute "create table defaults_test ( a string default NULL, b string default 'Hello', c string default '--- []\n' )"
    data = @db.table_info( "defaults_test" )
    assert_equal({"name" => "a", "type" => "string", "dflt_value" => nil, "notnull" => 0, "cid" => 0, "pk" => 0},
      data[0])
    assert_equal({"name" => "b", "type" => "string", "dflt_value" => "Hello", "notnull" => 0, "cid" => 1, "pk" => 0},
      data[1])
    assert_equal({"name" => "c", "type" => "string", "dflt_value" => "--- []\n", "notnull" => 0, "cid" => 2, "pk" => 0},
      data[2])
  end
end

#test_table_info_with_type_translation_activeObject



18
19
20
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 18

def test_table_info_with_type_translation_active
  assert_nothing_raised { @db.table_info("foo") }
end

#test_table_info_without_defaults_for_version_3_3_8_and_higherObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 35

def test_table_info_without_defaults_for_version_3_3_8_and_higher
  @db.transaction do
    @db.execute "create table no_defaults_test ( a integer default 1, b integer )"
    data = @db.table_info( "no_defaults_test" )
    assert_equal({"name" => "a", "type" => "integer", "dflt_value" => "1", "notnull" => 0, "cid" => 0, "pk" => 0},
      data[0])
    assert_equal({"name" => "b", "type" => "integer", "dflt_value" => nil, "notnull" => 0, "cid" => 1, "pk" => 0},
      data[1])
  end
end

#test_total_changesObject



405
406
407
408
409
410
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 405

def test_total_changes
  assert_equal 3, @db.total_changes
  @db.execute "insert into foo ( b ) values ( 'test' )"
  @db.execute "delete from foo where 1=1"
  assert_equal 8, @db.total_changes
end

#test_traceObject



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

def test_trace
  result = nil
  @db.trace { |sql| result = sql }
  @db.execute "select * from foo"
  assert_equal "select * from foo", result
end

#test_transaction_activeObject



463
464
465
466
467
468
469
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 463

def test_transaction_active
  assert !@db.transaction_active?
  @db.transaction
  assert @db.transaction_active?
  @db.commit
  assert !@db.transaction_active?
end

#test_transaction_commitObject



434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 434

def test_transaction_commit
  @db.transaction
  @db.execute_batch <<-SQL
    insert into foo (b) values ( 'test1' );
    insert into foo (b) values ( 'test2' );
    insert into foo (b) values ( 'test3' );
    insert into foo (b) values ( 'test4' );
  SQL
  assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
  @db.commit
  assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
end

#test_transaction_commit_in_blockObject



455
456
457
458
459
460
461
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 455

def test_transaction_commit_in_block
  assert_raise( SQLite3::SQLException ) do
    @db.transaction do
      @db.commit
    end
  end
end

#test_transaction_implicit_rollbackObject



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

def test_transaction_implicit_rollback
  assert !@db.transaction_active?
  @db.transaction 
  @db.execute('create table bar (x CHECK(1 = 0))')
  assert @db.transaction_active?
  assert_raises( SQLite3::ConstraintException ) do
    @db.execute("insert or rollback into bar (x) VALUES ('x')")
  end
  assert !@db.transaction_active?
end

#test_transaction_nestObject



412
413
414
415
416
417
418
419
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 412

def test_transaction_nest
  assert_raise( SQLite3::SQLException ) do
    @db.transaction do
      @db.transaction do
      end
    end
  end
end

#test_transaction_rollbackObject



421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 421

def test_transaction_rollback
  @db.transaction
  @db.execute_batch <<-SQL
    insert into foo (b) values ( 'test1' );
    insert into foo (b) values ( 'test2' );
    insert into foo (b) values ( 'test3' );
    insert into foo (b) values ( 'test4' );
  SQL
  assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
  @db.rollback
  assert_equal 3, @db.get_first_value("select count(*) from foo").to_i
end

#test_transaction_rollback_in_blockObject



447
448
449
450
451
452
453
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb', line 447

def test_transaction_rollback_in_block
  assert_raise( SQLite3::SQLException ) do
    @db.transaction do
      @db.rollback
    end
  end
end