Add test case to try to repro the reported ambiguous bind() int64_t on LP64 Android

This commit is contained in:
Sébastien Rombauts 2019-03-02 18:20:10 +01:00
parent efa3da6534
commit df7d113a3b
3 changed files with 33 additions and 11 deletions

View File

@ -176,7 +176,7 @@ public:
{ {
return getUInt(); return getUInt();
} }
#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits) #if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
/// Inline cast operator to 32bits long /// Inline cast operator to 32bits long
inline operator long() const inline operator long() const
{ {
@ -187,8 +187,8 @@ public:
{ {
return getUInt(); return getUInt();
} }
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux) #else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
/// Inline cast operator to 64bits long when the data model of the system is ILP64 (Linux 64 bits...) /// Inline cast operator to 64bits long when the data model of the system is LP64 (Linux 64 bits...)
inline operator long() const inline operator long() const
{ {
return getInt64(); return getInt64();

View File

@ -116,7 +116,7 @@ public:
*/ */
void bind(const int aIndex, const unsigned aValue); void bind(const int aIndex, 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) #if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
/** /**
* @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
@ -124,7 +124,7 @@ public:
{ {
bind(aIndex, static_cast<int>(aValue)); bind(aIndex, static_cast<int>(aValue));
} }
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux) #else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
/** /**
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
@ -198,7 +198,7 @@ public:
*/ */
void bind(const char* apName, const unsigned aValue); 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) #if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
/** /**
* @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
@ -206,7 +206,7 @@ public:
{ {
bind(apName, static_cast<int>(aValue)); bind(apName, static_cast<int>(aValue));
} }
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux) #else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
/** /**
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
@ -286,7 +286,7 @@ public:
bind(aName.c_str(), aValue); 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) #if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
/** /**
* @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
@ -294,7 +294,7 @@ public:
{ {
bind(aName.c_str(), static_cast<int>(aValue)); bind(aName.c_str(), static_cast<int>(aValue));
} }
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux) #else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
/** /**
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */

View File

@ -338,6 +338,25 @@ TEST(Statement, bindings) {
EXPECT_EQ(4294967295U, query.getColumn(2).getUInt()); EXPECT_EQ(4294967295U, query.getColumn(2).getUInt());
EXPECT_EQ(-123, query.getColumn(3).getInt()); EXPECT_EQ(-123, query.getColumn(3).getInt());
} }
// reset() without clearbindings()
insert.reset();
// Seventh row using another variant of int64 type
{
const int64_t int64 = 12345678900000LL;
insert.bind(2, int64);
EXPECT_EQ(1, insert.exec());
EXPECT_EQ(SQLITE_DONE, db.getErrorCode());
// Check the result
query.executeStep();
EXPECT_TRUE(query.hasRow());
EXPECT_FALSE(query.isDone());
EXPECT_EQ(7, query.getColumn(0).getInt64());
EXPECT_EQ(12345678900000LL, query.getColumn(2).getInt64());
}
} }
TEST(Statement, bindNoCopy) { TEST(Statement, bindNoCopy) {
@ -466,10 +485,12 @@ TEST(Statement, bindByName) {
// reset() without clearbindings() // reset() without clearbindings()
insert.reset(); insert.reset();
// Fourth row with uint32_t unsigned value // Fourth row with uint32_t unsigned value and int64_t 64bits value
{ {
const uint32_t uint32 = 4294967295U; const uint32_t uint32 = 4294967295U;
const int64_t int64 = 12345678900000LL;
insert.bind("@int", uint32); insert.bind("@int", uint32);
insert.bind("@long", int64);
EXPECT_EQ(1, insert.exec()); EXPECT_EQ(1, insert.exec());
EXPECT_EQ(SQLITE_DONE, db.getErrorCode()); EXPECT_EQ(SQLITE_DONE, db.getErrorCode());
@ -479,6 +500,7 @@ TEST(Statement, bindByName) {
EXPECT_FALSE(query.isDone()); EXPECT_FALSE(query.isDone());
EXPECT_EQ(4, query.getColumn(0).getInt64()); EXPECT_EQ(4, query.getColumn(0).getInt64());
EXPECT_EQ(4294967295U, query.getColumn(2).getUInt()); EXPECT_EQ(4294967295U, query.getColumn(2).getUInt());
EXPECT_EQ(12345678900000LL, query.getColumn(4).getInt64());
} }
} }
@ -762,7 +784,7 @@ TEST(Statement, getColumns) {
} }
#endif #endif
#if (LONG_MAX > INT_MAX) // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux) #if (LONG_MAX > INT_MAX) // sizeof(long)==8 means the data model of the system is LP64 (64bits Linux)
TEST(Statement, bind64bitsLong) { TEST(Statement, bind64bitsLong) {
// Create a new database // Create a new database
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);