33 * @ingroup SQLiteCpp
44 * @brief Step executor for SQLite prepared Statement Object
55 *
6+ * Copyright (c) 2022 Kacper Zielinski (KacperZ155@gmail.com)
67 * Copyright (c) 2012-2021 Sebastien Rombauts (sebastien.rombauts@gmail.com)
78 *
89 * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
@@ -38,7 +39,7 @@ extern const int OK; ///< SQLITE_OK
3839* 2) the SQLite "Serialized" mode is not supported by SQLiteC++,
3940* because of the way it shares the underling SQLite precompiled statement
4041* in a custom shared pointer (See the inner class "Statement::Ptr").
41- * TODO Test Serialized mode after all changes to pointers
42+ * TODO: Test Serialized mode after all changes to pointers
4243*/
4344class StatementExecutor
4445{
@@ -52,7 +53,12 @@ class StatementExecutor
5253 StatementExecutor (StatementExecutor&&) = default ;
5354 StatementExecutor& operator =(StatementExecutor&&) = default ;
5455
55- // / Reset the statement to make it ready for a new execution. Throws an exception on error.
56+ /* *
57+ * @brief Reset the statement to make it ready for a new execution.
58+ * This doesn't clear bindings!
59+ *
60+ * @throws SQLite::Exception in case of error
61+ */
5662 void reset ();
5763
5864 // / Reset the statement. Returns the sqlite result code instead of throwing an exception on error.
@@ -124,7 +130,7 @@ class StatementExecutor
124130 }
125131
126132 // / Get columns names with theirs ids
127- const TColumnsMap& getColumnsNames () const
133+ const TColumnsMap& getColumnsNames () const noexcept
128134 {
129135 return mColumnNames ;
130136 }
@@ -168,10 +174,10 @@ class StatementExecutor
168174 using difference_type = std::ptrdiff_t ;
169175
170176 RowIterator () = default ;
171- RowIterator (TRowWeakPtr apStatement, uint16_t aID) :
177+ RowIterator (TStatementWeakPtr apStatement, uint16_t aID) :
172178 mpStatement (apStatement), mID (aID), mRow (apStatement, aID) {}
173179
174- reference operator *() const
180+ reference operator *() const noexcept
175181 {
176182 return mRow ;
177183 }
@@ -180,22 +186,22 @@ class StatementExecutor
180186 return &mRow ;
181187 }
182188
183- reference operator ++() noexcept
189+ RowIterator& operator ++() noexcept
184190 {
185191 mRow = Row (mpStatement, ++mID );
186192 advance ();
187- return mRow ;
193+ return * this ;
188194 }
189- value_type operator ++(int )
195+ // / Prefer to use prefix increment (++it)
196+ RowIterator operator ++(int ) noexcept
190197 {
191- Row copy{ mRow };
192- mRow = Row (mpStatement, ++mID );
198+ RowIterator copy{ *this };
193199 advance ();
194200 return copy;
195201 }
196202
197- bool operator ==(const RowIterator& aIt) const ;
198- bool operator !=(const RowIterator& aIt) const
203+ bool operator ==(const RowIterator& aIt) const noexcept ;
204+ bool operator !=(const RowIterator& aIt) const noexcept
199205 {
200206 return !(*this == aIt);
201207 }
@@ -204,7 +210,7 @@ class StatementExecutor
204210 // / Executing next statement step
205211 void advance () noexcept ;
206212
207- TRowWeakPtr mpStatement{}; // !< Weak pointer to prepared Statement Object
213+ TStatementWeakPtr mpStatement{}; // !< Weak pointer to prepared Statement Object
208214 uint16_t mID {}; // !< Current row number
209215
210216 // / Internal row object storage
@@ -223,9 +229,12 @@ class StatementExecutor
223229 RowIterator begin ();
224230
225231 /* *
232+ * @brief Empty RowIterator without any connection to exisiting statements.
233+ * Use to find if RowIterator is out of steps.
234+ *
226235 * @return RowIterator to non-exisitng step
227236 */
228- RowIterator end ();
237+ RowIterator end () noexcept ;
229238
230239protected:
231240 /* *
@@ -239,40 +248,33 @@ class StatementExecutor
239248 explicit StatementExecutor (sqlite3* apSQLite, const std::string& aQuery);
240249
241250 /* *
242- * @brief Return a std::shared_ptr with SQLite Statement Object.
251+ * @brief Return a std::shared_ptr with prepared SQLite Statement Object.
243252 *
244- * @return raw pointer to Statement Object
253+ * @return TRawStatementPtr with SQLite Statement Object
245254 */
246- StatementPtr::TStatementPtr getStatement () const noexcept
255+ StatementPtr::TRawStatementPtr getStatementPtr () const noexcept
247256 {
248257 return mpStatement->mpStatement ;
249258 }
250259
251260 /* *
252- * @brief Return a prepared SQLite Statement Object.
261+ * @brief Return a pointer to prepared SQLite Statement Object.
253262 *
254- * Throw an exception if the statement object was not prepared.
255- * @return raw pointer to Prepared Statement Object
263+ * @return Raw pointer to SQLite Statement Object
256264 */
257- sqlite3_stmt* getPreparedStatement () const ;
258-
259- /* *
260- * @brief Return a prepared SQLite Statement Object.
261- *
262- * Throw an exception if the statement object was not prepared.
263- * @return raw pointer to Prepared Statement Object
264- */
265- TRowWeakPtr getExecutorWeakPtr () const
265+ sqlite3_stmt* getStatement () const noexcept
266266 {
267- return mpStatement;
267+ return mpStatement-> getStatement () ;
268268 }
269269
270270 // //////////////////////////////////////////////////////////////////////////
271271
272272 /* *
273273 * @brief Check if a return code equals SQLITE_OK, else throw a SQLite::Exception with the SQLite error message
274274 *
275- * @param[in] aRet SQLite return code to test against the SQLITE_OK expected value
275+ * @param[in] aRet SQLite return code to test against the SQLITE_OK expected value.
276+ *
277+ * @throws SQLite::Exception when aRet isn't SQLITE_OK.
276278 */
277279 void check (const int aRet) const
278280 {
@@ -284,6 +286,8 @@ class StatementExecutor
284286
285287 /* *
286288 * @brief Check if there is a row of result returned by executeStep(), else throw a SQLite::Exception.
289+ *
290+ * @throws SQLite::Exception when mbHasRow is false.
287291 */
288292 void checkRow () const
289293 {
@@ -295,6 +299,8 @@ class StatementExecutor
295299
296300 /* *
297301 * @brief Check if there is a Column index is in the range of columns in the result.
302+ *
303+ * @throws SQLite::Exception when aIndex is out of bounds.
298304 */
299305 void checkIndex (const int aIndex) const
300306 {
@@ -305,17 +311,12 @@ class StatementExecutor
305311 }
306312
307313private:
308- // / Get column number and create map with columns names
314+ // / Get column number and create map with columns names.
309315 void createColumnInfo ();
310316
311- // xD
312- bool checkReturnCode (int aReturnCode) const ;
313- // xD
314- bool checkReturnCode (int aReturnCode, int aErrorCode) const ;
315-
316317 // / Shared Pointer to this object.
317- // / Allows RowIterator to execute next step
318- TRowPtr mpStatement{};
318+ // / Allows RowIterator to execute next step.
319+ TStatementPtr mpStatement{};
319320
320321 int mColumnCount = 0 ; // !< Number of columns in the result of the prepared statement
321322 bool mbHasRow = false ; // !< true when a row has been fetched with executeStep()
0 commit comments