Add the fix from a3160dcfc2f80f692f3477a67c202ff87f75fa5a also to the bind by name functions

This commit is contained in:
Alexander Guettler 2017-11-09 11:05:01 -08:00
parent 7c4689eb51
commit cebea884c3
No known key found for this signature in database
GPG Key ID: F3485BF85CE6593C
2 changed files with 44 additions and 3 deletions

View File

@ -196,6 +196,24 @@ public:
* @brief Bind a 32bits unsigned int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/
void bind(const char* apName, const unsigned aValue);
#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits)
/**
* @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/
void bind(const char* apName, const long aValue)
{
bind(apName, static_cast<int>(aValue));
}
#else
/**
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/
void bind(const char* apName, const long aValue)
{
bind(apName, static_cast<long long>(aValue));
}
#endif
/**
* @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/
@ -266,6 +284,24 @@ public:
{
bind(aName.c_str(), aValue);
}
#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits)
/**
* @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/
void bind(const std::string& aName, const long aValue)
{
bind(aName.c_str(), static_cast<int>(aValue));
}
#else
/**
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/
void bind(const std::string& aName, const long aValue)
{
bind(aName.c_str(), static_cast<long long>(aValue));
}
#endif
/**
* @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/

View File

@ -384,15 +384,16 @@ TEST(Statement, bindByName) {
EXPECT_EQ(SQLite::OK, db.getErrorCode());
// Create a new table
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT, int INTEGER, double REAL)"));
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT, int INTEGER, double REAL, long INTEGER)"));
EXPECT_EQ(SQLite::OK, db.getErrorCode());
// Insertion with bindable parameters
SQLite::Statement insert(db, "INSERT INTO test VALUES (NULL, @msg, @int, @double)");
SQLite::Statement insert(db, "INSERT INTO test VALUES (NULL, @msg, @int, @double, @long)");
// First row with text/int/double
insert.bind("@msg", "first");
insert.bind("@int", 123);
insert.bind("@long", -123);
insert.bind("@double", 0.123);
EXPECT_EQ(1, insert.exec());
EXPECT_EQ(SQLITE_DONE, db.getErrorCode());
@ -400,7 +401,7 @@ TEST(Statement, bindByName) {
// Compile a SQL query to check the result
SQLite::Statement query(db, "SELECT * FROM test");
EXPECT_STREQ("SELECT * FROM test", query.getQuery().c_str());
EXPECT_EQ(4, query.getColumnCount());
EXPECT_EQ(5, query.getColumnCount());
// Check the result
query.executeStep();
@ -410,6 +411,7 @@ TEST(Statement, bindByName) {
EXPECT_STREQ("first", query.getColumn(1).getText());
EXPECT_EQ (123, query.getColumn(2).getInt());
EXPECT_EQ (0.123, query.getColumn(3).getDouble());
EXPECT_EQ (-123, query.getColumn(4).getInt());
// reset() with clearbindings() and new bindings
insert.reset();
@ -419,10 +421,12 @@ TEST(Statement, bindByName) {
{
const std::string second("second");
const long long int64 = 12345678900000LL;
const long integer = -123;
const float float32 = 0.234f;
insert.bind("@msg", second);
insert.bind("@int", int64);
insert.bind("@double", float32);
insert.bind("@long", integer);
EXPECT_EQ(1, insert.exec());
EXPECT_EQ(SQLITE_DONE, db.getErrorCode());
@ -434,6 +438,7 @@ TEST(Statement, bindByName) {
EXPECT_EQ(second, query.getColumn(1).getText());
EXPECT_EQ(12345678900000LL, query.getColumn(2).getInt64());
EXPECT_EQ(0.234f, query.getColumn(3).getDouble());
EXPECT_EQ(-123, query.getColumn(4).getInt());
}
// reset() without clearbindings()