Skip to content

Commit a3160dc

Browse files
committed
Add Statement binding for long int values to Fix SRombauts#147
1 parent eb065bf commit a3160dc

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

include/SQLiteCpp/Statement.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ class Statement
114114
* @brief Bind a 32bits unsigned int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
115115
*/
116116
void bind(const int aIndex, const unsigned aValue);
117+
118+
#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits)
119+
/**
120+
* @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
121+
*/
122+
void bind(const int aIndex, const long aValue)
123+
{
124+
bind(aIndex, static_cast<int>(aValue));
125+
}
126+
#else
127+
/**
128+
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
129+
*/
130+
void bind(const int aIndex, const long aValue)
131+
{
132+
bind(aIndex, static_cast<long long>(aValue));
133+
}
134+
#endif
135+
117136
/**
118137
* @brief Bind a 64bits int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
119138
*/

tests/Statement_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ TEST(Statement, bindings) {
320320
// reset() without clearbindings()
321321
insert.reset();
322322

323-
// Sixth row with uint32_t unsigned value
323+
// Sixth row with uint32_t unsigned value and a long value (which is either a 32b int or a 64b long long)
324324
{
325325
const uint32_t uint32 = 4294967295U;
326+
const long integer = -123;
326327
insert.bind(2, uint32);
328+
insert.bind(3, integer);
327329
EXPECT_EQ(1, insert.exec());
328330
EXPECT_EQ(SQLITE_DONE, db.getErrorCode());
329331

@@ -333,6 +335,7 @@ TEST(Statement, bindings) {
333335
EXPECT_FALSE(query.isDone());
334336
EXPECT_EQ(6, query.getColumn(0).getInt64());
335337
EXPECT_EQ(4294967295U, query.getColumn(2).getUInt());
338+
EXPECT_EQ(-123, query.getColumn(3).getInt());
336339
}
337340
}
338341

0 commit comments

Comments
 (0)