add blob support

This commit is contained in:
Brian J. Cardiff 2016-01-29 19:22:30 -03:00
parent 82f68ed6cf
commit 63f98d18d1
3 changed files with 37 additions and 2 deletions

View file

@ -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:

View file

@ -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