Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of remaining long APIs #364

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/SQLiteCpp/Assertion.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace SQLite
{
// declaration of the assert handler to define in user code
void assertion_failed(const char* apFile, const long apLine, const char* apFunc,
void assertion_failed(const char* apFile, const int apLine, const char* apFunc,
const char* apExpr, const char* apMsg);

#ifdef _MSC_VER
Expand Down
54 changes: 15 additions & 39 deletions include/SQLiteCpp/Column.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <string>
#include <memory>
#include <climits> // For INT_MAX

// Forward declarations to avoid inclusion of <sqlite3.h> in a header
struct sqlite3_stmt;
Expand Down Expand Up @@ -79,11 +78,11 @@ class Column
#endif

/// Return the integer value of the column.
int getInt() const noexcept;
int32_t getInt() const noexcept;
/// Return the 32bits unsigned integer value of the column (note that SQLite3 does not support unsigned 64bits).
unsigned getUInt() const noexcept;
uint32_t getUInt() const noexcept;
/// Return the 64bits integer value of the column (note that SQLite3 does not support unsigned 64bits).
long long getInt64() const noexcept;
int64_t getInt64() const noexcept;
/// Return the double (64bits float) value of the column
double getDouble() const noexcept;
/**
Expand Down Expand Up @@ -160,62 +159,39 @@ class Column
return getBytes ();
}

/// Inline cast operator to char
/// Inline cast operators to basic types
operator char() const
{
return static_cast<char>(getInt());
}
/// Inline cast operator to unsigned char
operator unsigned char() const
operator int8_t() const
{
return static_cast<unsigned char>(getInt());
return static_cast<int8_t>(getInt());
}
/// Inline cast operator to short
operator short() const
operator uint8_t() const
{
return static_cast<short>(getInt());
return static_cast<uint8_t>(getInt());
}
/// Inline cast operator to unsigned short
operator unsigned short() const
operator int16_t() const
{
return static_cast<unsigned short>(getInt());
return static_cast<int16_t>(getInt());
}

/// Inline cast operator to int
operator int() const
operator uint16_t() const
{
return getInt();
}
/// Inline cast operator to 32bits unsigned integer
operator unsigned int() const
{
return getUInt();
return static_cast<uint16_t>(getInt());
}
#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
operator long() const
operator int32_t() const
{
return getInt();
}
/// Inline cast operator to 32bits unsigned long
operator unsigned long() const
operator uint32_t() const
{
return getUInt();
}
#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 LP64 (Linux 64 bits...)
operator long() const
{
return getInt64();
}
#endif

/// Inline cast operator to 64bits integer
operator long long() const
operator int64_t() const
{
return getInt64();
}
/// Inline cast operator to double
operator double() const
{
return getDouble();
Expand Down
2 changes: 1 addition & 1 deletion include/SQLiteCpp/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ class Database
*
* @return Rowid of the most recent successful INSERT into the database, or 0 if there was none.
*/
long long getLastInsertRowid() const noexcept;
int64_t getLastInsertRowid() const noexcept;

/// Get number of rows modified by last INSERT, UPDATE or DELETE statement (not DROP table).
int getChanges() const noexcept;
Expand Down
6 changes: 3 additions & 3 deletions src/Column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ const char* Column::getOriginName() const noexcept
#endif

// Return the integer value of the column specified by its index starting at 0
int Column::getInt() const noexcept
int32_t Column::getInt() const noexcept
{
return sqlite3_column_int(mStmtPtr.get(), mIndex);
}

// Return the unsigned integer value of the column specified by its index starting at 0
unsigned Column::getUInt() const noexcept
uint32_t Column::getUInt() const noexcept
{
return static_cast<unsigned>(getInt64());
}

// Return the 64bits integer value of the column specified by its index starting at 0
long long Column::getInt64() const noexcept
int64_t Column::getInt64() const noexcept
{
return sqlite3_column_int64(mStmtPtr.get(), mIndex);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bool Database::tableExists(const char* apTableName)
}

// Get the rowid of the most recent successful INSERT into the database from the current connection.
long long Database::getLastInsertRowid() const noexcept
int64_t Database::getLastInsertRowid() const noexcept
{
return sqlite3_last_insert_rowid(getHandle());
}
Expand Down
18 changes: 7 additions & 11 deletions tests/Column_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <SQLiteCpp/Statement.h>
#include <SQLiteCpp/Column.h>

#include <sqlite3.h> // for sqlite3_int64

#include <gtest/gtest.h>

#include <cstdio>
Expand Down Expand Up @@ -59,12 +57,13 @@ TEST(Column, basis)

// validates every variant of cast operators, and conversions of types
{
const sqlite3_int64 id1 = query.getColumn(0); // operator long long()
const int64_t id2 = query.getColumn(0); // operator long long()
const long long id3 = query.getColumn(0); // operator long long()
const long id4 = query.getColumn(0); // operator long long() or long() depending on compiler/architecture
const char id5 = query.getColumn(0); // operator char()
const short id6 = query.getColumn(0); // operator short()
const int64_t id1 = query.getColumn(0); // operator int64_t()
const int32_t id2 = query.getColumn(0); // operator int32_t()
const int id3 = query.getColumn(0); // operator int32_t()
const int16_t id4 = query.getColumn(0); // operator int32_t()
const short id5 = query.getColumn(0); // operator int32_t()
const int8_t id6 = query.getColumn(0); // operator int32_t()
const char id7 = query.getColumn(0); // operator int32_t()
const unsigned int uint1 = query.getColumn(0); // operator unsigned int()
const uint32_t uint2 = query.getColumn(0); // operator unsigned int()
const unsigned char uint3 = query.getColumn(0); // operator unsigned char()
Expand All @@ -83,9 +82,6 @@ TEST(Column, basis)
EXPECT_EQ(1, id1);
EXPECT_EQ(1, id2);
EXPECT_EQ(1, id3);
EXPECT_EQ(1, id4);
EXPECT_EQ(1, id5);
EXPECT_EQ(1, id6);
EXPECT_EQ(1U, uint1);
EXPECT_EQ(1U, uint2);
EXPECT_EQ(1U, uint3);
Expand Down