Skip to content

Commit 4f7899c

Browse files
committed
Rename Statement::mbIsOk to mbHasRow
1 parent 473a307 commit 4f7899c

File tree

4 files changed

+47
-42
lines changed

4 files changed

+47
-42
lines changed

include/SQLiteCpp/Statement.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,14 @@ class Statement
549549
return mColumnCount;
550550
}
551551
/// true when a row has been fetched with executeStep()
552+
inline bool hasRow() const
553+
{
554+
return mbHasRow;
555+
}
556+
/// @deprecated, use #hasRow()
552557
inline bool isOk() const
553558
{
554-
return mbOk;
559+
return hasRow();
555560
}
556561
/// true when the last executeStep() had no more row to fetch
557562
inline bool isDone() const
@@ -632,7 +637,7 @@ class Statement
632637
*/
633638
inline void checkRow() const
634639
{
635-
if (false == mbOk)
640+
if (false == mbHasRow)
636641
{
637642
throw SQLite::Exception("No row to get a column from. executeStep() was not called, or returned false.");
638643
}
@@ -658,7 +663,7 @@ class Statement
658663
Ptr mStmtPtr; //!< Shared Pointer to the prepared SQLite Statement Object
659664
int mColumnCount; //!< Number of columns in the result of the prepared statement
660665
mutable TColumnNames mColumnNames; //!< Map of columns index by name (mutable so getColumnIndex can be const)
661-
bool mbOk; //!< true when a row has been fetched with executeStep()
666+
bool mbHasRow; //!< true when a row has been fetched with executeStep()
662667
bool mbDone; //!< true when the last executeStep() had no more row to fetch
663668
};
664669

src/Statement.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Statement::Statement(Database &aDatabase, const char* apQuery) :
2525
mQuery(apQuery),
2626
mStmtPtr(aDatabase.mpSQLite, mQuery), // prepare the SQL query, and ref count (needs Database friendship)
2727
mColumnCount(0),
28-
mbOk(false),
28+
mbHasRow(false),
2929
mbDone(false)
3030
{
3131
mColumnCount = sqlite3_column_count(mStmtPtr);
@@ -36,7 +36,7 @@ Statement::Statement(Database &aDatabase, const std::string& aQuery) :
3636
mQuery(aQuery),
3737
mStmtPtr(aDatabase.mpSQLite, mQuery), // prepare the SQL query, and ref count (needs Database friendship)
3838
mColumnCount(0),
39-
mbOk(false),
39+
mbHasRow(false),
4040
mbDone(false)
4141
{
4242
mColumnCount = sqlite3_column_count(mStmtPtr);
@@ -58,7 +58,7 @@ void Statement::reset()
5858

5959
int Statement::tryReset() noexcept
6060
{
61-
mbOk = false;
61+
mbHasRow = false;
6262
mbDone = false;
6363
return sqlite3_reset(mStmtPtr);
6464
}
@@ -250,7 +250,7 @@ bool Statement::executeStep()
250250
throw SQLite::Exception(mStmtPtr, ret);
251251
}
252252

253-
return mbOk; // true only if one row is accessible by getColumn(N)
253+
return mbHasRow; // true only if one row is accessible by getColumn(N)
254254
}
255255

256256
// Execute a one-step query with no expected result
@@ -280,16 +280,16 @@ int Statement::tryExecuteStep() noexcept
280280
const int ret = sqlite3_step(mStmtPtr);
281281
if (SQLITE_ROW == ret) // one row is ready : call getColumn(N) to access it
282282
{
283-
mbOk = true;
283+
mbHasRow = true;
284284
}
285285
else if (SQLITE_DONE == ret) // no (more) row ready : the query has finished executing
286286
{
287-
mbOk = false;
287+
mbHasRow = false;
288288
mbDone = true;
289289
}
290290
else
291291
{
292-
mbOk = false;
292+
mbHasRow = false;
293293
mbDone = false;
294294
}
295295

