summaryrefslogtreecommitdiffstats
path: root/test/tc_integration.rb
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-02-07 17:23:53 +0000
committerJamis Buck <jamis@37signals.com>2005-02-07 17:23:53 +0000
commit4c3f433efc54403478cbc56d348773167ee5a775 (patch)
treee7784809e0ca71949b191018ebb3fa00b5f6fc51 /test/tc_integration.rb
parent372281cf9bef717f3a0b60167bc0fe1a35c6f352 (diff)
downloadthird_party-sqlite3-ruby-4c3f433efc54403478cbc56d348773167ee5a775.tar.gz
third_party-sqlite3-ruby-4c3f433efc54403478cbc56d348773167ee5a775.tar.xz
third_party-sqlite3-ruby-4c3f433efc54403478cbc56d348773167ee5a775.zip
Added Database#query and made it possible to close a statement from a resultset. This should make it easier to create a sqlite3 adapter for Og.
Diffstat (limited to 'test/tc_integration.rb')
-rw-r--r--test/tc_integration.rb93
1 files changed, 93 insertions, 0 deletions
diff --git a/test/tc_integration.rb b/test/tc_integration.rb
index 948e833..e55b5a1 100644
--- a/test/tc_integration.rb
+++ b/test/tc_integration.rb
@@ -302,6 +302,70 @@ module Integration
assert_equal %w{1 1 1}, rows
end
+ define_method( "test_query_no_block_no_bind_no_match" ) do
+ result = @db.query( "select * from foo where a > 100" )
+ assert_nil result.next
+ result.close
+ end
+
+ define_method( "test_query_with_block_no_bind_no_match" ) do
+ r = nil
+ @db.query( "select * from foo where a > 100" ) do |result|
+ assert_nil result.next
+ r = result
+ end
+ assert r.closed?
+ end
+
+ define_method( "test_query_no_block_with_bind_no_match" ) do
+ result = @db.query( "select * from foo where a > ?", 100 )
+ assert_nil result.next
+ result.close
+ end
+
+ define_method( "test_query_with_block_with_bind_no_match" ) do
+ r = nil
+ @db.query( "select * from foo where a > ?", 100 ) do |result|
+ assert_nil result.next
+ r = result
+ end
+ assert r.closed?
+ end
+
+ define_method( "test_query_no_block_no_bind_with_match" ) do
+ result = @db.query( "select * from foo where a = 1" )
+ assert_not_nil result.next
+ assert_nil result.next
+ result.close
+ end
+
+ define_method( "test_query_with_block_no_bind_with_match" ) do
+ 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
+
+ define_method( "test_query_no_block_with_bind_with_match" ) do
+ result = @db.query( "select * from foo where a = ?", 1 )
+ assert_not_nil result.next
+ assert_nil result.next
+ result.close
+ end
+
+ define_method( "test_query_with_block_with_bind_with_match" ) do
+ 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
+
define_method( "test_get_first_row_no_bind_no_match" ) do
result = @db.get_first_row( "select * from foo where a=100" )
assert_nil result
@@ -741,6 +805,20 @@ module Integration
end
assert called
end
+
+ define_method( "test_close" ) do
+ stmt = @db.prepare( "select * from foo" )
+ assert !stmt.closed?
+ stmt.close
+ assert stmt.closed?
+ assert_raise( SQLite3::Exception ) { stmt.execute }
+ assert_raise( SQLite3::Exception ) { stmt.execute! }
+ assert_raise( SQLite3::Exception ) { stmt.close }
+ assert_raise( SQLite3::Exception ) { stmt.bind_params 5 }
+ assert_raise( SQLite3::Exception ) { stmt.bind_param 1, 5 }
+ assert_raise( SQLite3::Exception ) { stmt.columns }
+ assert_raise( SQLite3::Exception ) { stmt.types }
+ end
end
const_set( "TC_Statement_#{driver}", test_case )
@@ -837,6 +915,21 @@ module Integration
define_method( "test_columns" ) do
assert_equal [ "a", "b" ], @result.columns
end
+
+ define_method( "test_close" ) do
+ 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
end
const_set( "TC_ResultSet_#{driver}", test_case )
end