column_count, column_name, close statement

This commit is contained in:
Brian J. Cardiff 2016-01-29 21:58:04 -03:00
parent 63f98d18d1
commit 5266a7e7b3
3 changed files with 42 additions and 0 deletions

View File

@ -6,6 +6,10 @@ ensure
File.delete(DB_FILENAME)
end
def with_mem_db
yield DB.open "sqlite3", {"database": ":memory:"}
end
def sql(s : String)
"#{s.inspect}"
end
@ -119,4 +123,30 @@ describe Driver do
assert_single_read result_set, String, "hello"
end
end
it "gets column count" do
with_mem_db do |db|
db.exec_non_query "create table person (name string, age integer)"
db.exec_non_query %(insert into person values ("foo", 10))
run = false
db.exec_query_each "select * from person" do |result_set|
run = true
result_set.column_count.should eq(2)
end
run.should be_true
end
end
it "gets column name" do
with_mem_db do |db|
db.exec_non_query "create table person (name string, age integer)"
db.exec_non_query %(insert into person values ("foo", 10))
db.exec_query_each("select * from person") do |result_set|
result_set.column_name(0).should eq("name")
result_set.column_name(1).should eq("age")
end
end
end
end

View File

@ -57,6 +57,14 @@ class SQLite3::ResultSet2 < DB::ResultSet
end
end
def column_count
LibSQLite3.column_count(self)
end
def column_name(index)
String.new LibSQLite3.column_name(self, index)
end
def to_unsafe
@statement.to_unsafe
end

View File

@ -8,6 +8,10 @@ class SQLite3::Statement2 < DB::Statement
LibSQLite3.reset(self)
end
protected def on_close
check LibSQLite3.finalize(self)
end
protected def add_parameter(index : Int32, value)
bind_arg(index, value)
end