forked from qt-creator/qt-creator
Sqlite: Use std::byte
Change-Id: Ie5bdbae67f7d0f9e533ad20ddb66d03057df2028 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -687,7 +687,8 @@ StringType textForColumn(sqlite3_stmt *sqlStatment, int column)
|
||||
|
||||
BlobView blobForColumn(sqlite3_stmt *sqlStatment, int column)
|
||||
{
|
||||
const byte *blob = reinterpret_cast<const byte *>(sqlite3_column_blob(sqlStatment, column));
|
||||
const std::byte *blob = reinterpret_cast<const std::byte *>(
|
||||
sqlite3_column_blob(sqlStatment, column));
|
||||
std::size_t size = std::size_t(sqlite3_column_bytes(sqlStatment, column));
|
||||
|
||||
return {blob, size};
|
||||
|
||||
@@ -42,22 +42,22 @@ class BlobView
|
||||
public:
|
||||
BlobView() = default;
|
||||
|
||||
BlobView(const byte *data, std::size_t size)
|
||||
BlobView(const std::byte *data, std::size_t size)
|
||||
: m_data(data)
|
||||
, m_size(size)
|
||||
{}
|
||||
|
||||
BlobView(const QByteArray &byteArray)
|
||||
: m_data(reinterpret_cast<const byte *>(byteArray.constData()))
|
||||
: m_data(reinterpret_cast<const std::byte *>(byteArray.constData()))
|
||||
, m_size(static_cast<std::size_t>(byteArray.size()))
|
||||
{}
|
||||
|
||||
BlobView(const std::vector<Sqlite::byte> &bytes)
|
||||
BlobView(const std::vector<std::byte> &bytes)
|
||||
: m_data(bytes.data())
|
||||
, m_size(static_cast<std::size_t>(bytes.size()))
|
||||
{}
|
||||
|
||||
const byte *data() const { return m_data; }
|
||||
const std::byte *data() const { return m_data; }
|
||||
const char *cdata() const { return reinterpret_cast<const char *>(m_data); }
|
||||
std::size_t size() const { return m_size; }
|
||||
int sisize() const { return static_cast<int>(m_size); }
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const byte *m_data{};
|
||||
const std::byte *m_data{};
|
||||
std::size_t m_size{};
|
||||
};
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
std::copy_n(blobView.data(), blobView.size(), std::back_inserter(bytes));
|
||||
}
|
||||
|
||||
std::vector<Sqlite::byte> bytes;
|
||||
std::vector<std::byte> bytes;
|
||||
};
|
||||
|
||||
class ByteArrayBlob
|
||||
|
||||
@@ -66,8 +66,6 @@ enum class OpenMode : char
|
||||
|
||||
enum class ChangeType : int { Delete = 9, Insert = 18, Update = 23 };
|
||||
|
||||
enum class byte : unsigned char {};
|
||||
|
||||
enum class CallbackControl : unsigned char { Continue, Abort };
|
||||
|
||||
} // namespace Sqlite
|
||||
|
||||
@@ -118,7 +118,7 @@ SessionChangeSet::~SessionChangeSet()
|
||||
|
||||
BlobView SessionChangeSet::asBlobView() const
|
||||
{
|
||||
return {static_cast<const byte *>(m_data), static_cast<std::size_t>(m_size)};
|
||||
return {static_cast<const std::byte *>(m_data), static_cast<std::size_t>(m_size)};
|
||||
}
|
||||
|
||||
SessionChangeSetInternal::ConstIterator SessionChangeSet::begin() const
|
||||
|
||||
@@ -323,7 +323,7 @@ TEST_F(SqliteStatement, BindBlob)
|
||||
{
|
||||
SqliteTestStatement statement("WITH T(blob) AS (VALUES (?)) SELECT blob FROM T", database);
|
||||
const unsigned char chars[] = "aaafdfdlll";
|
||||
auto bytePointer = reinterpret_cast<const Sqlite::byte *>(chars);
|
||||
auto bytePointer = reinterpret_cast<const std::byte *>(chars);
|
||||
Sqlite::BlobView bytes{bytePointer, sizeof(chars) - 1};
|
||||
|
||||
statement.bind(1, bytes);
|
||||
@@ -527,7 +527,7 @@ TEST_F(SqliteStatement, WriteBlobs)
|
||||
SqliteTestStatement statement("INSERT INTO test VALUES ('blob', 40, ?)", database);
|
||||
SqliteTestStatement readStatement("SELECT value FROM test WHERE name = 'blob'", database);
|
||||
const unsigned char chars[] = "aaafdfdlll";
|
||||
auto bytePointer = reinterpret_cast<const Sqlite::byte *>(chars);
|
||||
auto bytePointer = reinterpret_cast<const std::byte *>(chars);
|
||||
Sqlite::BlobView bytes{bytePointer, sizeof(chars) - 1};
|
||||
|
||||
statement.write(bytes);
|
||||
@@ -657,7 +657,7 @@ TEST_F(SqliteStatement, GetBlobValues)
|
||||
database.execute("INSERT INTO test VALUES ('blob', 40, x'AABBCCDD')");
|
||||
ReadStatement<1> statement("SELECT value FROM test WHERE name='blob'", database);
|
||||
const int value = 0xDDCCBBAA;
|
||||
auto bytePointer = reinterpret_cast<const Sqlite::byte *>(&value);
|
||||
auto bytePointer = reinterpret_cast<const std::byte *>(&value);
|
||||
Sqlite::BlobView bytes{bytePointer, 4};
|
||||
|
||||
auto values = statement.values<Sqlite::Blob>(1);
|
||||
|
||||
Reference in New Issue
Block a user