mirror of
https://gitea.invidious.io/iv-org/shard-crystal-sqlite3.git
synced 2024-08-15 00:53:26 +00:00
add blob support
This commit is contained in:
parent
82f68ed6cf
commit
63f98d18d1
3 changed files with 37 additions and 2 deletions
|
@ -44,7 +44,17 @@ class SQLite3::ResultSet2 < DB::ResultSet
|
|||
end
|
||||
|
||||
def read(t : Float64.class) : Float64
|
||||
moving_column { LibSQLite3.column_double(self, @column_index) }
|
||||
moving_column { |col| LibSQLite3.column_double(self, col) }
|
||||
end
|
||||
|
||||
def read(t : Slice(UInt8).class) : Slice(UInt8)
|
||||
moving_column do |col|
|
||||
blob = LibSQLite3.column_blob(self, col)
|
||||
bytes = LibSQLite3.column_bytes(self, col)
|
||||
ptr = Pointer(UInt8).malloc(bytes)
|
||||
ptr.copy_from(blob, bytes)
|
||||
Slice(UInt8).new(ptr, bytes)
|
||||
end
|
||||
end
|
||||
|
||||
def to_unsafe
|
||||
|
@ -52,7 +62,11 @@ class SQLite3::ResultSet2 < DB::ResultSet
|
|||
end
|
||||
|
||||
private def read_nil?
|
||||
LibSQLite3.column_type(self, @column_index) == Type::NULL
|
||||
column_sqlite_type == Type::NULL
|
||||
end
|
||||
|
||||
private def column_sqlite_type
|
||||
LibSQLite3.column_type(self, @column_index)
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
|
|
|
@ -47,6 +47,10 @@ class SQLite3::Statement2 < DB::Statement
|
|||
check LibSQLite3.bind_text(self, index, value, value.bytesize, nil)
|
||||
end
|
||||
|
||||
private def bind_arg(index, value : Slice(UInt8))
|
||||
check LibSQLite3.bind_blob(self, index, value, value.size, 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