Index: qt4-x11-4.4.3/src/sql/drivers/psql/qsql_psql.cpp
===================================================================
--- qt4-x11-4.4.3.orig/src/sql/drivers/psql/qsql_psql.cpp 2008-12-08 11:42:21.000000000 +0200
+++ qt4-x11-4.4.3/src/sql/drivers/psql/qsql_psql.cpp 2008-12-08 11:48:11.000000000 +0200
@@ -146,11 +146,28 @@
};
- const QPSQLDriverPrivate *p)
+ const QPSQLDriverPrivate *p,
+ const PGresult *res = 0)
{
const char *s = PQerrorMessage(p->connection);
+ int errnum = -1;
+ if (res) {
+ const char *sql_state_ = PQresultErrorField(res, PG_DIAG_SQLSTATE);
+ if (sql_state_) {
+ bool ok;
+ // PQresultErrorField returns 5-character error code,
+ // see the appendix A (titled `PostgreSQL Error Codes')
+ // of the PostgreSQL manual. On the other hand, Qt
+ // expects an integer.
+ static const int latin_base = 29;
+ // Error code contains arbitrary alphanumeric characters
+ errnum
= QString::fromAscii(sql_state_
).
toInt(&ok, latin_base
);
+ if (!ok)
+ errnum = -1;
+ }
+ }
}
bool QPSQLResultPrivate::processResults()
@@ -171,7 +188,7 @@
return true;
}
- "Unable to create query"),
QSqlError::StatementError, driver
));
+ "Unable to create query"),
QSqlError::StatementError, driver, result
));
return false;
}
@@ -543,6 +560,7 @@
: stmt.toLocal8Bit().constData());
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
+ // XXX: do we need to setNumber() here?
"Unable to prepare statement"),
QSqlError::StatementError, d
->driver
));
PQclear(result);
@@ -1173,6 +1191,7 @@
d->isUtf8 ? query.toUtf8().constData()
: query.toLocal8Bit().constData())
) != PGRES_COMMAND_OK) {
+ // XXX: do we need to setNumber() here?
setLastError
(qMakeError
(tr
("Unable to subscribe"),
QSqlError::StatementError, d
));
return false;
}
@@ -1205,6 +1224,7 @@
d->isUtf8 ? query.toUtf8().constData()
: query.toLocal8Bit().constData())
) != PGRES_COMMAND_OK) {
+ // XXX: do we need to setNumber() here?
setLastError
(qMakeError
(tr
("Unable to unsubscribe"),
QSqlError::StatementError, d
));
return false;
}
Index: qt4-x11-4.4.3/src/sql/drivers/psql/qsql_psql.cpp
===================================================================
--- qt4-x11-4.4.3.orig/src/sql/drivers/psql/qsql_psql.cpp 2008-12-08 11:42:21.000000000 +0200
+++ qt4-x11-4.4.3/src/sql/drivers/psql/qsql_psql.cpp 2008-12-08 11:48:11.000000000 +0200
@@ -146,11 +146,28 @@
};
static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type,
- const QPSQLDriverPrivate *p)
+ const QPSQLDriverPrivate *p,
+ const PGresult *res = 0)
{
const char *s = PQerrorMessage(p->connection);
+ int errnum = -1;
+ if (res) {
+ const char *sql_state_ = PQresultErrorField(res, PG_DIAG_SQLSTATE);
+ if (sql_state_) {
+ bool ok;
+ // PQresultErrorField returns 5-character error code,
+ // see the appendix A (titled `PostgreSQL Error Codes')
+ // of the PostgreSQL manual. On the other hand, Qt
+ // expects an integer.
+ static const int latin_base = 29;
+ // Error code contains arbitrary alphanumeric characters
+ errnum = QString::fromAscii(sql_state_).toInt(&ok, latin_base);
+ if (!ok)
+ errnum = -1;
+ }
+ }
QString msg = p->isUtf8 ? QString::fromUtf8(s) : QString::fromLocal8Bit(s);
- return QSqlError(QLatin1String("QPSQL: ") + err, msg, type);
+ return QSqlError(QLatin1String("QPSQL: ") + err, msg, type, errnum);
}
bool QPSQLResultPrivate::processResults()
@@ -171,7 +188,7 @@
return true;
}
q->setLastError(qMakeError(QCoreApplication::translate("QPSQLResult",
- "Unable to create query"), QSqlError::StatementError, driver));
+ "Unable to create query"), QSqlError::StatementError, driver, result));
return false;
}
@@ -543,6 +560,7 @@
: stmt.toLocal8Bit().constData());
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
+ // XXX: do we need to setNumber() here?
setLastError(qMakeError(QCoreApplication::translate("QPSQLResult",
"Unable to prepare statement"), QSqlError::StatementError, d->driver));
PQclear(result);
@@ -1173,6 +1191,7 @@
d->isUtf8 ? query.toUtf8().constData()
: query.toLocal8Bit().constData())
) != PGRES_COMMAND_OK) {
+ // XXX: do we need to setNumber() here?
setLastError(qMakeError(tr("Unable to subscribe"), QSqlError::StatementError, d));
return false;
}
@@ -1205,6 +1224,7 @@
d->isUtf8 ? query.toUtf8().constData()
: query.toLocal8Bit().constData())
) != PGRES_COMMAND_OK) {
+ // XXX: do we need to setNumber() here?
setLastError(qMakeError(tr("Unable to unsubscribe"), QSqlError::StatementError, d));
return false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks