comparison 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
comparison
equal deleted inserted replaced
69:19764fc60ade 70:e6c13ddd26d9
109 return database_; 109 return database_;
110 } 110 }
111 }; 111 };
112 112
113 113
114 class CachedStatement : public boost::noncopyable 114 class StatementBase : public boost::noncopyable
115 { 115 {
116 private: 116 private:
117 DatabaseManager& manager_; 117 DatabaseManager& manager_;
118 boost::recursive_mutex::scoped_lock lock_; 118 boost::recursive_mutex::scoped_lock lock_;
119 IDatabase& database_;
120 StatementLocation location_;
121 ITransaction& transaction_; 119 ITransaction& transaction_;
122 IPrecompiledStatement* statement_;
123 std::auto_ptr<Query> query_; 120 std::auto_ptr<Query> query_;
124 std::auto_ptr<IResult> result_; 121 std::auto_ptr<IResult> result_;
125 122
126 void Setup(const char* sql);
127
128 IResult& GetResult() const; 123 IResult& GetResult() const;
124
125 protected:
126 DatabaseManager& GetManager() const
127 {
128 return manager_;
129 }
130
131 ITransaction& GetTransaction() const
132 {
133 return transaction_;
134 }
135
136 void SetQuery(Query* query);
137
138 void SetResult(IResult* result);
139
140 void ClearResult()
141 {
142 result_.reset();
143 }
144
145 Query* ReleaseQuery()
146 {
147 return query_.release();
148 }
149
150 public:
151 StatementBase(DatabaseManager& manager);
152
153 virtual ~StatementBase();
154
155 // Used only by SQLite
156 IDatabase& GetDatabase()
157 {
158 return manager_.GetDatabase();
159 }
160
161 void SetReadOnly(bool readOnly);
162
163 void SetParameterType(const std::string& parameter,
164 ValueType type);
165
166 bool IsDone() const;
167
168 void Next();
169
170 size_t GetResultFieldsCount() const;
171
172 void SetResultFieldType(size_t field,
173 ValueType type);
174
175 const IValue& GetResultField(size_t index) const;
176 };
177
178
179 class CachedStatement : public StatementBase
180 {
181 private:
182 StatementLocation location_;
183 IPrecompiledStatement* statement_;
129 184
130 public: 185 public:
131 CachedStatement(const StatementLocation& location, 186 CachedStatement(const StatementLocation& location,
132 DatabaseManager& manager, 187 DatabaseManager& manager,
133 const char* sql); 188 const std::string& sql);
134 189
135 CachedStatement(const StatementLocation& location, 190 void Execute()
136 Transaction& transaction, 191 {
137 const char* sql); 192 Dictionary parameters;
138 193 Execute(parameters);
139 ~CachedStatement(); 194 }
140
141 IDatabase& GetDatabase()
142 {
143 return database_;
144 }
145
146 void SetReadOnly(bool readOnly);
147
148 void SetParameterType(const std::string& parameter,
149 ValueType type);
150
151 void Execute();
152 195
153 void Execute(const Dictionary& parameters); 196 void Execute(const Dictionary& parameters);
154 197 };
155 bool IsDone() const; 198
156 199
157 void Next(); 200 class StandaloneStatement : public StatementBase
158 201 {
159 size_t GetResultFieldsCount() const; 202 private:
160 203 std::auto_ptr<IPrecompiledStatement> statement_;
161 void SetResultFieldType(size_t field, 204
162 ValueType type); 205 public:
163 206 StandaloneStatement(DatabaseManager& manager,
164 const IValue& GetResultField(size_t index) const; 207 const std::string& sql);
208
209 virtual ~StandaloneStatement();
210
211 void Execute(const Dictionary& parameters);
165 }; 212 };
166 }; 213 };
167 } 214 }