mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
Fix #155 Statement::bind truncates long integer to 32 bits on x86_64 Linux
Reproduced the problem with a dedicated unit test, then fixed the bug. Thanks @tszypenbejl for the clear analysis and the fix.
This commit is contained in:
parent
d15a84e46e
commit
a41629f9ed
@ -14,7 +14,7 @@
|
||||
#include <SQLiteCpp/Exception.h>
|
||||
|
||||
#include <string>
|
||||
#include <limits.h>
|
||||
#include <climits> // For INT_MAX
|
||||
|
||||
|
||||
namespace SQLite
|
||||
@ -187,7 +187,7 @@ public:
|
||||
{
|
||||
return getUInt();
|
||||
}
|
||||
#else
|
||||
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux)
|
||||
/// Inline cast operator to 64bits long when the data model of the system is ILP64 (Linux 64 bits...)
|
||||
inline operator long() const
|
||||
{
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <climits> // For INT_MAX
|
||||
|
||||
// Forward declarations to avoid inclusion of <sqlite3.h> in a header
|
||||
struct sqlite3;
|
||||
@ -123,7 +124,7 @@ public:
|
||||
{
|
||||
bind(aIndex, static_cast<int>(aValue));
|
||||
}
|
||||
#else
|
||||
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux)
|
||||
/**
|
||||
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
@ -205,7 +206,7 @@ public:
|
||||
{
|
||||
bind(apName, static_cast<int>(aValue));
|
||||
}
|
||||
#else
|
||||
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux)
|
||||
/**
|
||||
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
@ -293,7 +294,7 @@ public:
|
||||
{
|
||||
bind(aName.c_str(), static_cast<int>(aValue));
|
||||
}
|
||||
#else
|
||||
#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux)
|
||||
/**
|
||||
* @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <cstdio>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <climits> // For INT_MAX
|
||||
|
||||
TEST(Statement, invalid) {
|
||||
// Create a new database
|
||||
@ -761,3 +762,16 @@ TEST(Statement, getColumns) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LONG_MAX > INT_MAX) // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux)
|
||||
TEST(Statement, bind64bitsLong) {
|
||||
// Create a new database
|
||||
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
|
||||
EXPECT_EQ(SQLite::OK, db.getErrorCode());
|
||||
EXPECT_EQ(SQLite::OK, db.getExtendedErrorCode());
|
||||
|
||||
SQLite::Statement query(db, "SELECT ?");
|
||||
query.bind(1, 4294967297L);
|
||||
query.executeStep();
|
||||
EXPECT_EQ(4294967297L, query.getColumn(0).getInt64());
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user