summaryrefslogtreecommitdiffstats
path: root/src/plugins/sqldrivers/db2/qsql_db2.cpp
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2017-12-05 12:55:09 +0100
committerAndy Shaw <andy.shaw@qt.io>2018-01-02 08:51:06 +0000
commita899e454950e346709d233c7180ba4ce5aed34ec (patch)
tree83c025a0ecbe9c9f0fbdf2c166bf3b606cd7c7ee /src/plugins/sqldrivers/db2/qsql_db2.cpp
parentfa1397882ac322da376ad3bc1f2094334eb67e6e (diff)
DB2: Pass on the native error codes to QSqlError
Since DB2 can potentially have more than one error code, we need to join these together using ';' as a separator. Task-number: QTBUG-142 Change-Id: Idd376df84a8e3ae4c05b4722b4d0020fa4f3edad Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/plugins/sqldrivers/db2/qsql_db2.cpp')
-rw-r--r--src/plugins/sqldrivers/db2/qsql_db2.cpp57
1 files changed, 46 insertions, 11 deletions
diff --git a/src/plugins/sqldrivers/db2/qsql_db2.cpp b/src/plugins/sqldrivers/db2/qsql_db2.cpp
index b457ced538..1f98228f1b 100644
--- a/src/plugins/sqldrivers/db2/qsql_db2.cpp
+++ b/src/plugins/sqldrivers/db2/qsql_db2.cpp
@@ -156,7 +156,7 @@ static SQLTCHAR* qToTChar(const QString& str)
return (SQLTCHAR*)str.utf16();
}
-static QString qWarnDB2Handle(int handleType, SQLHANDLE handle)
+static QString qWarnDB2Handle(int handleType, SQLHANDLE handle, int *errorCode)
{
SQLINTEGER nativeCode;
SQLSMALLINT msgLen;
@@ -171,22 +171,51 @@ static QString qWarnDB2Handle(int handleType, SQLHANDLE handle)
(SQLTCHAR*) description,
SQL_MAX_MESSAGE_LENGTH - 1, /* in bytes, not in characters */
&msgLen);
- if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO)
+ if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
+ if (errorCode)
+ *errorCode = nativeCode;
return QString(qFromTChar(description));
+ }
return QString();
}
-static QString qDB2Warn(const QDB2DriverPrivate* d)
+static QString qDB2Warn(const QDB2DriverPrivate* d, QStringList *errorCodes = nullptr)
{
- return (qWarnDB2Handle(SQL_HANDLE_ENV, d->hEnv) + QLatin1Char(' ')
- + qWarnDB2Handle(SQL_HANDLE_DBC, d->hDbc));
+ int errorCode = 0;
+ QString error = qWarnDB2Handle(SQL_HANDLE_ENV, d->hEnv, &errorCode);
+ if (errorCodes && errorCode != 0) {
+ *errorCodes << QString::number(errorCode);
+ errorCode = 0;
+ }
+ if (!error.isEmpty())
+ error += QLatin1Char(' ');
+ error += qWarnDB2Handle(SQL_HANDLE_DBC, d->hDbc, &errorCode);
+ if (errorCodes && errorCode != 0)
+ *errorCodes << QString::number(errorCode);
+ return error;
}
-static QString qDB2Warn(const QDB2ResultPrivate* d)
+static QString qDB2Warn(const QDB2ResultPrivate* d, QStringList *errorCodes = nullptr)
{
- return (qWarnDB2Handle(SQL_HANDLE_ENV, d->drv_d_func()->hEnv) + QLatin1Char(' ')
- + qWarnDB2Handle(SQL_HANDLE_DBC, d->drv_d_func()->hDbc)
- + qWarnDB2Handle(SQL_HANDLE_STMT, d->hStmt));
+ int errorCode = 0;
+ QString error = qWarnDB2Handle(SQL_HANDLE_ENV, d->drv_d_func()->hEnv, &errorCode);
+ if (errorCodes && errorCode != 0) {
+ *errorCodes << QString::number(errorCode);
+ errorCode = 0;
+ }
+ if (!error.isEmpty())
+ error += QLatin1Char(' ');
+ error += qWarnDB2Handle(SQL_HANDLE_DBC, d->drv_d_func()->hDbc, &errorCode);
+ if (errorCodes && errorCode != 0) {
+ *errorCodes << QString::number(errorCode);
+ errorCode = 0;
+ }
+ if (!error.isEmpty())
+ error += QLatin1Char(' ');
+ error += qWarnDB2Handle(SQL_HANDLE_STMT, d->hStmt, &errorCode);
+ if (errorCodes && errorCode != 0)
+ *errorCodes << QString::number(errorCode);
+ return error;
}
static void qSqlWarning(const QString& message, const QDB2DriverPrivate* d)
@@ -204,13 +233,19 @@ static void qSqlWarning(const QString& message, const QDB2ResultPrivate* d)
static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type,
const QDB2DriverPrivate* p)
{
- return QSqlError(QLatin1String("QDB2: ") + err, qDB2Warn(p), type);
+ QStringList errorCodes;
+ const QString error = qDB2Warn(p, &errorCodes);
+ return QSqlError(QStringLiteral("QDB2: ") + err, error, type,
+ errorCodes.join(QLatin1Char(';')));
}
static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type,
const QDB2ResultPrivate* p)
{
- return QSqlError(QLatin1String("QDB2: ") + err, qDB2Warn(p), type);
+ QStringList errorCodes;
+ const QString error = qDB2Warn(p, &errorCodes);
+ return QSqlError(QStringLiteral("QDB2: ") + err, error, type,
+ errorCodes.join(QLatin1Char(';')));
}
static QVariant::Type qDecodeDB2Type(SQLSMALLINT sqltype)