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)
|
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));
|
std::size_t size = std::size_t(sqlite3_column_bytes(sqlStatment, column));
|
||||||
|
|
||||||
return {blob, size};
|
return {blob, size};
|
||||||
|
|||||||
@@ -42,22 +42,22 @@ class BlobView
|
|||||||
public:
|
public:
|
||||||
BlobView() = default;
|
BlobView() = default;
|
||||||
|
|
||||||
BlobView(const byte *data, std::size_t size)
|
BlobView(const std::byte *data, std::size_t size)
|
||||||
: m_data(data)
|
: m_data(data)
|
||||||
, m_size(size)
|
, m_size(size)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BlobView(const QByteArray &byteArray)
|
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()))
|
, 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_data(bytes.data())
|
||||||
, m_size(static_cast<std::size_t>(bytes.size()))
|
, 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); }
|
const char *cdata() const { return reinterpret_cast<const char *>(m_data); }
|
||||||
std::size_t size() const { return m_size; }
|
std::size_t size() const { return m_size; }
|
||||||
int sisize() const { return static_cast<int>(m_size); }
|
int sisize() const { return static_cast<int>(m_size); }
|
||||||
@@ -71,7 +71,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const byte *m_data{};
|
const std::byte *m_data{};
|
||||||
std::size_t m_size{};
|
std::size_t m_size{};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ public:
|
|||||||
std::copy_n(blobView.data(), blobView.size(), std::back_inserter(bytes));
|
std::copy_n(blobView.data(), blobView.size(), std::back_inserter(bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Sqlite::byte> bytes;
|
std::vector<std::byte> bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ByteArrayBlob
|
class ByteArrayBlob
|
||||||
|
|||||||
@@ -66,8 +66,6 @@ enum class OpenMode : char
|
|||||||
|
|
||||||
enum class ChangeType : int { Delete = 9, Insert = 18, Update = 23 };
|
enum class ChangeType : int { Delete = 9, Insert = 18, Update = 23 };
|
||||||
|
|
||||||
enum class byte : unsigned char {};
|
|
||||||
|
|
||||||
enum class CallbackControl : unsigned char { Continue, Abort };
|
enum class CallbackControl : unsigned char { Continue, Abort };
|
||||||
|
|
||||||
} // namespace Sqlite
|
} // namespace Sqlite
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ SessionChangeSet::~SessionChangeSet()
|
|||||||
|
|
||||||
BlobView SessionChangeSet::asBlobView() const
|
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
|
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);
|
SqliteTestStatement statement("WITH T(blob) AS (VALUES (?)) SELECT blob FROM T", database);
|
||||||
const unsigned char chars[] = "aaafdfdlll";
|
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};
|
Sqlite::BlobView bytes{bytePointer, sizeof(chars) - 1};
|
||||||
|
|
||||||
statement.bind(1, bytes);
|
statement.bind(1, bytes);
|
||||||
@@ -527,7 +527,7 @@ TEST_F(SqliteStatement, WriteBlobs)
|
|||||||
SqliteTestStatement statement("INSERT INTO test VALUES ('blob', 40, ?)", database);
|
SqliteTestStatement statement("INSERT INTO test VALUES ('blob', 40, ?)", database);
|
||||||
SqliteTestStatement readStatement("SELECT value FROM test WHERE name = 'blob'", database);
|
SqliteTestStatement readStatement("SELECT value FROM test WHERE name = 'blob'", database);
|
||||||
const unsigned char chars[] = "aaafdfdlll";
|
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};
|
Sqlite::BlobView bytes{bytePointer, sizeof(chars) - 1};
|
||||||
|
|
||||||
statement.write(bytes);
|
statement.write(bytes);
|
||||||
@@ -657,7 +657,7 @@ TEST_F(SqliteStatement, GetBlobValues)
|
|||||||
database.execute("INSERT INTO test VALUES ('blob', 40, x'AABBCCDD')");
|
database.execute("INSERT INTO test VALUES ('blob', 40, x'AABBCCDD')");
|
||||||
ReadStatement<1> statement("SELECT value FROM test WHERE name='blob'", database);
|
ReadStatement<1> statement("SELECT value FROM test WHERE name='blob'", database);
|
||||||
const int value = 0xDDCCBBAA;
|
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};
|
Sqlite::BlobView bytes{bytePointer, 4};
|
||||||
|
|
||||||
auto values = statement.values<Sqlite::Blob>(1);
|
auto values = statement.values<Sqlite::Blob>(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user