mirror of
https://gitea.invidious.io/iv-org/shard-crystal-sqlite3.git
synced 2024-08-15 00:53:26 +00:00
arguments support
This commit is contained in:
parent
efa010e2ad
commit
82f68ed6cf
3 changed files with 95 additions and 16 deletions
|
@ -4,11 +4,49 @@ class SQLite3::Statement2 < DB::Statement
|
|||
# @closed = false
|
||||
end
|
||||
|
||||
def exec(*args)
|
||||
protected def before_execute
|
||||
LibSQLite3.reset(self)
|
||||
end
|
||||
|
||||
protected def add_parameter(index : Int32, value)
|
||||
bind_arg(index, value)
|
||||
end
|
||||
|
||||
protected def add_parameter(name : String, value)
|
||||
converted_name = ":#{name}"
|
||||
index = LibSQLite3.bind_parameter_index(self, converted_name)
|
||||
raise "Unknown parameter: #{name}" if index == 0
|
||||
bind_arg(index, value)
|
||||
end
|
||||
|
||||
protected def execute
|
||||
ResultSet2.new(self)
|
||||
end
|
||||
|
||||
private def bind_arg(index, value : Nil)
|
||||
check LibSQLite3.bind_null(self, index)
|
||||
end
|
||||
|
||||
private def bind_arg(index, value : Int32)
|
||||
check LibSQLite3.bind_int(self, index, value)
|
||||
end
|
||||
|
||||
private def bind_arg(index, value : Int64)
|
||||
check LibSQLite3.bind_int64(self, index, value)
|
||||
end
|
||||
|
||||
private def bind_arg(index, value : Float32)
|
||||
check LibSQLite3.bind_double(self, index, value.to_f64)
|
||||
end
|
||||
|
||||
private def bind_arg(index, value : Float64)
|
||||
check LibSQLite3.bind_double(self, index, value)
|
||||
end
|
||||
|
||||
private def bind_arg(index, value : String)
|
||||
check LibSQLite3.bind_text(self, index, value, value.bytesize, nil)
|
||||
end
|
||||
|
||||
private def check(code)
|
||||
raise Exception.new(@driver) unless code == 0
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue