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
17+ #include < iterator>
1718#include < memory>
1819#include < string>
1920#include < map>
2021
21- // Forward declaration to avoid inclusion of <sqlite3.h> in a header
22- struct sqlite3_stmt ;
2322
2423namespace SQLite
2524{
@@ -44,24 +43,13 @@ extern const int OK; ///< SQLITE_OK
4443class StatementExecutor
4544{
4645public:
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-
5946 // / Type to store columns names and indexes
6047 using TColumnsMap = std::map<std::string, int , std::less<>>;
6148
6249 StatementExecutor (const StatementExecutor&) = delete ;
63- StatementExecutor (StatementExecutor&&) = default ;
6450 StatementExecutor& operator =(const StatementExecutor&) = delete ;
51+
52+ StatementExecutor (StatementExecutor&&) = default ;
6553 StatementExecutor& operator =(StatementExecutor&&) = default ;
6654
6755 // / Reset the statement to make it ready for a new execution. Throws an exception on error.
@@ -180,8 +168,8 @@ class StatementExecutor
180168 using difference_type = std::ptrdiff_t ;
181169
182170 RowIterator () = default ;
183- RowIterator (TStatementWeakPtr apStatement, TRowWeakPtr apRow , uint16_t aID) :
184- mpStatement (apStatement), mpRow(apRow), mID (aID), mRow (apStatement, aID) {}
171+ RowIterator (TRowWeakPtr apStatement , uint16_t aID) :
172+ mpStatement (apStatement), mID (aID), mRow (apStatement, aID) {}
185173
186174 reference operator *() const
187175 {
@@ -216,8 +204,7 @@ class StatementExecutor
216204 // / Executing next statement step
217205 void advance () noexcept ;
218206
219- TStatementWeakPtr mpStatement{}; // !< Weak pointer to SQLite Statement Object
220- TRowWeakPtr mpRow{}; // !< Weak pointer to StatementExecutor Object
207+ TRowWeakPtr mpStatement{}; // !< Weak pointer to prepared Statement Object
221208 uint16_t mID {}; // !< Current row number
222209
223210 // / Internal row object storage
@@ -256,9 +243,9 @@ class StatementExecutor
256243 *
257244 * @return raw pointer to Statement Object
258245 */
259- TStatementPtr getStatement () const noexcept
246+ StatementPtr:: TStatementPtr getStatement () const noexcept
260247 {
261- return mpStatement;
248+ return mpStatement-> mpStatement ;
262249 }
263250
264251 /* *
@@ -277,7 +264,7 @@ class StatementExecutor
277264 */
278265 TRowWeakPtr getExecutorWeakPtr () const
279266 {
280- return mpRowExecutor ;
267+ return mpStatement ;
281268 }
282269
283270 // //////////////////////////////////////////////////////////////////////////
@@ -291,7 +278,7 @@ class StatementExecutor
291278 {
292279 if (SQLite::OK != aRet)
293280 {
294- throw SQLite::Exception (mpSQLite , aRet);
281+ throw SQLite::Exception (mpStatement-> mpConnection , aRet);
295282 }
296283 }
297284
@@ -318,18 +305,17 @@ class StatementExecutor
318305 }
319306
320307private:
321- // / Create prepared SQLite Statement Object
322- void prepareStatement (const std::string& aQuery);
323-
324308 // / Get column number and create map with columns names
325309 void createColumnInfo ();
326310
327- sqlite3* mpSQLite{}; // !< Pointer to SQLite Database Connection Handle
328- TStatementPtr mpStatement{}; // !< Shared Pointer to the prepared SQLite Statement Object
311+ // xD
312+ bool checkReturnCode (int aReturnCode) const ;
313+ // xD
314+ bool checkReturnCode (int aReturnCode, int aErrorCode) const ;
329315
330316 // / Shared Pointer to this object.
331317 // / Allows RowIterator to execute next step
332- TRowPtr mpRowExecutor {};
318+ TRowPtr mpStatement {};
333319
334320 int mColumnCount = 0 ; // !< Number of columns in the result of the prepared statement
335321 bool mbHasRow = false ; // !< true when a row has been fetched with executeStep()
0 commit comments