Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper for bind parameter count #192

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/SQLiteCpp/Statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,9 @@ class Statement
return mbDone;
}

/// Return the number of bind parameters in the statement
int getBindParameterCount() const noexcept;

/// Return the numeric result code for the most recent failed API call (if any).
int getErrorCode() const noexcept; // nothrow
/// Return the extended numeric result code for the most recent failed API call (if any).
Expand Down
5 changes: 5 additions & 0 deletions src/Statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ int Statement::getColumnIndex(const char* apName) const
return (*iIndex).second;
}

int Statement::getBindParameterCount() const noexcept
{
return sqlite3_bind_parameter_count(mStmtPtr);
}

// Return the numeric result code for the most recent failed API call (if any).
int Statement::getErrorCode() const noexcept // nothrow
{
Expand Down
15 changes: 15 additions & 0 deletions tests/Statement_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,3 +797,18 @@ TEST(Statement, bind64bitsLong) {
EXPECT_EQ(4294967297L, query.getColumn(0).getInt64());
}
#endif

TEST(Statement, getBindParameterCount) {
// Create a new database
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT)"));

SQLite::Statement query(db, "SELECT id, msg FROM test where id = ?");
EXPECT_EQ(1, query.getBindParameterCount());

SQLite::Statement query2(db, "SELECT id, msg FROM test where id = ? and msg = ?");
EXPECT_EQ(2, query2.getBindParameterCount());

SQLite::Statement query3(db, "SELECT id, msg FROM test");
EXPECT_EQ(0, query3.getBindParameterCount());
}