Skip to content

Commit f1301a4

Browse files
authored
Merge pull request SRombauts#192 from jrave/bind_parameter_count
Add wrapper for bind parameter count
2 parents 78915c8 + 1dab172 commit f1301a4

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

include/SQLiteCpp/Statement.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ class Statement
629629
return mbDone;
630630
}
631631

632+
/// Return the number of bind parameters in the statement
633+
int getBindParameterCount() const noexcept;
634+
632635
/// Return the numeric result code for the most recent failed API call (if any).
633636
int getErrorCode() const noexcept; // nothrow
634637
/// Return the extended numeric result code for the most recent failed API call (if any).

src/Statement.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ int Statement::getColumnIndex(const char* apName) const
391391
return (*iIndex).second;
392392
}
393393

394+
int Statement::getBindParameterCount() const noexcept
395+
{
396+
return sqlite3_bind_parameter_count(mStmtPtr);
397+
}
398+
394399
// Return the numeric result code for the most recent failed API call (if any).
395400
int Statement::getErrorCode() const noexcept // nothrow
396401
{

tests/Statement_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,3 +831,18 @@ TEST(Statement, bind64bitsLong) {
831831
EXPECT_EQ(4294967297L, query.getColumn(0).getInt64());
832832
}
833833
#endif
834+
835+
TEST(Statement, getBindParameterCount) {
836+
// Create a new database
837+
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
838+
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT)"));
839+
840+
SQLite::Statement query(db, "SELECT id, msg FROM test where id = ?");
841+
EXPECT_EQ(1, query.getBindParameterCount());
842+
843+
SQLite::Statement query2(db, "SELECT id, msg FROM test where id = ? and msg = ?");
844+
EXPECT_EQ(2, query2.getBindParameterCount());
845+
846+
SQLite::Statement query3(db, "SELECT id, msg FROM test");
847+
EXPECT_EQ(0, query3.getBindParameterCount());
848+
}

0 commit comments

Comments
 (0)