|
36 | 36 | #include "errors.h"
|
37 | 37 |
|
38 | 38 | namespace sqlite {
|
| 39 | + using blob_t = std::pair<void const*, int>; |
| 40 | + |
39 | 41 | template<class T, int Type, class = void>
|
40 | 42 | struct has_sqlite_type : std::false_type {};
|
41 | 43 |
|
@@ -249,6 +251,31 @@ namespace sqlite {
|
249 | 251 | return std::vector<T, A>(buf, buf + bytes/sizeof(T));
|
250 | 252 | }
|
251 | 253 |
|
| 254 | + // blob_t |
| 255 | + template<> |
| 256 | + struct has_sqlite_type<blob_t, SQLITE_BLOB, void> : std::true_type {}; |
| 257 | + |
| 258 | + inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, const blob_t& blob) { |
| 259 | + return sqlite3_bind_blob(stmt, inx, blob.first, blob.second, SQLITE_TRANSIENT); |
| 260 | + } |
| 261 | + inline void store_result_in_db(sqlite3_context* db, const blob_t& blob) { |
| 262 | + sqlite3_result_blob(db, blob.first, blob.second, SQLITE_TRANSIENT); |
| 263 | + } |
| 264 | + inline blob_t get_col_from_db(sqlite3_stmt* stmt, int inx, result_type<blob_t>) { |
| 265 | + if(sqlite3_column_type(stmt, inx) == SQLITE_NULL) { |
| 266 | + return blob_t(nullptr, 0); |
| 267 | + } |
| 268 | + int bytes = sqlite3_column_bytes(stmt, inx); |
| 269 | + return blob_t(sqlite3_column_blob(stmt, inx), bytes); |
| 270 | + } |
| 271 | + inline blob_t get_val_from_db(sqlite3_value *value, result_type<blob_t>) { |
| 272 | + if(sqlite3_value_type(value) == SQLITE_NULL) { |
| 273 | + return blob_t(nullptr, 0); |
| 274 | + } |
| 275 | + int bytes = sqlite3_value_bytes(value); |
| 276 | + return blob_t(sqlite3_value_blob(value), bytes); |
| 277 | + } |
| 278 | + |
252 | 279 | /* for unique_ptr<T> support */
|
253 | 280 | template<typename T, int Type>
|
254 | 281 | struct has_sqlite_type<std::unique_ptr<T>, Type, void> : has_sqlite_type<T, Type> {};
|
|
0 commit comments