Enumerate columns in result_set

This commit is contained in:
Santiago Palladino 2016-03-28 19:29:15 -03:00
parent 344804dd79
commit 5773faaa5c
2 changed files with 21 additions and 0 deletions

View file

@ -41,5 +41,19 @@ describe DB::ResultSet do
end
the_rs.closed?.should be_true
end
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"])
end
end

View file

@ -41,6 +41,13 @@ module DB
end
end
# Iterates over all the columns
def each_column
column_count.times do |x|
yield column_name(x), column_type(x)
end
end
# Move the next row in the result.
# Return `false` if no more rows are available.
# See `#each`