From 2785e69fc17e30a0785efba9591104ed69fb6a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 29 Aug 2017 19:27:47 +0200 Subject: [PATCH] Data adopts StatementColumnConvertible --- GRDB/Core/Support/Foundation/Data.swift | 13 ++++++++++++- TODO.md | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/GRDB/Core/Support/Foundation/Data.swift b/GRDB/Core/Support/Foundation/Data.swift index 0210a13e9..275fcbb23 100644 --- a/GRDB/Core/Support/Foundation/Data.swift +++ b/GRDB/Core/Support/Foundation/Data.swift @@ -1,7 +1,18 @@ import Foundation +#if SWIFT_PACKAGE + import CSQLite +#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER + import SQLite3 +#endif /// Data is convertible to and from DatabaseValue. -extension Data : DatabaseValueConvertible { +extension Data : DatabaseValueConvertible, StatementColumnConvertible { + public init(sqliteStatement: SQLiteStatement, index: Int32) { + let bytes = unsafeBitCast(sqlite3_column_blob(sqliteStatement, Int32(index)), to: UnsafePointer.self) + let count = Int(sqlite3_column_bytes(sqliteStatement, Int32(index))) + self.init(bytes: bytes, count: count) // copy bytes + } + /// Returns a value that can be stored in the database. public var databaseValue: DatabaseValue { // SQLite cant' store zero-length blobs. diff --git a/TODO.md b/TODO.md index e840401bf..f65b10482 100644 --- a/TODO.md +++ b/TODO.md @@ -18,6 +18,7 @@ GRDB 2.0 - [ ] New concrete cursors - [ ] check performance improvements - [ ] document +- [ ] Test new adoption of StatementColumnConvertible by Data. Add support for NSData if possible/needed. Not sure