diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-24 19:01:19 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-24 19:01:19 +0300 |
commit | e5d0186db99492a139237067bab841a5b83463af (patch) | |
tree | 61719595e998314e58383c5081da16d7457a63e7 /libodb-sqlite/odb/sqlite/stream.hxx | |
parent | c53136bd7d266fccaca679d0471dd8ac0ce91373 (diff) |
Turn libodb-sqlite repository into package for muti-package repositorylibodb-sqlite
Diffstat (limited to 'libodb-sqlite/odb/sqlite/stream.hxx')
-rw-r--r-- | libodb-sqlite/odb/sqlite/stream.hxx | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/libodb-sqlite/odb/sqlite/stream.hxx b/libodb-sqlite/odb/sqlite/stream.hxx new file mode 100644 index 0000000..6ee76cb --- /dev/null +++ b/libodb-sqlite/odb/sqlite/stream.hxx @@ -0,0 +1,85 @@ +// file : odb/sqlite/stream.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_SQLITE_STREAM_HXX +#define ODB_SQLITE_STREAM_HXX + +#include <odb/pre.hxx> + +#include <sqlite3.h> + +#include <cstddef> // std::size_t + +#include <odb/sqlite/connection.hxx> +#include <odb/sqlite/details/export.hxx> + +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: + // @@ TODO: db is actually what we now (and SQLite in other places) + // call schema (see database::schema(), ATTACH DATABASE). So we + // should probably rename this at some point for consistency. + // + 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 <odb/post.hxx> + +#endif // ODB_SQLITE_STREAM_HXX |