summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2012-12-20 05:26:50 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-20 13:33:07 +0100
commitbc71836fc46b308b767af86a42ad5b6e01b78c1f (patch)
treeb7dd2abb86a934df19f23ba0d5ffa1ce099a8161 /src/sql
parent40474ceb11fd10a03c28ed3fa2836bcd2fd66929 (diff)
Use PG_VERSION if PG_MAJORVERSION is not defined
When only PG_VERSION was available for getting the client driver version for PostgreSQL it meant that it would not detect the client version and subsequently would not set the connection up correctly as a result. This fixes the blob test already in tst_qsqlquery. Change-Id: Ie2176a43b6be9c0e835498fca5aea129f0cc8fc6 Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/drivers/psql/qsql_psql.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp
index 8a0e2b86ea..5181d4f27a 100644
--- a/src/sql/drivers/psql/qsql_psql.cpp
+++ b/src/sql/drivers/psql/qsql_psql.cpp
@@ -695,25 +695,30 @@ QPSQLDriver::Protocol QPSQLDriverPrivate::getPSQLVersion()
int vMaj = rx.cap(1).toInt();
int vMin = rx.cap(2).toInt();
serverVersion = qMakePSQLVersion(vMaj, vMin);
-#ifdef PG_MAJORVERSION
- if (rx.indexIn(QLatin1String(PG_MAJORVERSION)) != -1) {
+#if defined(PG_MAJORVERSION)
+ if (rx.indexIn(QLatin1String(PG_MAJORVERSION)) != -1)
+#elif defined(PG_VERSION)
+ if (rx.indexIn(QLatin1String(PG_VERSION)) != -1)
+#else
+ if (0)
+#endif
+ {
vMaj = rx.cap(1).toInt();
vMin = rx.cap(2).toInt();
+ QPSQLDriver::Protocol clientVersion = qMakePSQLVersion(vMaj, vMin);
+
+ if (serverVersion >= QPSQLDriver::Version9 && clientVersion < QPSQLDriver::Version9) {
+ //Client version before QPSQLDriver::Version9 only supports escape mode for bytea type,
+ //but bytea format is set to hex by default in PSQL 9 and above. So need to force the
+ //server use the old escape mode when connects to the new server with old client library.
+ result = exec("SET bytea_output=escape; ");
+ status = PQresultStatus(result);
+ } else if (serverVersion == QPSQLDriver::VersionUnknown) {
+ serverVersion = clientVersion;
+ if (serverVersion != QPSQLDriver::VersionUnknown)
+ qWarning("The server version of this PostgreSQL is unknown, falling back to the client version.");
+ }
}
- QPSQLDriver::Protocol clientVersion = qMakePSQLVersion(vMaj, vMin);
-
- if (serverVersion >= QPSQLDriver::Version9 && clientVersion < QPSQLDriver::Version9) {
- //Client version before QPSQLDriver::Version9 only supports escape mode for bytea type,
- //but bytea format is set to hex by default in PSQL 9 and above. So need to force the
- //server use the old escape mode when connects to the new server with old client library.
- result = exec("SET bytea_output=escape; ");
- status = PQresultStatus(result);
- } else if (serverVersion == QPSQLDriver::VersionUnknown) {
- serverVersion = clientVersion;
- if (serverVersion != QPSQLDriver::VersionUnknown)
- qWarning("The server version of this PostgreSQL is unknown, falling back to the client version.");
- }
-#endif
}
}
PQclear(result);