summaryrefslogtreecommitdiff
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 17:59:05 +0200
commitfadeea9d028fe9ba8772b52aa751258bdf4d50a9 (patch)
tree048450720e95ef114188959a3d0d439c7987fa39
parenta339dcc6cc16c991fbc083cdca99c7fc440221df (diff)
downloadqtlocation-mapboxgl-upstream/qt-fix-bind-text.tar.gz
[Qt] Explicit QVariant type as string when binding textupstream/qt-fix-bind-text
-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) :