2016-02-26 01:37:10 +00:00
|
|
|
require "./spec_helper"
|
2016-01-30 22:46:43 +00:00
|
|
|
|
2016-06-24 01:07:59 +00:00
|
|
|
class DummyException < Exception
|
|
|
|
end
|
|
|
|
|
2016-01-30 22:46:43 +00:00
|
|
|
describe DB::ResultSet do
|
|
|
|
it "should enumerate records using each" do
|
|
|
|
nums = [] of Int32
|
|
|
|
|
|
|
|
with_dummy do |db|
|
|
|
|
db.query "3,4 1,2" do |rs|
|
|
|
|
rs.each do
|
|
|
|
nums << rs.read(Int32)
|
|
|
|
nums << rs.read(Int32)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
nums.should eq([3, 4, 1, 2])
|
|
|
|
end
|
2016-06-24 01:07:59 +00:00
|
|
|
|
|
|
|
it "should close ResultSet after query" do
|
|
|
|
with_dummy do |db|
|
|
|
|
the_rs = uninitialized DB::ResultSet
|
|
|
|
db.query "3,4 1,2" do |rs|
|
|
|
|
the_rs = rs
|
|
|
|
end
|
|
|
|
the_rs.closed?.should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should close ResultSet after query even with exception" do
|
|
|
|
with_dummy do |db|
|
|
|
|
the_rs = uninitialized DB::ResultSet
|
|
|
|
begin
|
|
|
|
db.query "3,4 1,2" do |rs|
|
|
|
|
the_rs = rs
|
|
|
|
raise DummyException.new
|
|
|
|
end
|
|
|
|
rescue DummyException
|
|
|
|
end
|
|
|
|
the_rs.closed?.should be_true
|
|
|
|
end
|
2016-03-28 22:29:15 +00:00
|
|
|
|
|
|
|
it "should enumerate columns" do
|
|
|
|
cols = [] of String
|
|
|
|
|
|
|
|
with_dummy do |db|
|
|
|
|
db.query "3,4 1,2" do |rs|
|
|
|
|
rs.each_column do |col, col_type|
|
|
|
|
cols << col
|
|
|
|
col_type.should eq(Slice(UInt8))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
cols.should eq(["c0", "c1"])
|
2016-06-24 01:07:59 +00:00
|
|
|
end
|
2016-01-30 22:46:43 +00:00
|
|
|
end
|