tests/Column_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TEST(Column, basis) {
5252
EXPECT_STREQ("SELECT * FROM test", query.getQuery().c_str());
5353
EXPECT_EQ(6, query.getColumnCount ());
5454
query.executeStep();
55-
EXPECT_TRUE (query.isOk());
55+
EXPECT_TRUE (query.hasRow());
5656
EXPECT_FALSE(query.isDone());
5757

5858
// validates every variant of cast operators, and conversions of types

tests/Statement_test.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ TEST(Statement, invalid) {
3939
SQLite::Statement query(db, "SELECT * FROM test");
4040
EXPECT_STREQ("SELECT * FROM test", query.getQuery().c_str());
4141
EXPECT_EQ(2, query.getColumnCount ());
42-
EXPECT_FALSE(query.isOk());
42+
EXPECT_FALSE(query.hasRow());
4343
EXPECT_FALSE(query.isDone());
4444
EXPECT_EQ(SQLite::OK, query.getErrorCode());
4545
EXPECT_EQ(SQLite::OK, query.getExtendedErrorCode());
@@ -53,14 +53,14 @@ TEST(Statement, invalid) {
5353
EXPECT_THROW(query.getColumn(2), SQLite::Exception);
5454

5555
query.reset();
56-
EXPECT_FALSE(query.isOk());
56+
EXPECT_FALSE(query.hasRow());
5757
EXPECT_FALSE(query.isDone());
5858

5959
query.executeStep();
60-
EXPECT_FALSE(query.isOk());
60+
EXPECT_FALSE(query.hasRow());
6161
EXPECT_TRUE( query.isDone());
6262
query.reset();
63-
EXPECT_FALSE(query.isOk());
63+
EXPECT_FALSE(query.hasRow());
6464
EXPECT_FALSE(query.isDone());
6565

6666
query.reset();
@@ -89,7 +89,7 @@ TEST(Statement, invalid) {
8989
EXPECT_EQ(1, db.getTotalChanges());
9090

9191
query.reset();
92-
EXPECT_FALSE(query.isOk());
92+
EXPECT_FALSE(query.hasRow());
9393
EXPECT_FALSE(query.isDone());
9494

9595
EXPECT_THROW(query.exec(), SQLite::Exception); // exec() shall throw as it does not expect a result
@@ -115,7 +115,7 @@ TEST(Statement, executeStep) {
115115

116116
// Get the first row
117117
query.executeStep();
118-
EXPECT_TRUE (query.isOk());
118+
EXPECT_TRUE (query.hasRow());
119119
EXPECT_FALSE(query.isDone());
120120
const int64_t id = query.getColumn(0);
121121
const std::string msg = query.getColumn(1);
@@ -130,7 +130,7 @@ TEST(Statement, executeStep) {
130130

131131
// Step one more time to discover there is nothing more
132132
query.executeStep();
133-
EXPECT_FALSE(query.isOk());
133+
EXPECT_FALSE(query.hasRow());
134134
EXPECT_TRUE (query.isDone()); // "done" is "the end"
135135

136136
// Step after "the end" throw an exception
@@ -167,7 +167,7 @@ TEST(Statement, tryExecuteStep) {
167167

168168
// Get the first row
169169
EXPECT_EQ(query.tryExecuteStep(), SQLITE_ROW);
170-
EXPECT_TRUE (query.isOk());
170+
EXPECT_TRUE (query.hasRow());
171171
EXPECT_FALSE(query.isDone());
172172
const int64_t id = query.getColumn(0);
173173
const std::string msg = query.getColumn(1);
@@ -182,7 +182,7 @@ TEST(Statement, tryExecuteStep) {
182182

183183
// Step one more time to discover there is nothing more
184184
EXPECT_EQ(query.tryExecuteStep(), SQLITE_DONE);
185-
EXPECT_FALSE(query.isOk());
185+
EXPECT_FALSE(query.hasRow());
186186
EXPECT_TRUE (query.isDone()); // "done" is "the end"
187187

188188
// Try to insert a new row with the same PRIMARY KEY: "UNIQUE constraint failed: test.id"
@@ -222,7 +222,7 @@ TEST(Statement, bindings) {
222222

223223
// Check the result
224224
query.executeStep();
225-
EXPECT_TRUE (query.isOk());
225+
EXPECT_TRUE (query.hasRow());
226226
EXPECT_FALSE(query.isDone());
227227
EXPECT_EQ (1, query.getColumn(0).getInt64());
228228
EXPECT_STREQ("first", query.getColumn(1).getText());
@@ -240,7 +240,7 @@ TEST(Statement, bindings) {
240240

241241
// Check the result
242242
query.executeStep();
243-
EXPECT_TRUE (query.isOk());
243+
EXPECT_TRUE (query.hasRow());
244244
EXPECT_FALSE(query.isDone());
245245
EXPECT_EQ (2, query.getColumn(0).getInt64());
246246
EXPECT_STREQ("first", query.getColumn(1).getText());
@@ -259,7 +259,7 @@ TEST(Statement, bindings) {
259259

260260
// Check the resultw
261261
query.executeStep();
262-
EXPECT_TRUE (query.isOk());
262+
EXPECT_TRUE (query.hasRow());
263263
EXPECT_FALSE(query.isDone());
264264
EXPECT_EQ (3, query.getColumn(0).getInt64());
265265
EXPECT_TRUE (query.isColumnNull(1));
@@ -287,7 +287,7 @@ TEST(Statement, bindings) {
287287

288288
// Check the result
289289
query.executeStep();
290-
EXPECT_TRUE (query.isOk());
290+
EXPECT_TRUE (query.hasRow());
291291
EXPECT_FALSE(query.isDone());
292292
EXPECT_EQ(4, query.getColumn(0).getInt64());
293293
EXPECT_EQ(fourth, query.getColumn(1).getText());
@@ -307,7 +307,7 @@ TEST(Statement, bindings) {
307307

308308
// Check the result
309309
query.executeStep();
310-
EXPECT_TRUE (query.isOk());
310+
EXPECT_TRUE (query.hasRow());
311311
EXPECT_FALSE(query.isDone());
312312
EXPECT_EQ(5, query.getColumn(0).getInt64());
313313
EXPECT_STREQ(buffer, query.getColumn(1).getText());
@@ -329,7 +329,7 @@ TEST(Statement, bindings) {
329329

330330
// Check the result
331331
query.executeStep();
332-
EXPECT_TRUE(query.isOk());
332+
EXPECT_TRUE(query.hasRow());
333333
EXPECT_FALSE(query.isDone());
334334
EXPECT_EQ(6, query.getColumn(0).getInt64());
335335
EXPECT_EQ(4294967295U, query.getColumn(2).getUInt());
@@ -366,7 +366,7 @@ TEST(Statement, bindNoCopy) {
366366

367367
// Check the result
368368
query.executeStep();
369-
EXPECT_TRUE(query.isOk());
369+
EXPECT_TRUE(query.hasRow());
370370
EXPECT_FALSE(query.isDone());
371371
EXPECT_EQ(1, query.getColumn(0).getInt64());
372372
EXPECT_STREQ(txt1, query.getColumn(1).getText());
@@ -401,7 +401,7 @@ TEST(Statement, bindByName) {
401401

402402
// Check the result
403403
query.executeStep();
404-
EXPECT_TRUE (query.isOk());
404+
EXPECT_TRUE (query.hasRow());
405405
EXPECT_FALSE(query.isDone());
406406
EXPECT_EQ (1, query.getColumn(0).getInt64());
407407
EXPECT_STREQ("first", query.getColumn(1).getText());
@@ -425,7 +425,7 @@ TEST(Statement, bindByName) {
425425

426426
// Check the result
427427
query.executeStep();
428-
EXPECT_TRUE (query.isOk());
428+
EXPECT_TRUE (query.hasRow());
429429
EXPECT_FALSE(query.isDone());
430430
EXPECT_EQ(2, query.getColumn(0).getInt64());
431431
EXPECT_EQ(second, query.getColumn(1).getText());
@@ -445,7 +445,7 @@ TEST(Statement, bindByName) {
445445

446446
// Check the result
447447
query.executeStep();
448-
EXPECT_TRUE (query.isOk());
448+
EXPECT_TRUE (query.hasRow());
449449
EXPECT_FALSE(query.isDone());
450450
EXPECT_EQ(3, query.getColumn(0).getInt64());
451451
EXPECT_STREQ(buffer, query.getColumn(1).getText());
@@ -466,7 +466,7 @@ TEST(Statement, bindByName) {
466466

467467
// Check the result
468468
query.executeStep();
469-
EXPECT_TRUE(query.isOk());
469+
EXPECT_TRUE(query.hasRow());
470470
EXPECT_FALSE(query.isDone());
471471
EXPECT_EQ(4, query.getColumn(0).getInt64());
472472
EXPECT_EQ(4294967295U, query.getColumn(2).getUInt());
@@ -503,7 +503,7 @@ TEST(Statement, bindNoCopyByName) {
503503

504504
// Check the result
505505
query.executeStep();
506-
EXPECT_TRUE(query.isOk());
506+
EXPECT_TRUE(query.hasRow());
507507
EXPECT_FALSE(query.isDone());
508508
EXPECT_EQ(1, query.getColumn(0).getInt64());
509509
EXPECT_STREQ(txt1, query.getColumn(1).getText());
@@ -535,7 +535,7 @@ TEST(Statement, isColumnNull) {
535535

536536
// Get the first non-null row
537537
query.executeStep();
538-
EXPECT_TRUE (query.isOk());
538+
EXPECT_TRUE (query.hasRow());
539539
EXPECT_FALSE(query.isDone());
540540
EXPECT_THROW(query.isColumnNull(-1), SQLite::Exception);
541541
EXPECT_EQ(false, query.isColumnNull(0));
@@ -545,7 +545,7 @@ TEST(Statement, isColumnNull) {
545545

546546
// Get the second row with null text
547547
query.executeStep();
548-
EXPECT_TRUE (query.isOk());
548+
EXPECT_TRUE (query.hasRow());
549549
EXPECT_FALSE(query.isDone());
550550
EXPECT_THROW(query.isColumnNull(-1), SQLite::Exception);
551551
EXPECT_EQ(true, query.isColumnNull(0));
@@ -555,7 +555,7 @@ TEST(Statement, isColumnNull) {
555555

556556
// Get the second row with null integer
557557
query.executeStep();
558-
EXPECT_TRUE (query.isOk());
558+
EXPECT_TRUE (query.hasRow());
559559
EXPECT_FALSE(query.isDone());
560560
EXPECT_THROW(query.isColumnNull(-1), SQLite::Exception);
561561
EXPECT_EQ(false, query.isColumnNull(0));
@@ -565,7 +565,7 @@ TEST(Statement, isColumnNull) {
565565

566566
// Get the third row with null float
567567
query.executeStep();
568-
EXPECT_TRUE (query.isOk());
568+
EXPECT_TRUE (query.hasRow());
569569
EXPECT_FALSE(query.isDone());
570570
EXPECT_THROW(query.isColumnNull(-1), SQLite::Exception);
571571
EXPECT_EQ(false, query.isColumnNull(0));
@@ -597,7 +597,7 @@ TEST(Statement, isColumnNullByName) {
597597

598598
// Get the first non-null row
599599
query.executeStep();
600-
EXPECT_TRUE (query.isOk());
600+
EXPECT_TRUE (query.hasRow());
601601
EXPECT_FALSE(query.isDone());
602602
EXPECT_THROW(query.isColumnNull(""), SQLite::Exception);
603603
EXPECT_EQ(false, query.isColumnNull("msg"));
@@ -607,7 +607,7 @@ TEST(Statement, isColumnNullByName) {
607607

608608
// Get the second row with null text
609609
query.executeStep();
610-
EXPECT_TRUE (query.isOk());
610+
EXPECT_TRUE (query.hasRow());
611611
EXPECT_FALSE(query.isDone());
612612
EXPECT_THROW(query.isColumnNull(""), SQLite::Exception);
613613
EXPECT_EQ(true, query.isColumnNull("msg"));
@@ -617,7 +617,7 @@ TEST(Statement, isColumnNullByName) {
617617

618618
// Get the second row with null integer
619619
query.executeStep();
620-
EXPECT_TRUE (query.isOk());
620+
EXPECT_TRUE (query.hasRow());
621621
EXPECT_FALSE(query.isDone());
622622
EXPECT_THROW(query.isColumnNull(""), SQLite::Exception);
623623
EXPECT_EQ(false, query.isColumnNull("msg"));
@@ -627,7 +627,7 @@ TEST(Statement, isColumnNullByName) {
627627

628628
// Get the third row with null float
629629
query.executeStep();
630-
EXPECT_TRUE (query.isOk());
630+
EXPECT_TRUE (query.hasRow());
631631
EXPECT_FALSE(query.isDone());
632632
EXPECT_THROW(query.isColumnNull(""), SQLite::Exception);
633633
EXPECT_EQ(false, query.isColumnNull("msg"));
@@ -657,7 +657,7 @@ TEST(Statement, getColumnByName) {
657657
EXPECT_STREQ("SELECT * FROM test", query.getQuery().c_str());
658658
EXPECT_EQ(4, query.getColumnCount());
659659
query.executeStep();
660-
EXPECT_TRUE (query.isOk());
660+
EXPECT_TRUE (query.hasRow());
661661
EXPECT_FALSE(query.isDone());
662662

663663
// Look for non-existing columns
@@ -734,7 +734,7 @@ TEST(Statement, getColumns) {
734734
EXPECT_STREQ("SELECT * FROM test", query.getQuery().c_str());
735735
EXPECT_EQ(4, query.getColumnCount());
736736
query.executeStep();
737-
EXPECT_TRUE(query.isOk());
737+
EXPECT_TRUE(query.hasRow());
738738
EXPECT_FALSE(query.isDone());
739739

740740
// Get all columns

0 commit comments

Comments
 (0)