Mercurial > hg > orthanc-databases
diff Framework/Common/DatabaseManager.h @ 70:e6c13ddd26d9 db-changes
all integration tests passing with LookupResources extension
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 03 Jan 2019 14:04:46 +0100 |
parents | 714c5d2bee76 |
children | 52c70007bb87 |
line wrap: on
line diff
--- a/Framework/Common/DatabaseManager.h Thu Jan 03 10:07:27 2019 +0100 +++ b/Framework/Common/DatabaseManager.h Thu Jan 03 14:04:46 2019 +0100 @@ -111,36 +111,51 @@ }; - class CachedStatement : public boost::noncopyable + class StatementBase : public boost::noncopyable { private: DatabaseManager& manager_; boost::recursive_mutex::scoped_lock lock_; - IDatabase& database_; - StatementLocation location_; ITransaction& transaction_; - IPrecompiledStatement* statement_; std::auto_ptr<Query> query_; std::auto_ptr<IResult> result_; - void Setup(const char* sql); - IResult& GetResult() const; - public: - CachedStatement(const StatementLocation& location, - DatabaseManager& manager, - const char* sql); + protected: + DatabaseManager& GetManager() const + { + return manager_; + } + + ITransaction& GetTransaction() const + { + return transaction_; + } + + void SetQuery(Query* query); + + void SetResult(IResult* result); - CachedStatement(const StatementLocation& location, - Transaction& transaction, - const char* sql); + void ClearResult() + { + result_.reset(); + } - ~CachedStatement(); + Query* ReleaseQuery() + { + return query_.release(); + } + public: + StatementBase(DatabaseManager& manager); + + virtual ~StatementBase(); + + // Used only by SQLite IDatabase& GetDatabase() { - return database_; + return manager_.GetDatabase(); } void SetReadOnly(bool readOnly); @@ -148,10 +163,6 @@ void SetParameterType(const std::string& parameter, ValueType type); - void Execute(); - - void Execute(const Dictionary& parameters); - bool IsDone() const; void Next(); @@ -163,5 +174,41 @@ const IValue& GetResultField(size_t index) const; }; + + + class CachedStatement : public StatementBase + { + private: + StatementLocation location_; + IPrecompiledStatement* statement_; + + public: + CachedStatement(const StatementLocation& location, + DatabaseManager& manager, + const std::string& sql); + + void Execute() + { + Dictionary parameters; + Execute(parameters); + } + + void Execute(const Dictionary& parameters); + }; + + + class StandaloneStatement : public StatementBase + { + private: + std::auto_ptr<IPrecompiledStatement> statement_; + + public: + StandaloneStatement(DatabaseManager& manager, + const std::string& sql); + + virtual ~StandaloneStatement(); + + void Execute(const Dictionary& parameters); + }; }; }