summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2015-01-19 13:49:52 +0100
committerFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2015-01-21 11:10:14 +0100
commitb6191b16d41459ed73cea738dfaf8e25e81ae22b (patch)
tree6ad0952af507bf1ab8df9612023d6e224db8d7e2 /src/sql
parentb2883a6acc7a8d8372a815cc91dd1a8449f25723 (diff)
parent9087df6bd2dd5198ccf101a237aadee331e51ec3 (diff)
Merge remote-tracking branch 'origin/5.4' into dev
Conflicts: src/corelib/global/global.pri src/corelib/global/qcompilerdetection.h src/corelib/global/qglobal.h src/corelib/tools/qdatetime.cpp src/plugins/platforms/xcb/qxcbscreen.h src/plugins/platforms/xcb/qxcbwindow.h src/widgets/dialogs/qcolordialog.cpp src/widgets/dialogs/qcolordialog_p.h tools/configure/configureapp.cpp Change-Id: Ie9d6e9df13e570da0a90a67745a0d05f46c532af
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.cpp12
-rw-r--r--src/sql/drivers/psql/qsql_psql.cpp43
-rw-r--r--src/sql/kernel/qsqlquery.cpp1
3 files changed, 29 insertions, 27 deletions
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp
index d9b31c7702..9462df8f97 100644
--- a/src/sql/drivers/odbc/qsql_odbc.cpp
+++ b/src/sql/drivers/odbc/qsql_odbc.cpp
@@ -393,10 +393,20 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni
colSize*sizeof(SQLTCHAR),
&lengthIndicator);
if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
- if (lengthIndicator == SQL_NULL_DATA || lengthIndicator == SQL_NO_TOTAL) {
+ if (lengthIndicator == SQL_NULL_DATA) {
fieldVal.clear();
break;
}
+ // starting with ODBC Native Client 2012, SQL_NO_TOTAL is returned
+ // instead of the length (which sometimes was wrong in older versions)
+ // see link for more info: http://msdn.microsoft.com/en-us/library/jj219209.aspx
+ // if length indicator equals SQL_NO_TOTAL, indicating that
+ // more data can be fetched, but size not known, collect data
+ // and fetch next block
+ if (lengthIndicator == SQL_NO_TOTAL) {
+ fieldVal += fromSQLTCHAR(buf, colSize);
+ continue;
+ }
// if SQL_SUCCESS_WITH_INFO is returned, indicating that
// more data can be fetched, the length indicator does NOT
// contain the number of bytes returned - it contains the
diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp
index 52b96a5456..455e1f46ca 100644
--- a/src/sql/drivers/psql/qsql_psql.cpp
+++ b/src/sql/drivers/psql/qsql_psql.cpp
@@ -426,11 +426,8 @@ QVariant QPSQLResult::data(int i)
#ifndef QT_NO_DATESTRING
if (str.isEmpty())
return QVariant(QTime());
- if (str.at(str.length() - 3) == QLatin1Char('+') || str.at(str.length() - 3) == QLatin1Char('-'))
- // strip the timezone
- // TODO: fix this when timestamp support comes into QDateTime
- return QVariant(QTime::fromString(str.left(str.length() - 3), Qt::ISODate));
- return QVariant(QTime::fromString(str, Qt::ISODate));
+ else
+ return QVariant(QTime::fromString(str, Qt::ISODate));
#else
return QVariant(str);
#endif
@@ -438,19 +435,13 @@ QVariant QPSQLResult::data(int i)
case QVariant::DateTime: {
QString dtval = QString::fromLatin1(val);
#ifndef QT_NO_DATESTRING
- if (dtval.length() < 10)
- return QVariant(QDateTime());
- // remove the timezone
- // TODO: fix this when timestamp support comes into QDateTime
- if (dtval.at(dtval.length() - 3) == QLatin1Char('+') || dtval.at(dtval.length() - 3) == QLatin1Char('-'))
- dtval.chop(3);
- // milliseconds are sometimes returned with 2 digits only
- if (dtval.at(dtval.length() - 3).isPunct())
- dtval += QLatin1Char('0');
- if (dtval.isEmpty())
+ if (dtval.length() < 10) {
return QVariant(QDateTime());
- else
- return QVariant(QDateTime::fromString(dtval, Qt::ISODate));
+ } else {
+ QChar sign = dtval[dtval.size() - 3];
+ if (sign == QLatin1Char('-') || sign == QLatin1Char('+')) dtval += QLatin1String(":00");
+ return QVariant(QDateTime::fromString(dtval, Qt::ISODate).toLocalTime());
+ }
#else
return QVariant(dtval);
#endif
@@ -536,6 +527,11 @@ QSqlRecord QPSQLResult::record() const
int precision = PQfmod(d->result, i);
switch (ptype) {
+ case QTIMESTAMPOID:
+ case QTIMESTAMPTZOID:
+ precision = 3;
+ break;
+
case QNUMERICOID:
if (precision != -1) {
len = (precision >> 16);
@@ -1263,15 +1259,10 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const
case QVariant::DateTime:
#ifndef QT_NO_DATESTRING
if (field.value().toDateTime().isValid()) {
- QDate dt = field.value().toDateTime().date();
- QTime tm = field.value().toDateTime().time();
- // msecs need to be right aligned otherwise psql interprets them wrong
- r = QLatin1Char('\'') + QString::number(dt.year()) + QLatin1Char('-')
- + QString::number(dt.month()).rightJustified(2, QLatin1Char('0')) + QLatin1Char('-')
- + QString::number(dt.day()).rightJustified(2, QLatin1Char('0')) + QLatin1Char(' ')
- + tm.toString() + QLatin1Char('.')
- + QString::number(tm.msec()).rightJustified(3, QLatin1Char('0'))
- + QLatin1Char('\'');
+ // we force the value to be considered with a timezone information, and we force it to be UTC
+ // this is safe since postgresql stores only the UTC value and not the timezone offset (only used
+ // while parsing), so we have correct behavior in both case of with timezone and without tz
+ r = QLatin1String("TIMESTAMP WITH TIME ZONE ") + QLatin1Char('\'') + field.value().toDateTime().toUTC().toString(QLatin1String("yyyy-MM-ddThh:mm:ss.zzz")) + QLatin1Char('Z') + QLatin1Char('\'');
} else {
r = QLatin1String("NULL");
}
diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp
index 98e262a7e2..2808587d96 100644
--- a/src/sql/kernel/qsqlquery.cpp
+++ b/src/sql/kernel/qsqlquery.cpp
@@ -1060,6 +1060,7 @@ bool QSqlQuery::exec()
*/
bool QSqlQuery::execBatch(BatchExecutionMode mode)
{
+ d->sqlResult->resetBindCount();
return d->sqlResult->execBatch(mode == ValuesAsColumns);
}