forked from qt-creator/qt-creator
Sqlite: Fix handling of blob and blob views
Change-Id: I90c31307ff3299975f820e191085ba93ed8afe0f Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -277,6 +277,30 @@ void BaseStatement::bind(int index, const Value &value)
|
||||
case ValueType::String:
|
||||
bind(index, value.toStringView());
|
||||
break;
|
||||
case ValueType::Blob:
|
||||
bind(index, value.toBlobView());
|
||||
break;
|
||||
case ValueType::Null:
|
||||
bind(index, NullValue{});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void BaseStatement::bind(int index, ValueView value)
|
||||
{
|
||||
switch (value.type()) {
|
||||
case ValueType::Integer:
|
||||
bind(index, value.toInteger());
|
||||
break;
|
||||
case ValueType::Float:
|
||||
bind(index, value.toFloat());
|
||||
break;
|
||||
case ValueType::String:
|
||||
bind(index, value.toStringView());
|
||||
break;
|
||||
case ValueType::Blob:
|
||||
bind(index, value.toBlobView());
|
||||
break;
|
||||
case ValueType::Null:
|
||||
bind(index, NullValue{});
|
||||
break;
|
||||
|
||||
@@ -91,6 +91,7 @@ public:
|
||||
void bind(int index, Utils::span<const char *> values);
|
||||
void bind(int index, Utils::SmallStringView value);
|
||||
void bind(int index, const Value &value);
|
||||
void bind(int index, ValueView value);
|
||||
void bind(int index, BlobView blobView);
|
||||
|
||||
void bind(int index, uint value) { bind(index, static_cast<long long>(value)); }
|
||||
|
||||
@@ -44,11 +44,11 @@ class NullValue
|
||||
friend bool operator==(NullValue, NullValue) { return false; }
|
||||
};
|
||||
|
||||
template<typename StringType>
|
||||
template<typename StringType, typename BlobType>
|
||||
class ValueBase
|
||||
{
|
||||
public:
|
||||
using VariantType = Utils::variant<NullValue, long long, double, StringType, Blob>;
|
||||
using VariantType = Utils::variant<NullValue, long long, double, StringType, BlobType>;
|
||||
|
||||
ValueBase() = default;
|
||||
|
||||
@@ -115,9 +115,12 @@ public:
|
||||
|
||||
BlobView toBlobView() const
|
||||
{
|
||||
const Blob &blob = Utils::get<int(ValueType::Blob)>(value);
|
||||
|
||||
return {blob.bytes};
|
||||
const BlobType &blob = Utils::get<int(ValueType::Blob)>(value);
|
||||
if constexpr (std::is_same_v<BlobType, Blob>) {
|
||||
return {blob.bytes};
|
||||
} else {
|
||||
return blob;
|
||||
}
|
||||
}
|
||||
explicit operator QVariant() const
|
||||
{
|
||||
@@ -245,7 +248,7 @@ public:
|
||||
VariantType value;
|
||||
};
|
||||
|
||||
class ValueView : public ValueBase<Utils::SmallStringView>
|
||||
class ValueView : public ValueBase<Utils::SmallStringView, BlobView>
|
||||
{
|
||||
public:
|
||||
explicit ValueView(ValueBase &&base)
|
||||
@@ -259,9 +262,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class Value : public ValueBase<Utils::SmallString>
|
||||
class Value : public ValueBase<Utils::SmallString, Blob>
|
||||
{
|
||||
using Base = ValueBase<Utils::SmallString>;
|
||||
using Base = ValueBase<Utils::SmallString, Blob>;
|
||||
|
||||
public:
|
||||
using Base::Base;
|
||||
|
||||
Reference in New Issue
Block a user