Class: TC_ResultSet
- Inherits:
-
SQLite3::TestCase
- Object
- Minitest::Test
- SQLite3::TestCase
- TC_ResultSet
- Defined in:
- lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb,
lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_resultset.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_close ⇒ Object
- #test_columns ⇒ Object
- #test_each ⇒ Object
- #test_enumerable ⇒ Object
- #test_eof_edge ⇒ Object
- #test_eof_inner ⇒ Object
- #test_next_eof ⇒ Object
- #test_next_no_type_translation_no_hash ⇒ Object
- #test_next_results_as_hash ⇒ Object
- #test_next_type_translation ⇒ Object
- #test_next_type_translation_with_untyped_column ⇒ Object
- #test_real_translation ⇒ Object
- #test_reset_unused ⇒ Object
- #test_reset_used ⇒ Object
- #test_reset_with_bind ⇒ Object
- #test_type_translation_with_null_column ⇒ Object
- #test_types ⇒ Object
Methods inherited from SQLite3::TestCase
Instance Method Details
#setup ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.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 @stmt = @db.prepare( "select * from foo where a in ( ?, ? )" ) @result = @stmt.execute end |
#teardown ⇒ Object
16 17 18 19 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 16 def teardown @stmt.close @db.close end |
#test_close ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 128 def test_close stmt = @db.prepare( "select * from foo" ) result = stmt.execute assert !result.closed? result.close assert result.closed? assert stmt.closed? assert_raise( SQLite3::Exception ) { result.reset } assert_raise( SQLite3::Exception ) { result.next } assert_raise( SQLite3::Exception ) { result.each } assert_raise( SQLite3::Exception ) { result.close } assert_raise( SQLite3::Exception ) { result.types } assert_raise( SQLite3::Exception ) { result.columns } end |
#test_columns ⇒ Object
124 125 126 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 124 def test_columns assert_equal [ "a", "b" ], @result.columns end |
#test_each ⇒ Object
108 109 110 111 112 113 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 108 def test_each called = 0 @result.reset( 1, 2 ) @result.each { |row| called += 1 } assert_equal 2, called end |
#test_enumerable ⇒ Object
115 116 117 118 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 115 def test_enumerable @result.reset( 1, 2 ) assert_equal 2, @result.to_a.length end |
#test_eof_edge ⇒ Object
43 44 45 46 47 48 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 43 def test_eof_edge @result.reset( 1 ) @result.next # to first row @result.next # to end of result set assert @result.eof? end |
#test_eof_inner ⇒ Object
38 39 40 41 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 38 def test_eof_inner @result.reset( 1 ) assert !@result.eof? end |
#test_next_eof ⇒ Object
50 51 52 53 54 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 50 def test_next_eof @result.reset( 1 ) assert_not_nil @result.next assert_nil @result.next end |
#test_next_no_type_translation_no_hash ⇒ Object
56 57 58 59 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 56 def test_next_no_type_translation_no_hash @result.reset( 1 ) assert_equal [ 1, "foo" ], @result.next end |
#test_next_results_as_hash ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 98 def test_next_results_as_hash @db.results_as_hash = true @result.reset( 1 ) hash = @result.next assert_equal( { "a" => 1, "b" => "foo" }, hash ) assert_equal hash[0], 1 assert_equal hash[1], "foo" end |
#test_next_type_translation ⇒ Object
61 62 63 64 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 61 def test_next_type_translation @result.reset( 1 ) assert_equal [ 1, "foo" ], @result.next end |
#test_next_type_translation_with_untyped_column ⇒ Object
66 67 68 69 70 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 66 def test_next_type_translation_with_untyped_column @db.query( "select count(*) from foo" ) do |result| assert_equal [3], result.next end end |
#test_real_translation ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 86 def test_real_translation @db.execute('create table foo_real(a real)') @db.execute('insert into foo_real values (42)' ) @db.query('select a, sum(a), typeof(a), typeof(sum(a)) from foo_real') do |result| result = result.next assert result[0].is_a?(Float) assert result[1].is_a?(Float) assert result[2].is_a?(String) assert result[3].is_a?(String) end end |
#test_reset_unused ⇒ Object
21 22 23 24 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 21 def test_reset_unused assert_nothing_raised { @result.reset } assert @result.to_a.empty? end |
#test_reset_used ⇒ Object
26 27 28 29 30 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 26 def test_reset_used @result.to_a assert_nothing_raised { @result.reset } assert @result.to_a.empty? end |
#test_reset_with_bind ⇒ Object
32 33 34 35 36 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 32 def test_reset_with_bind @result.to_a assert_nothing_raised { @result.reset( 1, 2 ) } assert_equal 2, @result.to_a.length end |
#test_type_translation_with_null_column ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 72 def test_type_translation_with_null_column time = '1974-07-25 14:39:00' @db.execute "create table bar ( a integer, b time, c string )" @db.execute "insert into bar (a, b, c) values (NULL, '#{time}', 'hello')" @db.execute "insert into bar (a, b, c) values (1, NULL, 'hello')" @db.execute "insert into bar (a, b, c) values (2, '#{time}', NULL)" @db.query( "select * from bar" ) do |result| assert_equal [nil, time, 'hello'], result.next assert_equal [1, nil, 'hello'], result.next assert_equal [2, time, nil], result.next end end |
#test_types ⇒ Object
120 121 122 |
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb', line 120 def test_types assert_equal [ "integer", "text" ], @result.types end |