summaryrefslogtreecommitdiff
path: root/platform/qt
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-11-09 17:58:05 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-11-09 19:17:10 +0200
commit6b5afaab7611cc59c86f749fd9130edb512b4945 (patch)
tree048450720e95ef114188959a3d0d439c7987fa39 /platform/qt
parenta339dcc6cc16c991fbc083cdca99c7fc440221df (diff)
downloadqtlocation-mapboxgl-6b5afaab7611cc59c86f749fd9130edb512b4945.tar.gz
[Qt] Explicit QVariant type as string when binding text
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/src/sqlite3.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/platform/qt/src/sqlite3.cpp b/platform/qt/src/sqlite3.cpp
index 1d18946364..2f3db12f33 100644
--- a/platform/qt/src/sqlite3.cpp
+++ b/platform/qt/src/sqlite3.cpp
@@ -277,9 +277,13 @@ void Statement::bind(int offset, const char* value, std::size_t length, bool ret
throw std::range_error("value too long");
}
+ // Qt SQLite driver treats QByteArray as blob: we need to explicitly
+ // declare the variant type as string.
+ QVariant text(QVariant::Type::String);
+ text.setValue(retain ? QByteArray(value, length) : QByteArray::fromRawData(value, length));
+
// Field numbering starts at 0.
- impl->query.bindValue(offset - 1, retain ? QByteArray(value, length) :
- QByteArray::fromRawData(value, length), QSql::In);
+ impl->query.bindValue(offset - 1, std::move(text), QSql::In);
checkQueryError(impl->query);
}
@@ -289,7 +293,12 @@ void Statement::bind(int offset, const std::string& value, bool retain) {
}
void Statement::bindBlob(int offset, const void* value_, std::size_t length, bool retain) {
+ assert(impl);
const char* value = reinterpret_cast<const char*>(value_);
+ if (length > std::numeric_limits<int>::max()) {
+ // Kept for consistence with the default implementation.
+ throw std::range_error("value too long");
+ }
// Field numbering starts at 0.
impl->query.bindValue(offset - 1, retain ? QByteArray(value, length) :