@@ -138,7 +138,7 @@ def test_changes
138
138
assert_equal 1 , @db . changes
139
139
@db . execute_batch (
140
140
"UPDATE items SET number = (number + :nn) WHERE (number = :n)" ,
141
- { "nn" => 20 , "n" => 10 }
141
+ { "nn" => 20 , "n" => 10 }
142
142
)
143
143
assert_equal 1 , @db . changes
144
144
assert_equal [ [ 30 ] ] , @db . execute ( "select number from items" )
@@ -168,38 +168,38 @@ def test_execute_batch2
168
168
INSERT INTO items (name) VALUES ("bar");
169
169
SELECT * FROM items;
170
170
EOSQL
171
- assert_equal [ { "id" => "1" , "name" => "foo" } , { "id" => "2" , "name" => "bar" } ] , return_value
171
+ assert_equal [ { "id" => "1" , "name" => "foo" } , { "id" => "2" , "name" => "bar" } ] , return_value
172
172
173
173
return_value = @db . execute_batch2 ( "SELECT * FROM items;" ) do |result |
174
174
result [ "id" ] = result [ "id" ] . to_i
175
175
result
176
176
end
177
- assert_equal [ { "id" => 1 , "name" => "foo" } , { "id" => 2 , "name" => "bar" } ] , return_value
177
+ assert_equal [ { "id" => 1 , "name" => "foo" } , { "id" => 2 , "name" => "bar" } ] , return_value
178
178
179
179
return_value = @db . execute_batch2 ( 'INSERT INTO items (name) VALUES ("oof")' )
180
180
assert_empty return_value
181
181
182
182
return_value = @db . execute_batch2 (
183
- ' CREATE TABLE employees (id integer PRIMARY KEY AUTOINCREMENT, name string, age integer(3));
183
+ " CREATE TABLE employees (id integer PRIMARY KEY AUTOINCREMENT, name string, age integer(3));
184
184
INSERT INTO employees (age) VALUES (30);
185
185
INSERT INTO employees (age) VALUES (40);
186
186
INSERT INTO employees (age) VALUES (20);
187
- SELECT age FROM employees;'
187
+ SELECT age FROM employees;"
188
188
) do |result |
189
189
result [ "age" ] = result [ "age" ] . to_i
190
190
result
191
191
end
192
- assert_equal [ { "age" => 30 } , { "age" => 40 } , { "age" => 20 } ] , return_value
192
+ assert_equal [ { "age" => 30 } , { "age" => 40 } , { "age" => 20 } ] , return_value
193
193
194
194
return_value = @db . execute_batch2 ( "SELECT name FROM employees" )
195
- assert_equal [ { "name" => nil } , { "name" => nil } , { "name" => nil } ] , return_value
195
+ assert_equal [ { "name" => nil } , { "name" => nil } , { "name" => nil } ] , return_value
196
196
197
197
@db . results_as_hash = false
198
198
return_value = @db . execute_batch2 (
199
- ' CREATE TABLE managers (id integer PRIMARY KEY AUTOINCREMENT, age integer(3));
199
+ " CREATE TABLE managers (id integer PRIMARY KEY AUTOINCREMENT, age integer(3));
200
200
INSERT INTO managers (age) VALUES (50);
201
201
INSERT INTO managers (age) VALUES (60);
202
- SELECT id, age from managers;'
202
+ SELECT id, age from managers;"
203
203
) do |result |
204
204
result = result . map do |res |
205
205
res . to_i
@@ -356,15 +356,15 @@ def test_execute_returns_list_of_hash
356
356
db . execute ( "create table foo ( a integer primary key, b text )" )
357
357
db . execute ( "insert into foo (b) values ('hello')" )
358
358
rows = db . execute ( "select * from foo" )
359
- assert_equal [ { "a" => 1 , "b" => "hello" } ] , rows
359
+ assert_equal [ { "a" => 1 , "b" => "hello" } ] , rows
360
360
end
361
361
362
362
def test_execute_yields_hash
363
363
db = SQLite3 ::Database . new ( ":memory:" , results_as_hash : true )
364
364
db . execute ( "create table foo ( a integer primary key, b text )" )
365
365
db . execute ( "insert into foo (b) values ('hello')" )
366
366
db . execute ( "select * from foo" ) do |row |
367
- assert_equal ( { "a" => 1 , "b" => "hello" } , row )
367
+ assert_equal ( { "a" => 1 , "b" => "hello" } , row )
368
368
end
369
369
end
370
370
@@ -377,16 +377,16 @@ def test_table_info
377
377
"notnull" => 0 ,
378
378
"type" => "integer" ,
379
379
"dflt_value" => nil ,
380
- "cid" => 0
380
+ "cid" => 0 ,
381
381
} ,
382
- {
383
- "name" => "b" ,
384
- "pk" => 0 ,
385
- "notnull" => 0 ,
386
- "type" => "text" ,
387
- "dflt_value" => nil ,
388
- "cid" => 1
389
- } ]
382
+ {
383
+ "name" => "b" ,
384
+ "pk" => 0 ,
385
+ "notnull" => 0 ,
386
+ "type" => "text" ,
387
+ "dflt_value" => nil ,
388
+ "cid" => 1 ,
389
+ } ]
390
390
assert_equal info , db . table_info ( "foo" )
391
391
end
392
392
@@ -415,7 +415,8 @@ def test_trace_with_block
415
415
def test_trace_with_object
416
416
obj = Class . new {
417
417
attr_accessor :result
418
- def call sql
418
+
419
+ def call ( sql )
419
420
@result = sql
420
421
end
421
422
} . new
@@ -516,7 +517,7 @@ def test_function_return_type_round_trip
516
517
def test_define_function_closed
517
518
@db . close
518
519
assert_raise ( SQLite3 ::Exception ) do
519
- @db . define_function ( "foo" ) { }
520
+ @db . define_function ( "foo" ) { }
520
521
end
521
522
end
522
523
@@ -536,11 +537,12 @@ def test_define_aggregate
536
537
acc = Class . new {
537
538
attr_reader :sum
538
539
alias_method :finalize , :sum
540
+
539
541
def initialize
540
542
@sum = 0
541
543
end
542
544
543
- def step a
545
+ def step ( a )
544
546
@sum += a
545
547
end
546
548
} . new
@@ -554,14 +556,14 @@ def test_authorizer_ok
554
556
statements = [ ]
555
557
556
558
@db . authorizer = Class . new {
557
- def call action , a , b , c , d
559
+ def call ( action , a , b , c , d )
558
560
true
559
561
end
560
562
} . new
561
563
statements << @db . prepare ( "select 'fooooo'" )
562
564
563
565
@db . authorizer = Class . new {
564
- def call action , a , b , c , d
566
+ def call ( action , a , b , c , d )
565
567
0
566
568
end
567
569
} . new
@@ -572,7 +574,7 @@ def call action, a, b, c, d
572
574
573
575
def test_authorizer_ignore
574
576
@db . authorizer = Class . new {
575
- def call action , a , b , c , d
577
+ def call ( action , a , b , c , d )
576
578
nil
577
579
end
578
580
} . new
@@ -584,7 +586,7 @@ def call action, a, b, c, d
584
586
585
587
def test_authorizer_fail
586
588
@db . authorizer = Class . new {
587
- def call action , a , b , c , d
589
+ def call ( action , a , b , c , d )
588
590
false
589
591
end
590
592
} . new
@@ -595,7 +597,7 @@ def call action, a, b, c, d
595
597
596
598
def test_remove_auth
597
599
@db . authorizer = Class . new {
598
- def call action , a , b , c , d
600
+ def call ( action , a , b , c , d )
599
601
false
600
602
end
601
603
} . new
@@ -623,14 +625,14 @@ def test_execute_with_empty_bind_params
623
625
end
624
626
625
627
def test_query_with_named_bind_params
626
- resultset = @db . query ( "select :n" , { "n" => "foo" } )
628
+ resultset = @db . query ( "select :n" , { "n" => "foo" } )
627
629
assert_equal [ [ "foo" ] ] , resultset . to_a
628
630
ensure
629
631
resultset &.close
630
632
end
631
633
632
634
def test_execute_with_named_bind_params
633
- assert_equal [ [ "foo" ] ] , @db . execute ( "select :n" , { "n" => "foo" } )
635
+ assert_equal [ [ "foo" ] ] , @db . execute ( "select :n" , { "n" => "foo" } )
634
636
end
635
637
636
638
def test_strict_mode
@@ -681,10 +683,10 @@ def test_default_transaction_mode
681
683
end
682
684
683
685
test_cases = [
684
- { mode : nil , read : true , write : true } ,
685
- { mode : :deferred , read : true , write : true } ,
686
- { mode : :immediate , read : true , write : false } ,
687
- { mode : :exclusive , read : false , write : false }
686
+ { mode : nil , read : true , write : true } ,
687
+ { mode : :deferred , read : true , write : true } ,
688
+ { mode : :immediate , read : true , write : false } ,
689
+ { mode : :exclusive , read : false , write : false } ,
688
690
]
689
691
690
692
test_cases . each do |item |
@@ -721,5 +723,9 @@ def test_transaction_returns_block_result
721
723
result = @db . transaction { :foo }
722
724
assert_equal :foo , result
723
725
end
726
+
727
+ def test_dbstat_table_exists
728
+ assert_nothing_raised { @db . execute ( "select * from dbstat" ) }
729
+ end
724
730
end
725
731
end
0 commit comments