File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33module SQLite3
44 class TestPragmas < SQLite3 ::TestCase
5+ class DatabaseTracker < SQLite3 ::Database
6+ attr_reader :test_statements
7+
8+ def initialize ( ...)
9+ @test_statements = [ ]
10+ super
11+ end
12+
13+ def execute ( sql , bind_vars = [ ] , &block )
14+ @test_statements << sql
15+ super
16+ end
17+ end
18+
519 def setup
620 super
7- @db = SQLite3 ::Database . new ( ":memory:" )
21+ @db = DatabaseTracker . new ( ":memory:" )
22+ end
23+
24+ def teardown
25+ @db . close
826 end
927
1028 def test_pragma_errors
@@ -32,5 +50,28 @@ def test_set_boolean_pragma
3250 ensure
3351 @db . set_boolean_pragma ( "read_uncommitted" , 0 )
3452 end
53+
54+ def test_optimize_with_no_args
55+ @db . optimize
56+
57+ assert_equal ( [ "PRAGMA optimize" ] , @db . test_statements )
58+ end
59+
60+ def test_optimize_with_args
61+ @db . optimize ( Constants ::Optimize ::DEFAULT )
62+ @db . optimize ( Constants ::Optimize ::ANALYZE_TABLES | Constants ::Optimize ::LIMIT_ANALYZE )
63+ @db . optimize ( Constants ::Optimize ::ANALYZE_TABLES | Constants ::Optimize ::DEBUG )
64+ @db . optimize ( Constants ::Optimize ::DEFAULT | Constants ::Optimize ::CHECK_ALL_TABLES )
65+
66+ assert_equal (
67+ [
68+ "PRAGMA optimize=18" ,
69+ "PRAGMA optimize=18" ,
70+ "PRAGMA optimize=3" ,
71+ "PRAGMA optimize=65554"
72+ ] ,
73+ @db . test_statements
74+ )
75+ end
3576 end
3677end
You can’t perform that action at this time.
0 commit comments