mirror of
https://gitea.invidious.io/iv-org/shard-crystal-sqlite3.git
synced 2024-08-15 00:53:26 +00:00
Make sure queries (insert and query) work with any type
This commit is contained in:
parent
bf26cdc24f
commit
c8d5acceae
2 changed files with 25 additions and 3 deletions
|
@ -46,6 +46,9 @@ def assert_filename(uri, filename)
|
|||
SQLite3::Connection.filename(URI.parse(uri)).should eq(filename)
|
||||
end
|
||||
|
||||
class NotSupportedType
|
||||
end
|
||||
|
||||
describe Driver do
|
||||
it "should register sqlite3 name" do
|
||||
DB.driver_class("sqlite3").should eq(SQLite3::Driver)
|
||||
|
@ -111,7 +114,7 @@ describe Driver do
|
|||
|
||||
it "executes and selects blob" do
|
||||
with_db do |db|
|
||||
slice = db.scalar(%(select X'53514C697465')) as Slice(UInt8)
|
||||
slice = db.scalar(%(select X'53514C697465')).as(Slice(UInt8))
|
||||
slice.to_a.should eq([0x53, 0x51, 0x4C, 0x69, 0x74, 0x65])
|
||||
end
|
||||
end
|
||||
|
@ -119,7 +122,7 @@ describe Driver do
|
|||
it "executes with bind blob" do
|
||||
with_db do |db|
|
||||
ary = UInt8[0x53, 0x51, 0x4C, 0x69, 0x74, 0x65]
|
||||
slice = db.scalar(%(select cast(? as BLOB)), Slice.new(ary.to_unsafe, ary.size)) as Slice(UInt8)
|
||||
slice = db.scalar(%(select cast(? as BLOB)), Slice.new(ary.to_unsafe, ary.size)).as(Slice(UInt8))
|
||||
slice.to_a.should eq(ary)
|
||||
end
|
||||
end
|
||||
|
@ -192,11 +195,26 @@ describe Driver do
|
|||
db.exec "create table table1 (col1 blob)"
|
||||
db.exec %(insert into table1 values (?)), Slice.new(ary.to_unsafe, ary.size)
|
||||
|
||||
slice = db.scalar("select cast(col1 as blob) from table1") as Slice(UInt8)
|
||||
slice = db.scalar("select cast(col1 as blob) from table1").as(Slice(UInt8))
|
||||
slice.to_a.should eq(ary)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises on unsupported param types" do
|
||||
with_db do |db|
|
||||
expect_raises Exception, "SQLite3::Statement does not support NotSupportedType params" do
|
||||
db.query "select 1", NotSupportedType.new
|
||||
end
|
||||
# TODO raising exception does not close the connection and pool is exhausted
|
||||
end
|
||||
|
||||
with_db do |db|
|
||||
expect_raises Exception, "SQLite3::Statement does not support NotSupportedType params" do
|
||||
db.exec "select 1", NotSupportedType.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "gets many rows from table" do
|
||||
with_mem_db do |db|
|
||||
db.exec "create table person (name string, age integer)"
|
||||
|
|
|
@ -56,6 +56,10 @@ class SQLite3::Statement < DB::Statement
|
|||
check LibSQLite3.bind_blob(self, index, value, value.size, nil)
|
||||
end
|
||||
|
||||
private def bind_arg(index, value)
|
||||
raise "#{self.class} does not support #{value.class} params"
|
||||
end
|
||||
|
||||
private def check(code)
|
||||
raise Exception.new(@connection) unless code == 0
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue