mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
Revert recent switch from uint32_t/int64_t to use int/unsigned/long/long long and fix #93
This commit is contained in:
parent
93dd526341
commit
f77b707206
@ -14,7 +14,7 @@
|
||||
#include <SQLiteCpp/Exception.h>
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
namespace SQLite
|
||||
@ -86,10 +86,10 @@ public:
|
||||
|
||||
/// Return the integer value of the column.
|
||||
int getInt() const noexcept; // nothrow
|
||||
/// Return the 32bits unsigned integer value of the column (note that SQLite3 does not support uint64_t).
|
||||
uint32_t getUInt() const noexcept; // nothrow
|
||||
/// Return the 64bits integer value of the column (note that SQLite3 does not support uint64_t).
|
||||
int64_t getInt64() const noexcept; // nothrow
|
||||
/// Return the 32bits unsigned integer value of the column (note that SQLite3 does not support unsigned 64bits).
|
||||
unsigned getUInt() const noexcept; // nothrow
|
||||
/// Return the 64bits integer value of the column (note that SQLite3 does not support unsigned 64bits).
|
||||
long long getInt64() const noexcept; // nothrow
|
||||
/// Return the double (64bits float) value of the column
|
||||
double getDouble() const noexcept; // nothrow
|
||||
/**
|
||||
@ -171,30 +171,35 @@ public:
|
||||
{
|
||||
return getInt();
|
||||
}
|
||||
#if !defined(__x86_64__) || defined(__APPLE__)
|
||||
/// Inline cast operator to long as 32bits integer for 32bit systems
|
||||
/// Inline cast operator to 32bits unsigned integer
|
||||
inline operator unsigned int() const
|
||||
{
|
||||
return getUInt();
|
||||
}
|
||||
#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits)
|
||||
/// Inline cast operator to 32bits long
|
||||
inline operator long() const
|
||||
{
|
||||
return getInt();
|
||||
}
|
||||
#endif // __x86_64__
|
||||
#if defined(__GNUC__) && !defined(__APPLE__)
|
||||
/// Inline cast operator to long long for GCC and Clang
|
||||
/// Inline cast operator to 32bits unsigned long
|
||||
inline operator unsigned long() const
|
||||
{
|
||||
return getUInt();
|
||||
}
|
||||
#else
|
||||
/// Inline cast operator to 64bits long when the data model of the system is ILP64 (Linux 64 bits...)
|
||||
inline operator long() const
|
||||
{
|
||||
return getInt64();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Inline cast operator to 64bits integer
|
||||
inline operator long long() const
|
||||
{
|
||||
return getInt64();
|
||||
}
|
||||
#endif // __GNUC__
|
||||
/// Inline cast operator to 64bits integer
|
||||
inline operator int64_t() const
|
||||
{
|
||||
return getInt64();
|
||||
}
|
||||
/// Inline cast operator to 32bits unsigned integer
|
||||
inline operator uint32_t() const
|
||||
{
|
||||
return getUInt();
|
||||
}
|
||||
/// Inline cast operator to double
|
||||
inline operator double() const
|
||||
{
|
||||
|
@ -20,6 +20,7 @@ struct sqlite3_context;
|
||||
struct Mem;
|
||||
typedef struct Mem sqlite3_value;
|
||||
|
||||
|
||||
namespace SQLite
|
||||
{
|
||||
|
||||
@ -256,7 +257,7 @@ public:
|
||||
*
|
||||
* @return Rowid of the most recent successful INSERT into the database, or 0 if there was none.
|
||||
*/
|
||||
int64_t getLastInsertRowid() const noexcept; // nothrow
|
||||
long long getLastInsertRowid() const noexcept; // nothrow
|
||||
|
||||
/// Get total number of rows modified by all INSERT, UPDATE or DELETE statement since connection (not DROP table).
|
||||
int getTotalChanges() const noexcept; // nothrow
|
||||
|
@ -10,11 +10,10 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <SQLiteCpp/Exception.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <SQLiteCpp/Exception.h>
|
||||
|
||||
// Forward declarations to avoid inclusion of <sqlite3.h> in a header
|
||||
struct sqlite3;
|
||||
@ -108,14 +107,14 @@ public:
|
||||
* @brief Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
void bind(const int aIndex, const int aValue);
|
||||
/**
|
||||
* @brief Bind a 64bits int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
void bind(const int aIndex, const int64_t aValue);
|
||||
/**
|
||||
* @brief Bind a 32bits unsigned int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
void bind(const int aIndex, const uint32_t aValue);
|
||||
void bind(const int aIndex, const unsigned aValue);
|
||||
/**
|
||||
* @brief Bind a 64bits int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
void bind(const int aIndex, const long long aValue);
|
||||
/**
|
||||
* @brief Bind a double (64bits float) value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
@ -171,14 +170,14 @@ public:
|
||||
* @brief Bind an int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
void bind(const char* apName, const int aValue);
|
||||
/**
|
||||
* @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
void bind(const char* apName, const int64_t aValue);
|
||||
/**
|
||||
* @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 uint32_t aValue);
|
||||
void bind(const char* apName, const unsigned aValue);
|
||||
/**
|
||||
* @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
void bind(const char* apName, const long long aValue);
|
||||
/**
|
||||
* @brief Bind a double (64bits float) value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
@ -239,16 +238,16 @@ public:
|
||||
bind(aName.c_str(), aValue);
|
||||
}
|
||||
/**
|
||||
* @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
* @brief Bind a 32bits unsigned int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
inline void bind(const std::string& aName, const int64_t aValue)
|
||||
inline void bind(const std::string& aName, const unsigned aValue)
|
||||
{
|
||||
bind(aName.c_str(), aValue);
|
||||
}
|
||||
/**
|
||||
* @brief Bind a 32bits unsigned int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
* @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
|
||||
*/
|
||||
inline void bind(const std::string& aName, const uint32_t aValue)
|
||||
inline void bind(const std::string& aName, const long long aValue)
|
||||
{
|
||||
bind(aName.c_str(), aValue);
|
||||
}
|
||||
|
@ -59,13 +59,13 @@ int Column::getInt() const noexcept // nothrow
|
||||
}
|
||||
|
||||
// Return the unsigned integer value of the column specified by its index starting at 0
|
||||
uint32_t Column::getUInt() const noexcept // nothrow
|
||||
unsigned Column::getUInt() const noexcept // nothrow
|
||||
{
|
||||
return static_cast<uint32_t>(getInt64());
|
||||
return static_cast<unsigned>(getInt64());
|
||||
}
|
||||
|
||||
// Return the 64bits integer value of the column specified by its index starting at 0
|
||||
int64_t Column::getInt64() const noexcept // nothrow
|
||||
long long Column::getInt64() const noexcept // nothrow
|
||||
{
|
||||
return sqlite3_column_int64(mStmtPtr, mIndex);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ bool Database::tableExists(const char* apTableName)
|
||||
}
|
||||
|
||||
// Get the rowid of the most recent successful INSERT into the database from the current connection.
|
||||
int64_t Database::getLastInsertRowid() const noexcept // nothrow
|
||||
long long Database::getLastInsertRowid() const noexcept // nothrow
|
||||
{
|
||||
return sqlite3_last_insert_rowid(mpSQLite);
|
||||
}
|
||||
|
@ -72,15 +72,15 @@ void Statement::bind(const int aIndex, const int aValue)
|
||||
check(ret);
|
||||
}
|
||||
|
||||
// Bind a 64bits int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||
void Statement::bind(const int aIndex, const int64_t aValue)
|
||||
// Bind a 32bits unsigned int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||
void Statement::bind(const int aIndex, const unsigned aValue)
|
||||
{
|
||||
const int ret = sqlite3_bind_int64(mStmtPtr, aIndex, aValue);
|
||||
check(ret);
|
||||
}
|
||||
|
||||
// Bind a 32bits unsigned int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||
void Statement::bind(const int aIndex, const uint32_t aValue)
|
||||
// Bind a 64bits int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||
void Statement::bind(const int aIndex, const long long aValue)
|
||||
{
|
||||
const int ret = sqlite3_bind_int64(mStmtPtr, aIndex, aValue);
|
||||
check(ret);
|
||||
@ -153,16 +153,16 @@ void Statement::bind(const char* apName, const int aValue)
|
||||
check(ret);
|
||||
}
|
||||
|
||||
// Bind a 64bits int value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||
void Statement::bind(const char* apName, const int64_t aValue)
|
||||
// Bind a 32bits unsigned int value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||
void Statement::bind(const char* apName, const unsigned aValue)
|
||||
{
|
||||
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
|
||||
const int ret = sqlite3_bind_int64(mStmtPtr, index, aValue);
|
||||
check(ret);
|
||||
}
|
||||
|
||||
// Bind a 32bits unsigned int value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||
void Statement::bind(const char* apName, const uint32_t aValue)
|
||||
// Bind a 64bits int value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||
void Statement::bind(const char* apName, const long long aValue)
|
||||
{
|
||||
const int index = sqlite3_bind_parameter_index(mStmtPtr, apName);
|
||||
const int ret = sqlite3_bind_int64(mStmtPtr, index, aValue);
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
TEST(Column, basis) {
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
TEST(Statement, invalid) {
|
||||
@ -231,7 +232,7 @@ TEST(Statement, bindings) {
|
||||
// Fourth row with string/int64/float
|
||||
{
|
||||
const std::string fourth("fourth");
|
||||
const int64_t int64 = 12345678900000LL;
|
||||
const long long int64 = 12345678900000LL;
|
||||
const float float32 = 0.234f;
|
||||
insert.bind(1, fourth);
|
||||
insert.bind(2, int64);
|
||||
@ -369,7 +370,7 @@ TEST(Statement, bindByName) {
|
||||
// Second row with string/int64/float
|
||||
{
|
||||
const std::string second("second");
|
||||
const int64_t int64 = 12345678900000LL;
|
||||
const long long int64 = 12345678900000LL;
|
||||
const float float32 = 0.234f;
|
||||
insert.bind("@msg", second);
|
||||
insert.bind("@int", int64);
|
||||
|
Loading…
x
Reference in New Issue
Block a user