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/statement.hxx | 68 ++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) (limited to 'odb/sqlite/statement.hxx') diff --git a/odb/sqlite/statement.hxx b/odb/sqlite/statement.hxx index 1be0cab..7344daf 100644 --- a/odb/sqlite/statement.hxx +++ b/odb/sqlite/statement.hxx @@ -30,7 +30,8 @@ namespace odb { class connection; - class LIBODB_SQLITE_EXPORT statement: public odb::statement + class LIBODB_SQLITE_EXPORT statement: public odb::statement, + public active_object { public: typedef sqlite::connection connection_type; @@ -72,7 +73,7 @@ namespace odb statement_kind sk, const binding* process, bool optimize) - : conn_ (conn) + : active_object (conn) { init (text.c_str (), text.size (), sk, process, optimize); } @@ -82,7 +83,7 @@ namespace odb statement_kind sk, const binding* process, bool optimize) - : conn_ (conn) + : active_object (conn) { init (text, std::strlen (text), sk, process, optimize); } @@ -93,13 +94,15 @@ namespace odb statement_kind sk, const binding* process, bool optimize) - : conn_ (conn) + : active_object (conn) { init (text, text_size, sk, process, optimize); } protected: - void + // Return true if we bound any stream parameters. + // + bool bind_param (const bind*, std::size_t count); // Extract row columns into the bound buffers. If the truncated @@ -110,6 +113,21 @@ namespace odb bool bind_result (const bind*, std::size_t count, bool truncated = false); + // Stream (so to speak) parameters. + // + struct stream_data + { + std::string db; + std::string table; + long long rowid; + }; + + void + stream_param (const bind*, std::size_t count, const stream_data&); + + friend void + update_hook (void*, const char*, const char*, long long); + // Active state. // protected: @@ -146,10 +164,12 @@ namespace odb return r; } - protected: - friend class sqlite::connection; + // The active_object interface. + // + virtual void + clear (); - connection_type& conn_; + protected: auto_handle stmt_; #if SQLITE_VERSION_NUMBER < 3005003 @@ -165,38 +185,6 @@ namespace odb statement_kind, const binding* process, bool optimize); - - // Doubly-linked list of active statements. - // - protected: - void - list_add () - { - next_ = conn_.statements_; - conn_.statements_ = this; - - if (next_ != 0) - next_->prev_ = this; - } - - void - list_remove () - { - (prev_ == 0 ? conn_.statements_ : prev_->next_) = next_; - - if (next_ != 0) - next_->prev_ = prev_; - - prev_ = 0; - next_ = this; - } - - // prev_ == 0 means we are the first element. - // next_ == 0 means we are the last element. - // next_ == this means we are not on the list (prev_ should be 0). - // - statement* prev_; - statement* next_; }; class LIBODB_SQLITE_EXPORT generic_statement: public statement -- cgit v1.1