Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/sql/drivers/psql/qsql_psql.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5555#include <qmutex.h>
    5656
    57 
    5857#include <libpq-fe.h>
    5958#include <pg_config.h>
     
    620619}
    621620
     621static QPSQLDriver::Protocol qMakePSQLVersion(int vMaj, int vMin)
     622{
     623    switch (vMaj) {
     624    case 6:
     625        return QPSQLDriver::Version6;
     626    case 7:
     627    {
     628        switch (vMin) {
     629        case 1:
     630            return QPSQLDriver::Version71;
     631        case 3:
     632            return QPSQLDriver::Version73;
     633        case 4:
     634            return QPSQLDriver::Version74;
     635        default:
     636            return QPSQLDriver::Version7;
     637        }
     638        break;
     639    }
     640    case 8:
     641    {
     642        switch (vMin) {
     643        case 1:
     644            return QPSQLDriver::Version81;
     645        case 2:
     646            return QPSQLDriver::Version82;
     647        case 3:
     648            return QPSQLDriver::Version83;
     649        case 4:
     650            return QPSQLDriver::Version84;
     651        default:
     652            return QPSQLDriver::Version8;
     653        }
     654        break;
     655    }
     656    case 9:
     657        return QPSQLDriver::Version9;
     658        break;
     659    default:
     660        break;
     661    }
     662    return QPSQLDriver::VersionUnknown;
     663}
     664
    622665static QPSQLDriver::Protocol getPSQLVersion(PGconn* connection)
    623666{
     
    627670    if (status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK) {
    628671        QString val = QString::fromAscii(PQgetvalue(result, 0, 0));
     672
    629673        QRegExp rx(QLatin1String("(\\d+)\\.(\\d+)"));
    630674        rx.setMinimal(true); // enforce non-greedy RegExp
     675
    631676        if (rx.indexIn(val) != -1) {
    632677            int vMaj = rx.cap(1).toInt();
    633678            int vMin = rx.cap(2).toInt();
    634 
    635             switch (vMaj) {
    636             case 7:
    637                 switch (vMin) {
    638                 case 0:
    639                     serverVersion = QPSQLDriver::Version7;
    640                     break;
    641                 case 1:
    642                 case 2:
    643                     serverVersion = QPSQLDriver::Version71;
    644                     break;
    645                 default:
    646                     serverVersion = QPSQLDriver::Version73;
    647                     break;
    648                 }
    649                 break;
    650             case 8:
    651                 switch (vMin) {
    652                 case 0:
    653                     serverVersion = QPSQLDriver::Version8;
    654                     break;
    655                 case 1:
    656                     serverVersion = QPSQLDriver::Version81;
    657                     break;
    658                 case 2:
    659                 default:
    660                     serverVersion = QPSQLDriver::Version82;
    661                     break;
    662                 }
    663                 break;
    664             default:
    665                 break;
     679            serverVersion = qMakePSQLVersion(vMaj, vMin);
     680#ifdef PG_MAJORVERSION
     681            if (rx.indexIn(QLatin1String(PG_MAJORVERSION)) != -1) {
     682                vMaj = rx.cap(1).toInt();
     683                vMin = rx.cap(2).toInt();
    666684            }
     685            QPSQLDriver::Protocol clientVersion = qMakePSQLVersion(vMaj, vMin);
     686
     687            if (serverVersion >= QPSQLDriver::Version9 && clientVersion < QPSQLDriver::Version9) {
     688                //Client version before QPSQLDriver::Version9 only supports escape mode for bytea type,
     689                //but bytea format is set to hex by default in PSQL 9 and above. So need to force the
     690                //server use the old escape mode when connects to the new server with old client library.
     691                result = PQexec(connection, "SET bytea_output=escape; ");
     692                status = PQresultStatus(result);
     693            } else if (serverVersion == QPSQLDriver::VersionUnknown) {
     694                serverVersion = clientVersion;
     695                if (serverVersion != QPSQLDriver::VersionUnknown)
     696                   qWarning("The server version of this PostgreSQL is unknown, falling back to the client version.");
     697            }
     698#endif
    667699        }
    668700    }
    669701    PQclear(result);
    670702
    671     if (serverVersion < QPSQLDriver::Version71)
     703    //keep the old behavior unchanged
     704    if (serverVersion == QPSQLDriver::VersionUnknown)
     705        serverVersion = QPSQLDriver::Version6;
     706
     707    if (serverVersion < QPSQLDriver::Version71) {
    672708        qWarning("This version of PostgreSQL is not supported and may not work.");
     709    }
    673710
    674711    return serverVersion;
     
    853890    if (d->pro == QPSQLDriver::Version8 ||
    854891        d->pro == QPSQLDriver::Version81 ||
    855         d->pro == QPSQLDriver::Version82) {
     892        d->pro == QPSQLDriver::Version82 ||
     893        d->pro == QPSQLDriver::Version83 ||
     894        d->pro == QPSQLDriver::Version84 ||
     895        d->pro == QPSQLDriver::Version9) {
    856896        transaction_failed = qstrcmp(PQcmdStatus(res), "ROLLBACK") == 0;
    857897    }
     
    9641004    case QPSQLDriver::Version81:
    9651005    case QPSQLDriver::Version82:
     1006    case QPSQLDriver::Version83:
     1007    case QPSQLDriver::Version84:
     1008    case QPSQLDriver::Version9:
    9661009        stmt = QLatin1String("SELECT pg_attribute.attname, pg_attribute.atttypid::int, "
    9671010                "pg_class.relname "
     
    10471090    case QPSQLDriver::Version81:
    10481091    case QPSQLDriver::Version82:
     1092    case QPSQLDriver::Version83:
     1093    case QPSQLDriver::Version84:
     1094    case QPSQLDriver::Version9:
    10491095        stmt = QLatin1String("select pg_attribute.attname, pg_attribute.atttypid::int, "
    10501096                "pg_attribute.attnotnull, pg_attribute.attlen, pg_attribute.atttypmod, "
  • trunk/src/sql/drivers/psql/qsql_psql.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    9898public:
    9999    enum Protocol {
     100        VersionUnknown = -1,
    100101        Version6 = 6,
    101102        Version7 = 7,
     
    105106        Version8 = 11,
    106107        Version81 = 12,
    107         Version82 = 13
     108        Version82 = 13,
     109        Version83 = 14,
     110        Version84 = 15,
     111        Version9 = 16,
    108112    };
    109113
Note: See TracChangeset for help on using the changeset viewer.