From 0f9cfacd6cc45f78f1453a8eeb7ffa542dc5dc48 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 15 Jul 2015 18:43:03 +0200 Subject: Implement SQLite incremental BLOB/TEXT I/O --- odb/sqlite/traits.hxx | 146 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 138 insertions(+), 8 deletions(-) (limited to 'odb/sqlite/traits.hxx') diff --git a/odb/sqlite/traits.hxx b/odb/sqlite/traits.hxx index de8e3c3..dc4d113 100644 --- a/odb/sqlite/traits.hxx +++ b/odb/sqlite/traits.hxx @@ -25,22 +25,18 @@ #include #include +#include #include #include #include +#include +#include + namespace odb { namespace sqlite { - enum database_type_id - { - id_integer, - id_real, - id_text, - id_blob - }; - // // image_traits // @@ -67,6 +63,18 @@ namespace odb template struct image_traits {typedef details::buffer image_type;}; + template + struct image_traits + { + typedef stream_buffers image_type; + }; + + template + struct image_traits + { + typedef stream_buffers image_type; + }; + // // value_traits // @@ -140,6 +148,20 @@ namespace odb { vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); } + + // TEXT and BLOB STREAM. + // + static void + set_value (W& v, const stream_buffers& b, std::size_t n, bool is_null) + { + vtraits::set_value (wtraits::set_ref (v), b, n, is_null); + } + + static void + set_image (stream_buffers& b, std::size_t& n, bool& is_null, const W& v) + { + vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); + } }; template @@ -191,6 +213,26 @@ namespace odb if (!is_null) vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); } + + // TEXT and BLOB STREAM. + // + static void + set_value (W& v, const stream_buffers& b, std::size_t n, bool is_null) + { + if (is_null) + wtraits::set_null (v); + else + vtraits::set_value (wtraits::set_ref (v), b, n, is_null); + } + + static void + set_image (stream_buffers& b, std::size_t& n, bool& is_null, const W& v) + { + is_null = wtraits::get_null (v); + + if (!is_null) + vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); + } }; template @@ -811,6 +853,82 @@ namespace odb }; #endif + // text (stream) specialization. + // + template <> + struct LIBODB_SQLITE_EXPORT default_value_traits + { + public: + typedef text value_type; + typedef std::string query_type; + typedef stream_buffers image_type; + + static void + set_value (text& v, const stream_buffers& b, std::size_t, bool is_null) + { + if (!is_null) + { + v.db_ = b.db.in; + v.table_ = b.table.in; + v.column_ = b.column.in; + v.rowid_ = b.rowid.in; + } + } + + static void + set_image (stream_buffers& b, + std::size_t& n, + bool& is_null, + const text& v) + { + is_null = false; + n = v.size_; + + b.db.out = &v.db_; + b.table.out = &v.table_; + b.column.out = &v.column_; + b.rowid.out = &v.rowid_; + } + }; + + // blob (stream) specialization. + // + template <> + struct LIBODB_SQLITE_EXPORT default_value_traits + { + public: + typedef blob value_type; + typedef std::vector query_type; + typedef stream_buffers image_type; + + static void + set_value (blob& v, const stream_buffers& b, std::size_t, bool is_null) + { + if (!is_null) + { + v.db_ = b.db.in; + v.table_ = b.table.in; + v.column_ = b.column.in; + v.rowid_ = b.rowid.in; + } + } + + static void + set_image (stream_buffers& b, + std::size_t& n, + bool& is_null, + const blob& v) + { + is_null = false; + n = v.size_; + + b.db.out = &v.db_; + b.table.out = &v.table_; + b.column.out = &v.column_; + b.rowid.out = &v.rowid_; + } + }; + // // type_traits // @@ -970,6 +1088,18 @@ namespace odb static const database_type_id db_type_id = id_blob; }; #endif + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_text_stream; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_blob_stream; + }; } } -- cgit v1.1