3
3
* @ingroup SQLiteCpp
4
4
* @brief Step executor for SQLite prepared Statement Object
5
5
*
6
- * Copyright (c) 2015 Shibao HONG ([email protected] )
7
- * Copyright (c) 2015-2021 Sebastien Rombauts ([email protected] )
6
+ * Copyright (c) 2012-2021 Sebastien Rombauts ([email protected] )
8
7
*
9
8
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
10
9
* or copy at http://opensource.org/licenses/MIT)
11
10
*/
12
11
#pragma once
13
12
13
+ #include < SQLiteCpp/StatementPtr.h>
14
14
#include < SQLiteCpp/Row.h>
15
15
#include < SQLiteCpp/Exception.h>
16
16
17
17
#include < memory>
18
18
#include < string>
19
19
#include < map>
20
20
21
- // Forward declaration to avoid inclusion of <sqlite3.h> in a header
22
- struct sqlite3_stmt ;
23
21
24
22
namespace SQLite
25
23
{
@@ -44,24 +42,13 @@ extern const int OK; ///< SQLITE_OK
44
42
class StatementExecutor
45
43
{
46
44
public:
47
- // / Shared pointer to SQLite Prepared Statement Object
48
- using TStatementPtr = std::shared_ptr<sqlite3_stmt>;
49
-
50
- // / Weak pointer to SQLite Prepared Statement Object
51
- using TStatementWeakPtr = std::weak_ptr<sqlite3_stmt>;
52
-
53
- // / Shared pointer to SQLite StatementExecutor
54
- using TRowPtr = std::shared_ptr<StatementExecutor>;
55
-
56
- // / Weak pointer to SQLite StatementExecutor
57
- using TRowWeakPtr = std::weak_ptr<StatementExecutor>;
58
-
59
45
// / Type to store columns names and indexes
60
46
using TColumnsMap = std::map<std::string, int , std::less<>>;
61
47
62
48
StatementExecutor (const StatementExecutor&) = delete ;
63
- StatementExecutor (StatementExecutor&&) = default ;
64
49
StatementExecutor& operator =(const StatementExecutor&) = delete ;
50
+
51
+ StatementExecutor (StatementExecutor&&) = default ;
65
52
StatementExecutor& operator =(StatementExecutor&&) = default ;
66
53
67
54
// / Reset the statement to make it ready for a new execution. Throws an exception on error.
@@ -180,8 +167,8 @@ class StatementExecutor
180
167
using difference_type = std::ptrdiff_t ;
181
168
182
169
RowIterator () = default ;
183
- RowIterator (TStatementWeakPtr apStatement, TRowWeakPtr apRow , uint16_t aID) :
184
- mpStatement (apStatement), mpRow(apRow), mID (aID), mRow (apStatement, aID) {}
170
+ RowIterator (TRowWeakPtr apStatement , uint16_t aID) :
171
+ mpStatement (apStatement), mID (aID), mRow (apStatement, aID) {}
185
172
186
173
reference operator *() const
187
174
{
@@ -216,8 +203,7 @@ class StatementExecutor
216
203
// / Executing next statement step
217
204
void advance () noexcept ;
218
205
219
- TStatementWeakPtr mpStatement{}; // !< Weak pointer to SQLite Statement Object
220
- TRowWeakPtr mpRow{}; // !< Weak pointer to StatementExecutor Object
206
+ TRowWeakPtr mpStatement{}; // !< Weak pointer to prepared Statement Object
221
207
uint16_t mID {}; // !< Current row number
222
208
223
209
// / Internal row object storage
@@ -256,9 +242,9 @@ class StatementExecutor
256
242
*
257
243
* @return raw pointer to Statement Object
258
244
*/
259
- TStatementPtr getStatement () const noexcept
245
+ StatementPtr:: TStatementPtr getStatement () const noexcept
260
246
{
261
- return mpStatement;
247
+ return mpStatement-> mpStatement ;
262
248
}
263
249
264
250
/* *
@@ -277,7 +263,7 @@ class StatementExecutor
277
263
*/
278
264
TRowWeakPtr getExecutorWeakPtr () const
279
265
{
280
- return mpRowExecutor ;
266
+ return mpStatement ;
281
267
}
282
268
283
269
// //////////////////////////////////////////////////////////////////////////
@@ -291,7 +277,7 @@ class StatementExecutor
291
277
{
292
278
if (SQLite::OK != aRet)
293
279
{
294
- throw SQLite::Exception (mpSQLite , aRet);
280
+ throw SQLite::Exception (mpStatement-> mpConnection , aRet);
295
281
}
296
282
}
297
283
@@ -318,18 +304,17 @@ class StatementExecutor
318
304
}
319
305
320
306
private:
321
- // / Create prepared SQLite Statement Object
322
- void prepareStatement (const std::string& aQuery);
323
-
324
307
// / Get column number and create map with columns names
325
308
void createColumnInfo ();
326
309
327
- sqlite3* mpSQLite{}; // !< Pointer to SQLite Database Connection Handle
328
- TStatementPtr mpStatement{}; // !< Shared Pointer to the prepared SQLite Statement Object
310
+ // xD
311
+ bool checkReturnCode (int aReturnCode) const ;
312
+ // xD
313
+ bool checkReturnCode (int aReturnCode, int aErrorCode) const ;
329
314
330
315
// / Shared Pointer to this object.
331
316
// / Allows RowIterator to execute next step
332
- TRowPtr mpRowExecutor {};
317
+ TRowPtr mpStatement {};
333
318
334
319
int mColumnCount = 0 ; // !< Number of columns in the result of the prepared statement
335
320
bool mbHasRow = false ; // !< true when a row has been fetched with executeStep()
0 commit comments