Changeset 846 for trunk/src/sql/drivers/psql
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/sql/drivers/psql/qsql_psql.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 55 55 #include <qmutex.h> 56 56 57 58 57 #include <libpq-fe.h> 59 58 #include <pg_config.h> … … 620 619 } 621 620 621 static 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 622 665 static QPSQLDriver::Protocol getPSQLVersion(PGconn* connection) 623 666 { … … 627 670 if (status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK) { 628 671 QString val = QString::fromAscii(PQgetvalue(result, 0, 0)); 672 629 673 QRegExp rx(QLatin1String("(\\d+)\\.(\\d+)")); 630 674 rx.setMinimal(true); // enforce non-greedy RegExp 675 631 676 if (rx.indexIn(val) != -1) { 632 677 int vMaj = rx.cap(1).toInt(); 633 678 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(); 666 684 } 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 667 699 } 668 700 } 669 701 PQclear(result); 670 702 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) { 672 708 qWarning("This version of PostgreSQL is not supported and may not work."); 709 } 673 710 674 711 return serverVersion; … … 853 890 if (d->pro == QPSQLDriver::Version8 || 854 891 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) { 856 896 transaction_failed = qstrcmp(PQcmdStatus(res), "ROLLBACK") == 0; 857 897 } … … 964 1004 case QPSQLDriver::Version81: 965 1005 case QPSQLDriver::Version82: 1006 case QPSQLDriver::Version83: 1007 case QPSQLDriver::Version84: 1008 case QPSQLDriver::Version9: 966 1009 stmt = QLatin1String("SELECT pg_attribute.attname, pg_attribute.atttypid::int, " 967 1010 "pg_class.relname " … … 1047 1090 case QPSQLDriver::Version81: 1048 1091 case QPSQLDriver::Version82: 1092 case QPSQLDriver::Version83: 1093 case QPSQLDriver::Version84: 1094 case QPSQLDriver::Version9: 1049 1095 stmt = QLatin1String("select pg_attribute.attname, pg_attribute.atttypid::int, " 1050 1096 "pg_attribute.attnotnull, pg_attribute.attlen, pg_attribute.atttypmod, " -
trunk/src/sql/drivers/psql/qsql_psql.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 98 98 public: 99 99 enum Protocol { 100 VersionUnknown = -1, 100 101 Version6 = 6, 101 102 Version7 = 7, … … 105 106 Version8 = 11, 106 107 Version81 = 12, 107 Version82 = 13 108 Version82 = 13, 109 Version83 = 14, 110 Version84 = 15, 111 Version9 = 16, 108 112 }; 109 113
Note:
See TracChangeset
for help on using the changeset viewer.