Skip to content

Commit df7d113

Browse files
committed
Add test case to try to repro the reported ambiguous bind() int64_t on LP64 Android
1 parent efa3da6 commit df7d113

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

include/SQLiteCpp/Column.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class Column
176176
{
177177
return getUInt();
178178
}
179-
#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits)
179+
#if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
180180
/// Inline cast operator to 32bits long
181181
inline operator long() const
182182
{
@@ -187,8 +187,8 @@ class Column
187187
{
188188
return getUInt();
189189
}
190-
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux)
191-
/// Inline cast operator to 64bits long when the data model of the system is ILP64 (Linux 64 bits...)
190+
#else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
191+
/// Inline cast operator to 64bits long when the data model of the system is LP64 (Linux 64 bits...)
192192
inline operator long() const
193193
{
194194
return getInt64();

include/SQLiteCpp/Statement.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ class Statement
116116
*/
117117
void bind(const int aIndex, const unsigned aValue);
118118

119-
#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits)
119+
#if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
120120
/**
121121
* @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
122122
*/
123123
void bind(const int aIndex, const long aValue)
124124
{
125125
bind(aIndex, static_cast<int>(aValue));
126126
}
127-
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux)
127+
#else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
128128
/**
129129
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
130130
*/
@@ -198,15 +198,15 @@ class Statement
198198
*/
199199
void bind(const char* apName, const unsigned aValue);
200200

201-
#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits)
201+
#if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
202202
/**
203203
* @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
204204
*/
205205
void bind(const char* apName, const long aValue)
206206
{
207207
bind(apName, static_cast<int>(aValue));
208208
}
209-
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux)
209+
#else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
210210
/**
211211
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
212212
*/
@@ -286,15 +286,15 @@ class Statement
286286
bind(aName.c_str(), aValue);
287287
}
288288

289-
#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits)
289+
#if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
290290
/**
291291
* @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
292292
*/
293293
void bind(const std::string& aName, const long aValue)
294294
{
295295
bind(aName.c_str(), static_cast<int>(aValue));
296296
}
297-
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux)
297+
#else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
298298
/**
299299
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
300300
*/

tests/Statement_test.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,25 @@ TEST(Statement, bindings) {
338338
EXPECT_EQ(4294967295U, query.getColumn(2).getUInt());
339339
EXPECT_EQ(-123, query.getColumn(3).getInt());
340340
}
341+
342+
343+
// reset() without clearbindings()
344+
insert.reset();
345+
346+
// Seventh row using another variant of int64 type
347+
{
348+
const int64_t int64 = 12345678900000LL;
349+
insert.bind(2, int64);
350+
EXPECT_EQ(1, insert.exec());
351+
EXPECT_EQ(SQLITE_DONE, db.getErrorCode());
352+
353+
// Check the result
354+
query.executeStep();
355+
EXPECT_TRUE(query.hasRow());
356+
EXPECT_FALSE(query.isDone());
357+
EXPECT_EQ(7, query.getColumn(0).getInt64());
358+
EXPECT_EQ(12345678900000LL, query.getColumn(2).getInt64());
359+
}
341360
}
342361

343362
TEST(Statement, bindNoCopy) {
@@ -466,10 +485,12 @@ TEST(Statement, bindByName) {
466485
// reset() without clearbindings()
467486
insert.reset();
468487

469-
// Fourth row with uint32_t unsigned value
488+
// Fourth row with uint32_t unsigned value and int64_t 64bits value
470489
{
471490
const uint32_t uint32 = 4294967295U;
491+
const int64_t int64 = 12345678900000LL;
472492
insert.bind("@int", uint32);
493+
insert.bind("@long", int64);
473494
EXPECT_EQ(1, insert.exec());
474495
EXPECT_EQ(SQLITE_DONE, db.getErrorCode());
475496

@@ -479,6 +500,7 @@ TEST(Statement, bindByName) {
479500
EXPECT_FALSE(query.isDone());
480501
EXPECT_EQ(4, query.getColumn(0).getInt64());
481502
EXPECT_EQ(4294967295U, query.getColumn(2).getUInt());
503+
EXPECT_EQ(12345678900000LL, query.getColumn(4).getInt64());
482504
}
483505
}
484506

@@ -762,7 +784,7 @@ TEST(Statement, getColumns) {
762784
}
763785
#endif
764786

765-
#if (LONG_MAX > INT_MAX) // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux)
787+
#if (LONG_MAX > INT_MAX) // sizeof(long)==8 means the data model of the system is LP64 (64bits Linux)
766788
TEST(Statement, bind64bitsLong) {
767789
// Create a new database
768790
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);

0 commit comments

Comments
 (0)