mirror of
https://gitea.invidious.io/iv-org/shard-crystal-sqlite3.git
synced 2024-08-15 00:53:26 +00:00
column_count, column_name, close statement
This commit is contained in:
parent
63f98d18d1
commit
5266a7e7b3
3 changed files with 42 additions and 0 deletions
|
@ -6,6 +6,10 @@ ensure
|
||||||
File.delete(DB_FILENAME)
|
File.delete(DB_FILENAME)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_mem_db
|
||||||
|
yield DB.open "sqlite3", {"database": ":memory:"}
|
||||||
|
end
|
||||||
|
|
||||||
def sql(s : String)
|
def sql(s : String)
|
||||||
"#{s.inspect}"
|
"#{s.inspect}"
|
||||||
end
|
end
|
||||||
|
@ -119,4 +123,30 @@ describe Driver do
|
||||||
assert_single_read result_set, String, "hello"
|
assert_single_read result_set, String, "hello"
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -57,6 +57,14 @@ class SQLite3::ResultSet2 < DB::ResultSet
|
||||||
end
|
end
|
||||||
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
|
def to_unsafe
|
||||||
@statement.to_unsafe
|
@statement.to_unsafe
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,10 @@ class SQLite3::Statement2 < DB::Statement
|
||||||
LibSQLite3.reset(self)
|
LibSQLite3.reset(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected def on_close
|
||||||
|
check LibSQLite3.finalize(self)
|
||||||
|
end
|
||||||
|
|
||||||
protected def add_parameter(index : Int32, value)
|
protected def add_parameter(index : Int32, value)
|
||||||
bind_arg(index, value)
|
bind_arg(index, value)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue