From 1065917e59c0238b63dccf8cba46415fffe8da57 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Wed, 11 Jan 2017 18:09:23 -0200 Subject: [PATCH] [Qt] Save a copy when using binary data if possible --- platform/qt/src/sqlite3.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/platform/qt/src/sqlite3.cpp b/platform/qt/src/sqlite3.cpp index 57725b823..b339cb14f 100644 --- a/platform/qt/src/sqlite3.cpp +++ b/platform/qt/src/sqlite3.cpp @@ -233,7 +233,7 @@ void Statement::bind(int offset, optional value) { } } -void Statement::bind(int offset, const char* value, std::size_t length, bool /* retain */) { +void Statement::bind(int offset, const char* value, std::size_t length, bool retain) { assert(impl); if (length > std::numeric_limits::max()) { // Kept for consistence with the default implementation. @@ -241,22 +241,23 @@ void Statement::bind(int offset, const char* value, std::size_t length, bool /* } // Field numbering starts at 0. - impl->query.bindValue(offset - 1, QString::fromLatin1(value, length), QSql::In); + impl->query.bindValue(offset - 1, retain ? QByteArray(value, length) : + QByteArray::fromRawData(value, length), QSql::In); + checkQueryError(impl->query); } -void Statement::bind(int offset, const std::string& value, bool /* retain */) { - // Field numbering starts at 0. - impl->query.bindValue(offset - 1, QString::fromStdString(value), QSql::In); - checkQueryError(impl->query); +void Statement::bind(int offset, const std::string& value, bool retain) { + bind(offset, value.data(), value.size(), retain); } -void Statement::bindBlob(int offset, const void* value, std::size_t length, bool /* retain */) { - assert(impl); +void Statement::bindBlob(int offset, const void* value_, std::size_t length, bool retain) { const char* value = reinterpret_cast(value_); // Field numbering starts at 0. - impl->query.bindValue(offset - 1, QByteArray(reinterpret_cast(value), length), QSql::In | QSql::Binary); + impl->query.bindValue(offset - 1, retain ? QByteArray(value, length) : + QByteArray::fromRawData(value, length), QSql::In | QSql::Binary); + checkQueryError(impl->query); }