33 * @ingroup SQLiteCpp
44 * @brief Step executor for SQLite prepared Statement Object
55 *
6- * Copyright (c) 2015 Shibao HONG (shibaohong@outlook.com)
7- * Copyright (c) 2015-2021 Sebastien Rombauts (sebastien.rombauts@gmail.com)
6+ * Copyright (c) 2012-2021 Sebastien Rombauts (sebastien.rombauts@gmail.com)
87 *
98 * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
109 * or copy at http://opensource.org/licenses/MIT)
1110 */
1211#pragma once
1312
13+ #include < SQLiteCpp/StatementPtr.h>
1414#include < SQLiteCpp/Row.h>
1515#include < SQLiteCpp/Exception.h>
1616
1717#include < memory>
1818#include < string>
1919#include < map>
2020
21- // Forward declaration to avoid inclusion of <sqlite3.h> in a header
22- struct sqlite3_stmt ;
2321
2422namespace SQLite
2523{
@@ -44,24 +42,13 @@ extern const int OK; ///< SQLITE_OK
4442class StatementExecutor
4543{
4644public:
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-
5945 // / Type to store columns names and indexes
6046 using TColumnsMap = std::map<std::string, int , std::less<>>;
6147
6248 StatementExecutor (const StatementExecutor&) = delete ;
63- StatementExecutor (StatementExecutor&&) = default ;
6449 StatementExecutor& operator =(const StatementExecutor&) = delete ;
50+
51+ StatementExecutor (StatementExecutor&&) = default ;
6552 StatementExecutor& operator =(StatementExecutor&&) = default ;
6653
6754 // / Reset the statement to make it ready for a new execution. Throws an exception on error.
@@ -180,8 +167,8 @@ class StatementExecutor
180167 using difference_type = std::ptrdiff_t ;
181168
182169 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) {}
185172
186173 reference operator *() const
187174 {
@@ -216,8 +203,7 @@ class StatementExecutor
216203 // / Executing next statement step
217204 void advance () noexcept ;
218205
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
221207 uint16_t mID {}; // !< Current row number
222208
223209 // / Internal row object storage
@@ -256,9 +242,9 @@ class StatementExecutor
256242 *
257243 * @return raw pointer to Statement Object
258244 */
259- TStatementPtr getStatement () const noexcept
245+ StatementPtr:: TStatementPtr getStatement () const noexcept
260246 {
261- return mpStatement;
247+ return mpStatement-> mpStatement ;
262248 }
263249
264250 /* *
@@ -277,7 +263,7 @@ class StatementExecutor
277263 */
278264 TRowWeakPtr getExecutorWeakPtr () const
279265 {
280- return mpRowExecutor ;
266+ return mpStatement ;
281267 }
282268
283269 // //////////////////////////////////////////////////////////////////////////
@@ -291,7 +277,7 @@ class StatementExecutor
291277 {
292278 if (SQLite::OK != aRet)
293279 {
294- throw SQLite::Exception (mpSQLite , aRet);
280+ throw SQLite::Exception (mpStatement-> mpConnection , aRet);
295281 }
296282 }
297283
@@ -318,18 +304,17 @@ class StatementExecutor
318304 }
319305
320306private:
321- // / Create prepared SQLite Statement Object
322- void prepareStatement (const std::string& aQuery);
323-
324307 // / Get column number and create map with columns names
325308 void createColumnInfo ();
326309
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 ;
329314
330315 // / Shared Pointer to this object.
331316 // / Allows RowIterator to execute next step
332- TRowPtr mpRowExecutor {};
317+ TRowPtr mpStatement {};
333318
334319 int mColumnCount = 0 ; // !< Number of columns in the result of the prepared statement
335320 bool mbHasRow = false ; // !< true when a row has been fetched with executeStep()
0 commit comments