Skip to content

Commit ec887cf

Browse files
authored
Merge pull request #364 from SRombauts/convert-remaining-long-types
Removal of remaining long APIs
2 parents b611b5c + 3d149cc commit ec887cf

File tree

6 files changed

+28
-56
lines changed

6 files changed

+28
-56
lines changed

include/SQLiteCpp/Assertion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
namespace SQLite
2727
{
2828
// declaration of the assert handler to define in user code
29-
void assertion_failed(const char* apFile, const long apLine, const char* apFunc,
29+
void assertion_failed(const char* apFile, const int apLine, const char* apFunc,
3030
const char* apExpr, const char* apMsg);
3131

3232
#ifdef _MSC_VER

include/SQLiteCpp/Column.h

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include <string>
1717
#include <memory>
18-
#include <climits> // For INT_MAX
1918

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

8180
/// Return the integer value of the column.
82-
int getInt() const noexcept;
81+
int32_t getInt() const noexcept;
8382
/// Return the 32bits unsigned integer value of the column (note that SQLite3 does not support unsigned 64bits).
84-
unsigned getUInt() const noexcept;
83+
uint32_t getUInt() const noexcept;
8584
/// Return the 64bits integer value of the column (note that SQLite3 does not support unsigned 64bits).
86-
long long getInt64() const noexcept;
85+
int64_t getInt64() const noexcept;
8786
/// Return the double (64bits float) value of the column
8887
double getDouble() const noexcept;
8988
/**
@@ -160,62 +159,39 @@ class Column
160159
return getBytes ();
161160
}
162161

163-
/// Inline cast operator to char
162+
/// Inline cast operators to basic types
164163
operator char() const
165164
{
166165
return static_cast<char>(getInt());
167166
}
168-
/// Inline cast operator to unsigned char
169-
operator unsigned char() const
167+
operator int8_t() const
170168
{
171-
return static_cast<unsigned char>(getInt());
169+
return static_cast<int8_t>(getInt());
172170
}
173-
/// Inline cast operator to short
174-
operator short() const
171+
operator uint8_t() const
175172
{
176-
return static_cast<short>(getInt());
173+
return static_cast<uint8_t>(getInt());
177174
}
178-
/// Inline cast operator to unsigned short
179-
operator unsigned short() const
175+
operator int16_t() const
180176
{
181-
return static_cast<unsigned short>(getInt());
177+
return static_cast<int16_t>(getInt());
182178
}
183-
184-
/// Inline cast operator to int
185-
operator int() const
179+
operator uint16_t() const
186180
{
187-
return getInt();
188-
}
189-
/// Inline cast operator to 32bits unsigned integer
190-
operator unsigned int() const
191-
{
192-
return getUInt();
181+
return static_cast<uint16_t>(getInt());
193182
}
194-
#if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW)
195-
/// Inline cast operator to 32bits long
196-
operator long() const
183+
operator int32_t() const
197184
{
198185
return getInt();
199186
}
200-
/// Inline cast operator to 32bits unsigned long
201-
operator unsigned long() const
187+
operator uint32_t() const
202188
{
203189
return getUInt();
204190
}
205-
#else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS)
206-
/// Inline cast operator to 64bits long when the data model of the system is LP64 (Linux 64 bits...)
207-
operator long() const
208-
{
209-
return getInt64();
210-
}
211-
#endif
212-
213-
/// Inline cast operator to 64bits integer
214-
operator long long() const
191+
operator int64_t() const
215192
{
216193
return getInt64();
217194
}
218-
/// Inline cast operator to double
219195
operator double() const
220196
{
221197
return getDouble();

include/SQLiteCpp/Database.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ class Database
429429
*
430430
* @return Rowid of the most recent successful INSERT into the database, or 0 if there was none.
431431
*/
432-
long long getLastInsertRowid() const noexcept;
432+
int64_t getLastInsertRowid() const noexcept;
433433

434434
/// Get number of rows modified by last INSERT, UPDATE or DELETE statement (not DROP table).
435435
int getChanges() const noexcept;

src/Column.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ const char* Column::getOriginName() const noexcept
5151
#endif
5252

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

5959
// Return the unsigned integer value of the column specified by its index starting at 0
60-
unsigned Column::getUInt() const noexcept
60+
uint32_t Column::getUInt() const noexcept
6161
{
6262
return static_cast<unsigned>(getInt64());
6363
}
6464

6565
// Return the 64bits integer value of the column specified by its index starting at 0
66-
long long Column::getInt64() const noexcept
66+
int64_t Column::getInt64() const noexcept
6767
{
6868
return sqlite3_column_int64(mStmtPtr.get(), mIndex);
6969
}

src/Database.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ bool Database::tableExists(const char* apTableName)
151151
}
152152

153153
// Get the rowid of the most recent successful INSERT into the database from the current connection.
154-
long long Database::getLastInsertRowid() const noexcept
154+
int64_t Database::getLastInsertRowid() const noexcept
155155
{
156156
return sqlite3_last_insert_rowid(getHandle());
157157
}

tests/Column_test.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <SQLiteCpp/Statement.h>
1414
#include <SQLiteCpp/Column.h>
1515

16-
#include <sqlite3.h> // for sqlite3_int64
17-
1816
#include <gtest/gtest.h>
1917

2018
#include <cstdio>
@@ -59,12 +57,13 @@ TEST(Column, basis)
5957

6058
// validates every variant of cast operators, and conversions of types
6159
{
62-
const sqlite3_int64 id1 = query.getColumn(0); // operator long long()
63-
const int64_t id2 = query.getColumn(0); // operator long long()
64-
const long long id3 = query.getColumn(0); // operator long long()
65-
const long id4 = query.getColumn(0); // operator long long() or long() depending on compiler/architecture
66-
const char id5 = query.getColumn(0); // operator char()
67-
const short id6 = query.getColumn(0); // operator short()
60+
const int64_t id1 = query.getColumn(0); // operator int64_t()
61+
const int32_t id2 = query.getColumn(0); // operator int32_t()
62+
const int id3 = query.getColumn(0); // operator int32_t()
63+
const int16_t id4 = query.getColumn(0); // operator int32_t()
64+
const short id5 = query.getColumn(0); // operator int32_t()
65+
const int8_t id6 = query.getColumn(0); // operator int32_t()
66+
const char id7 = query.getColumn(0); // operator int32_t()
6867
const unsigned int uint1 = query.getColumn(0); // operator unsigned int()
6968
const uint32_t uint2 = query.getColumn(0); // operator unsigned int()
7069
const unsigned char uint3 = query.getColumn(0); // operator unsigned char()
@@ -83,9 +82,6 @@ TEST(Column, basis)
8382
EXPECT_EQ(1, id1);
8483
EXPECT_EQ(1, id2);
8584
EXPECT_EQ(1, id3);
86-
EXPECT_EQ(1, id4);
87-
EXPECT_EQ(1, id5);
88-
EXPECT_EQ(1, id6);
8985
EXPECT_EQ(1U, uint1);
9086
EXPECT_EQ(1U, uint2);
9187
EXPECT_EQ(1U, uint3);

0 commit comments

Comments
 (0)