Skip to content

Commit bacdf84

Browse files
committed
Handle null results in execScalar()
It now takes an `nNullSentinel` parameter similar to `getIntField()` and returns it when the result of the scalar query is null. Closes #16.
1 parent b001fed commit bacdf84

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/CppSQLite3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ CppSQLite3Query CppSQLite3DB::execQuery(const char* szSQL)
13501350
}
13511351

13521352

1353-
int CppSQLite3DB::execScalar(const char* szSQL)
1353+
int CppSQLite3DB::execScalar(const char* szSQL, int nNullSentinel)
13541354
{
13551355
CppSQLite3Query q = execQuery(szSQL);
13561356

@@ -1361,7 +1361,7 @@ int CppSQLite3DB::execScalar(const char* szSQL)
13611361
DONT_DELETE_MSG);
13621362
}
13631363

1364-
return atoi(q.fieldValue(0));
1364+
return q.getIntField(0, nNullSentinel);
13651365
}
13661366

13671367

src/CppSQLite3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class CppSQLite3DB
309309

310310
CppSQLite3Query execQuery(const char* szSQL);
311311

312-
int execScalar(const char* szSQL);
312+
int execScalar(const char* szSQL, int nNullSentinel = 0);
313313

314314
CppSQLite3Table getTable(const char* szSQL);
315315

0 commit comments

Comments
 (0)