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/stream.hxx | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 odb/sqlite/stream.hxx (limited to 'odb/sqlite/stream.hxx') diff --git a/odb/sqlite/stream.hxx b/odb/sqlite/stream.hxx new file mode 100644 index 0000000..387dcf0 --- /dev/null +++ b/odb/sqlite/stream.hxx @@ -0,0 +1,82 @@ +// file : odb/sqlite/stream.hxx +// copyright : Copyright (c) 2005-2015 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_SQLITE_STREAM_HXX +#define ODB_SQLITE_STREAM_HXX + +#include + +#include + +#include // std::size_t + +#include +#include + +namespace odb +{ + namespace sqlite + { + // SQLite incremental BLOB/TEXT I/O stream. Available since + // SQLite 3.4.0. + // + class LIBODB_SQLITE_EXPORT stream: public active_object + { + public: + stream (const char* db, + const char* table, + const char* column, + long long rowid, + bool rw); + + std::size_t + size () const; + + // The following two functions throw std::invalid_argument if + // offset + n is past size(). + // + void + read (void* buf, std::size_t n, std::size_t offset = 0); + + void + write (const void* buf, std::size_t n, std::size_t offset = 0); + + sqlite3_blob* + handle () const {return h_;} + + // Close without reporting errors, if any. + // + virtual + ~stream () {close (false);} + + // Close, by default with reporting errors, if any. + // + void + close (bool check = true); + + // Open the same BLOB but in a different row. Can be faster + // than creating a new stream instance. Note that the stream + // must be in the open state prior to calling this function. + // Only available since SQLite 3.7.4. + // +#if SQLITE_VERSION_NUMBER >= 3007004 + void + reopen (long long rowid); +#endif + + protected: + // The active_object interface. + // + virtual void + clear (); + + private: + sqlite3_blob* h_; + }; + } +} + +#include + +#endif // ODB_SQLITE_STREAM_HXX -- cgit v1.1