From 14170bbf09d2f1fee3cf2fd8a8087f7e913839b4 Mon Sep 17 00:00:00 2001 From: Marcel Krems Date: Tue, 12 Feb 2013 05:13:21 +0100 Subject: [PATCH] QSqlError: Set error code for psql-driver. Task-number: QTBUG-142 Change-Id: I4a68da595b7c8869188225958eaa88f789d4c3bf Reviewed-by: Mark Brand --- src/sql/drivers/psql/qsql_psql.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp index fd5990f3ee..c052e4c2e7 100644 --- a/src/sql/drivers/psql/qsql_psql.cpp +++ b/src/sql/drivers/psql/qsql_psql.cpp @@ -224,11 +224,12 @@ static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, { const char *s = PQerrorMessage(p->connection); QString msg = p->isUtf8 ? QString::fromUtf8(s) : QString::fromLocal8Bit(s); + QString errorCode; if (result) { - const char *sCode = PQresultErrorField(result, PG_DIAG_SQLSTATE); - msg += QString::fromLatin1("(%1)").arg(QString::fromLatin1(sCode)); + errorCode = QString::fromLatin1(PQresultErrorField(result, PG_DIAG_SQLSTATE)); + msg += QString::fromLatin1("(%1)").arg(errorCode); } - return QSqlError(QLatin1String("QPSQL: ") + err, msg, type); + return QSqlError(QLatin1String("QPSQL: ") + err, msg, type, errorCode); } bool QPSQLResultPrivate::processResults()