summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTobias Koenig <tobias.koenig.qnx@kdab.com>2013-11-27 13:11:01 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-28 00:21:56 +0100
commit9e64fc9e1cebf1e11694c4f536881128f5aee288 (patch)
tree3f9750ca6764c928fdb1ee63448dface95f47896 /src
parent7216387370203fc8f49d76cc2cb68bb5286c8dff (diff)
Fix sub-second handling in SQLite driver
Use explicit format string, that contains milliseconds, when converting an QDateTime/QTime to a SQLite field content. Task-number: QTBUG-24200 [ChangeLog][QtSql][QSQLITE] Fix sub-second handling Change-Id: Ib89152b7c3dd780b57a8826beff8b6b118e9d3d6 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'src')
-rw-r--r--src/sql/drivers/sqlite/qsql_sqlite.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp
index 0a8b71aa8a..27bc80e63f 100644
--- a/src/sql/drivers/sqlite/qsql_sqlite.cpp
+++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp
@@ -42,6 +42,7 @@
#include "qsql_sqlite_p.h"
#include <qcoreapplication.h>
+#include <qdatetime.h>
#include <qvariant.h>
#include <qsqlerror.h>
#include <qsqlfield.h>
@@ -447,6 +448,20 @@ bool QSQLiteResult::exec()
case QVariant::LongLong:
res = sqlite3_bind_int64(d->stmt, i + 1, value.toLongLong());
break;
+ case QVariant::DateTime: {
+ const QDateTime dateTime = value.toDateTime();
+ const QString str = dateTime.toString(QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"));
+ res = sqlite3_bind_text16(d->stmt, i + 1, str.utf16(),
+ str.size() * sizeof(ushort), SQLITE_TRANSIENT);
+ break;
+ }
+ case QVariant::Time: {
+ const QTime time = value.toTime();
+ const QString str = time.toString(QStringLiteral("hh:mm:ss.zzz"));
+ res = sqlite3_bind_text16(d->stmt, i + 1, str.utf16(),
+ str.size() * sizeof(ushort), SQLITE_TRANSIENT);
+ break;
+ }
case QVariant::String: {
// lifetime of string == lifetime of its qvariant
const QString *str = static_cast<const QString*>(value.constData());