summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerick Hawcroft <derick.hawcroft@nokia.com>2009-06-22 04:33:42 (GMT)
committerDerick Hawcroft <derick.hawcroft@nokia.com>2009-06-22 04:33:42 (GMT)
commit0a2fa1662cf482736e8c439596d5c057f58e1454 (patch)
tree2f0e2381082504625e6559dc8329a9db6851915a
parent3d0e9c521f4cdc788a7f2335a0d98a811638a9d1 (diff)
downloadQt-0a2fa1662cf482736e8c439596d5c057f58e1454.zip
Qt-0a2fa1662cf482736e8c439596d5c057f58e1454.tar.gz
Qt-0a2fa1662cf482736e8c439596d5c057f58e1454.tar.bz2
task 226042
Until the PostgreSQL API has this functionality. Use a hack to find out if a transaction has failed or not. This hack is a limited to 8.x versions of PostgreSQL. Bill King
-rw-r--r--src/sql/drivers/psql/qsql_psql.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp
index 13cdc01..ed9b98c 100644
--- a/src/sql/drivers/psql/qsql_psql.cpp
+++ b/src/sql/drivers/psql/qsql_psql.cpp
@@ -534,7 +534,7 @@ bool QPSQLResult::prepare(const QString &query)
{
if (!d->preparedQueriesEnabled)
return QSqlResult::prepare(query);
-
+
cleanup();
if (!d->preparedStmtId.isEmpty())
@@ -824,7 +824,20 @@ bool QPSQLDriver::commitTransaction()
return false;
}
PGresult* res = PQexec(d->connection, "COMMIT");
- if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
+
+ bool transaction_failed = false;
+
+ // XXX
+ // This hack is used to tell if the transaction has succeeded for the protocol versions of
+ // PostgreSQL below. For 7.x and other protocol versions we are left in the dark.
+ // This hack can dissapear once there is an API to query this sort of information.
+ if (d->pro == QPSQLDriver::Version8 ||
+ d->pro == QPSQLDriver::Version81 ||
+ d->pro == QPSQLDriver::Version82) {
+ transaction_failed = QByteArray(PQcmdStatus(res)) == QByteArray("ROLLBACK")?true:false;
+ }
+
+ if (!res || PQresultStatus(res) != PGRES_COMMAND_OK || transaction_failed) {
PQclear(res);
setLastError(qMakeError(tr("Could not commit transaction"),
QSqlError::TransactionError, d));
@@ -1172,12 +1185,12 @@ bool QPSQLDriver::subscribeToNotificationImplementation(const QString &name)
qPrintable(name));
return false;
}
-
+
int socket = PQsocket(d->connection);
if (socket) {
QString query = QString(QLatin1String("LISTEN %1")).arg(escapeIdentifier(name, QSqlDriver::TableName));
- if (PQresultStatus(PQexec(d->connection,
- d->isUtf8 ? query.toUtf8().constData()
+ if (PQresultStatus(PQexec(d->connection,
+ d->isUtf8 ? query.toUtf8().constData()
: query.toLocal8Bit().constData())
) != PGRES_COMMAND_OK) {
setLastError(qMakeError(tr("Unable to subscribe"), QSqlError::StatementError, d));
@@ -1208,8 +1221,8 @@ bool QPSQLDriver::unsubscribeFromNotificationImplementation(const QString &name)
}
QString query = QString(QLatin1String("UNLISTEN %1")).arg(escapeIdentifier(name, QSqlDriver::TableName));
- if (PQresultStatus(PQexec(d->connection,
- d->isUtf8 ? query.toUtf8().constData()
+ if (PQresultStatus(PQexec(d->connection,
+ d->isUtf8 ? query.toUtf8().constData()
: query.toLocal8Bit().constData())
) != PGRES_COMMAND_OK) {
setLastError(qMakeError(tr("Unable to unsubscribe"), QSqlError::StatementError, d));
@@ -1242,7 +1255,7 @@ void QPSQLDriver::_q_handleNotification(int)
if (d->seid.contains(name))
emit notification(name);
else
- qWarning("QPSQLDriver: received notification for '%s' which isn't subscribed to.",
+ qWarning("QPSQLDriver: received notification for '%s' which isn't subscribed to.",
qPrintable(name));
qPQfreemem(notify);