Permalink
Browse files

fixing resultset and tests

  • Loading branch information...
1 parent 2061408 commit 7ddd30de1729d08ec913f3c61c6b6bb1d4e62daa @tenderlove tenderlove committed Jan 25, 2010
Showing with 12 additions and 14 deletions.
  1. +6 −7 lib/sqlite3/resultset.rb
  2. +6 −7 test/test_integration_resultset.rb
View
13 lib/sqlite3/resultset.rb
@@ -46,7 +46,7 @@ def reset( *bind_params )
# Query whether the cursor has reached the end of the result set or not.
def eof?
- @eof
+ @stmt.done?
end
# Obtain the next row from the cursor. If there are no more rows to be
@@ -63,27 +63,26 @@ def eof?
# For hashes, the column names are the keys of the hash, and the column
# types are accessible via the +types+ property.
def next
- val = @stmt.step
+ row = @stmt.step
return nil if @stmt.done?
if @db.type_translation
- row = @stmt.types.zip( row ).map do |type, value|
+ row = @stmt.types.zip(row).map do |type, value|
@db.translator.translate( type, value )
end
end
if @db.results_as_hash
- new_row = HashWithTypes[ *( @stmt.columns.zip( row ).to_a.flatten ) ]
+ new_row = HashWithTypes[*@stmt.columns.zip(row).flatten]
row.each_with_index { |value,idx|
- value.taint
new_row[idx] = value
}
row = new_row
else
if row.respond_to?(:fields)
- row = ArrayWithTypes.new(val)
+ row = ArrayWithTypes.new(row)
else
- row = ArrayWithTypesAndFields.new(val)
+ row = ArrayWithTypesAndFields.new(row)
end
row.fields = @stmt.columns
end
View
13 test/test_integration_resultset.rb
@@ -2,7 +2,7 @@
class TC_ResultSet < Test::Unit::TestCase
def setup
- @db = SQLite3::Database.new( "test.db" )
+ @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' )"
@@ -16,7 +16,6 @@ def setup
def teardown
@stmt.close
@db.close
- File.delete( "test.db" )
end
def test_reset_unused
@@ -56,7 +55,7 @@ def test_next_eof
def test_next_no_type_translation_no_hash
@result.reset( 1 )
- assert_equal [ "1", "foo" ], @result.next
+ assert_equal [ 1, "foo" ], @result.next
end
def test_next_type_translation
@@ -68,7 +67,7 @@ def test_next_type_translation
def test_next_type_translation_with_untyped_column
@db.type_translation = true
@db.query( "select count(*) from foo" ) do |result|
- assert_equal ["3"], result.next
+ assert_equal [3], result.next
end
end
@@ -114,7 +113,7 @@ def test_real_translation
def test_next_results_as_hash
@db.results_as_hash = true
@result.reset( 1 )
- assert_equal( { "a" => "1", "b" => "foo", 0 => "1", 1 => "foo" },
+ assert_equal( { "a" => 1, "b" => "foo", 0 => 1, 1 => "foo" },
@result.next )
end
@@ -123,15 +122,15 @@ def test_tainted_results_as_hash
@result.reset( 1 )
row = @result.next
row.each do |_, v|
- assert_equal true, v.tainted?
+ assert(v.tainted?) if String === v
end
end
def test_tainted_row_values
@result.reset( 1 )
row = @result.next
row.each do |v|
- assert_equal true, v.tainted?
+ assert(v.tainted?) if String === v
end
end

0 comments on commit 7ddd30d

Please sign in to comment.