Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update googletest to v1.18.0 (#583)
- Improve tests for `Savepoint::rollbackTo()` and scope-exit rollback semantics (#584)
- Fix link errors in supplied assertion handlers and add handler-enabled CI coverage (#587)
- Make column type constants usable in constant expressions (ABI change) (#609)

### Removed

Expand Down
11 changes: 6 additions & 5 deletions include/SQLiteCpp/Column.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ struct sqlite3_stmt;
namespace SQLite
{

SQLITECPP_API extern const int INTEGER; ///< SQLITE_INTEGER
SQLITECPP_API extern const int FLOAT; ///< SQLITE_FLOAT
SQLITECPP_API extern const int TEXT; ///< SQLITE_TEXT
SQLITECPP_API extern const int BLOB; ///< SQLITE_BLOB
SQLITECPP_API extern const int Null; ///< SQLITE_NULL
/// SQLite result type codes, usable in constant expressions without including sqlite3.h.
inline constexpr int INTEGER = 1; ///< SQLITE_INTEGER
inline constexpr int FLOAT = 2; ///< SQLITE_FLOAT
inline constexpr int TEXT = 3; ///< SQLITE_TEXT
inline constexpr int BLOB = 4; ///< SQLITE_BLOB
inline constexpr int Null = 5; ///< SQLITE_NULL

/**
* @brief Encapsulation of a Column in a row of the result pointed by the prepared Statement.
Expand Down
10 changes: 5 additions & 5 deletions src/Column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
namespace SQLite
{

const int INTEGER = SQLITE_INTEGER;
const int FLOAT = SQLITE_FLOAT;
const int TEXT = SQLITE_TEXT;
const int BLOB = SQLITE_BLOB;
const int Null = SQLITE_NULL;
static_assert(INTEGER == SQLITE_INTEGER, "SQLite::INTEGER must match SQLITE_INTEGER");
static_assert(FLOAT == SQLITE_FLOAT, "SQLite::FLOAT must match SQLITE_FLOAT");
static_assert(TEXT == SQLITE_TEXT, "SQLite::TEXT must match SQLITE_TEXT");
static_assert(BLOB == SQLITE_BLOB, "SQLite::BLOB must match SQLITE_BLOB");
static_assert(Null == SQLITE_NULL, "SQLite::Null must match SQLITE_NULL");


// Encapsulation of a Column in a row of the result pointed by the prepared Statement.
Expand Down
35 changes: 35 additions & 0 deletions tests/Column_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,41 @@
#include <stdint.h>


TEST(Column, typeConstantsAsCaseLabels)
{
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
SQLite::Statement query(db, "SELECT 42, 1.5, 'text', X'1234', NULL");

ASSERT_TRUE(query.executeStep());
ASSERT_EQ(5, query.getColumnCount());

// Each label must be a constant expression, and each code must match SQLite's runtime type.
for (int i = 0; i < query.getColumnCount(); ++i)
{
switch (query.getColumn(i).getType())
{
case SQLite::INTEGER:
EXPECT_EQ(0, i);
break;
case SQLite::FLOAT:
EXPECT_EQ(1, i);
break;
case SQLite::TEXT:
EXPECT_EQ(2, i);
break;
case SQLite::BLOB:
EXPECT_EQ(3, i);
break;
case SQLite::Null:
EXPECT_EQ(4, i);
break;
default:
FAIL() << "Unexpected type for column " << i;
}
}
}


static void test_column_basis(bool utf16)
{
// Create a new database
Expand Down
Loading