Changeset 561 for trunk/src/sql/drivers/db2
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/sql/drivers/db2/qsql_db2.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtSql module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 50 50 #include <qvarlengtharray.h> 51 51 #include <qvector.h> 52 53 #ifndef UNICODE 54 #define UNICODE 55 #endif 52 #include <QDebug> 56 53 57 54 #if defined(Q_CC_BOR) … … 63 60 #endif 64 61 62 #define UNICODE 63 65 64 #include <sqlcli1.h> 66 65 … … 84 83 { 85 84 public: 86 QDB2ResultPrivate(const QDB2DriverPrivate* d): dp(d), hStmt(0) , precisionPolicy(QSql::HighPrecision)85 QDB2ResultPrivate(const QDB2DriverPrivate* d): dp(d), hStmt(0) 87 86 {} 88 87 ~QDB2ResultPrivate() 89 88 { 90 for (int i = 0; i < valueCache.count(); ++i) 89 emptyValueCache(); 90 } 91 void clearValueCache() 92 { 93 for (int i = 0; i < valueCache.count(); ++i) { 91 94 delete valueCache[i]; 95 valueCache[i] = NULL; 96 } 97 } 98 void emptyValueCache() 99 { 100 clearValueCache(); 101 valueCache.clear(); 92 102 } 93 103 … … 96 106 QSqlRecord recInf; 97 107 QVector<QVariant*> valueCache; 98 QSql::NumericalPrecisionPolicy precisionPolicy;99 108 }; 100 109 101 110 static QString qFromTChar(SQLTCHAR* str) 102 111 { 103 #ifdef UNICODE104 112 return QString::fromUtf16(str); 105 #else106 return QString::fromLocal8Bit((const char*) str);107 #endif108 113 } 109 114 … … 112 117 static SQLTCHAR* qToTChar(const QString& str) 113 118 { 114 #ifdef UNICODE115 119 return (SQLTCHAR*)str.utf16(); 116 #else117 return (unsigned char*) str.ascii();118 #endif119 120 } 120 121 … … 337 338 while (true) { 338 339 r = SQLGetData(hStmt, 339 column+1, 340 #ifdef UNICODE 340 column + 1, 341 341 SQL_C_WCHAR, 342 #else343 SQL_C_CHAR,344 #endif345 342 (SQLPOINTER)buf, 346 343 colSize * sizeof(SQLTCHAR), … … 545 542 546 543 d->recInf.clear(); 547 d-> valueCache.clear();544 d->emptyValueCache(); 548 545 549 546 if (!qMakeStatement(d, isForwardOnly())) … … 569 566 } 570 567 d->valueCache.resize(count); 568 d->valueCache.fill(NULL); 571 569 setActive(true); 572 570 return true; … … 580 578 581 579 d->recInf.clear(); 582 d-> valueCache.clear();580 d->emptyValueCache(); 583 581 584 582 if (!qMakeStatement(d, isForwardOnly())) … … 608 606 609 607 d->recInf.clear(); 610 d-> valueCache.clear();608 d->emptyValueCache(); 611 609 612 610 if (!qMakeStatement(d, isForwardOnly(), false)) … … 729 727 break; } 730 728 case QVariant::String: 731 #ifdef UNICODE732 729 { 733 730 QString str(values.at(i).toString()); … … 763 760 break; 764 761 } 765 #endif766 // fall through767 762 default: { 768 763 QByteArray ba = values.at(i).toString().toAscii(); … … 812 807 setActive(true); 813 808 d->valueCache.resize(count); 809 d->valueCache.fill(NULL); 814 810 815 811 //get out parameters … … 837 833 break; 838 834 case QVariant::String: 839 #ifdef UNICODE840 835 if (bindValueType(i) & QSql::Out) 841 836 values[i] = QString::fromUtf16((ushort*)tmpStorage.takeFirst().constData()); 842 837 break; 843 #endif844 // fall through845 838 default: { 846 839 values[i] = QString::fromAscii(tmpStorage.takeFirst().constData()); … … 859 852 if (i == at()) 860 853 return true; 861 d-> valueCache.fill(0);854 d->clearValueCache(); 862 855 int actualIdx = i + 1; 863 856 if (actualIdx <= 0) { … … 876 869 actualIdx); 877 870 } 878 if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO ) {871 if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO && r != SQL_NO_DATA) { 879 872 setLastError(qMakeError(QCoreApplication::translate("QDB2Result", 880 873 "Unable to fetch record %1").arg(i), QSqlError::StatementError, d)); 881 874 return false; 882 875 } 876 else if (r == SQL_NO_DATA) 877 return false; 883 878 setAt(i); 884 879 return true; … … 888 883 { 889 884 SQLRETURN r; 890 d-> valueCache.fill(0);885 d->clearValueCache(); 891 886 r = SQLFetchScroll(d->hStmt, 892 887 SQL_FETCH_NEXT, … … 908 903 if (isForwardOnly()) 909 904 return fetchNext(); 910 d-> valueCache.fill(0);905 d->clearValueCache(); 911 906 SQLRETURN r; 912 907 r = SQLFetchScroll(d->hStmt, … … 914 909 0); 915 910 if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) { 916 setLastError(qMakeError(QCoreApplication::translate("QDB2Result", "Unable to fetch first"), 917 QSqlError::StatementError, d)); 911 if(r!= SQL_NO_DATA) 912 setLastError(qMakeError(QCoreApplication::translate("QDB2Result", "Unable to fetch first"), 913 QSqlError::StatementError, d)); 918 914 return false; 919 915 } … … 924 920 bool QDB2Result::fetchLast() 925 921 { 926 d-> valueCache.fill(0);922 d->clearValueCache(); 927 923 928 924 int i = at(); … … 1030 1026 case QVariant::Double: 1031 1027 { 1032 QString value=qGetStringData(d->hStmt, field, info.length() + 1, isNull); 1033 bool ok=false; 1034 switch(d->precisionPolicy) { 1028 switch(numericalPrecisionPolicy()) { 1035 1029 case QSql::LowPrecisionInt32: 1036 v = new QVariant( value.toInt(&ok));1030 v = new QVariant(qGetIntData(d->hStmt, field, isNull)); 1037 1031 break; 1038 1032 case QSql::LowPrecisionInt64: 1039 v = new QVariant( value.toLongLong(&ok));1033 v = new QVariant(qGetBigIntData(d->hStmt, field, isNull)); 1040 1034 break; 1041 1035 case QSql::LowPrecisionDouble: 1042 v = new QVariant( value.toDouble(&ok));1036 v = new QVariant(qGetDoubleData(d->hStmt, field, isNull)); 1043 1037 break; 1044 1038 case QSql::HighPrecision: … … 1046 1040 // length + 1 for the comma 1047 1041 v = new QVariant(qGetStringData(d->hStmt, field, info.length() + 1, isNull)); 1048 ok = true;1049 1042 break; 1050 1043 } 1051 if(!ok)1052 v = new QVariant();1053 1044 break; 1054 1045 } … … 1102 1093 setAt(QSql::BeforeFirstRow); 1103 1094 d->recInf.clear(); 1104 d-> valueCache.clear();1095 d->emptyValueCache(); 1105 1096 setSelect(false); 1106 1097 … … 1121 1112 1122 1113 d->valueCache.resize(fieldCount); 1114 d->valueCache.fill(NULL); 1123 1115 setActive(true); 1124 1116 … … 1133 1125 *static_cast<bool*>(data) = nextResult(); 1134 1126 break; 1135 case QSqlResult:: SetNumericalPrecision:1136 Q_ASSERT(data);1137 d->precisionPolicy = *reinterpret_cast<QSql::NumericalPrecisionPolicy *>(data);1127 case QSqlResult::DetachFromResultSet: 1128 if (d->hStmt) 1129 SQLCloseCursor(d->hStmt); 1138 1130 break; 1139 1131 default: … … 1168 1160 } 1169 1161 1170 bool QDB2Driver::open(const QString& db, const QString& user, const QString& password, const QString& , int,1162 bool QDB2Driver::open(const QString& db, const QString& user, const QString& password, const QString& host, int port, 1171 1163 const QString& connOpts) 1172 1164 { … … 1191 1183 return false; 1192 1184 } 1185 1186 QString protocol; 1193 1187 // Set connection attributes 1194 1188 const QStringList opts(connOpts.split(QLatin1Char(';'), QString::SkipEmptyParts)); … … 1221 1215 v = val.toUInt(); 1222 1216 r = SQLSetConnectAttr(d->hDbc, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER) v, 0); 1223 } else { 1217 } else if (opt.compare(QLatin1String("PROTOCOL"), Qt::CaseInsensitive) == 0) { 1218 protocol = tmp; 1219 } 1220 else { 1224 1221 qWarning("QDB2Driver::open: Unknown connection attribute '%s'", 1225 1222 tmp.toLocal8Bit().constData()); … … 1230 1227 } 1231 1228 1229 if (protocol.isEmpty()) 1230 protocol = QLatin1String("PROTOCOL=TCPIP"); 1231 1232 if (port < 0 ) 1233 port = 50000; 1234 1232 1235 QString connQStr; 1233 connQStr = QLatin1String("DSN=") + db + QLatin1String(";UID=") + user + QLatin1String(";PWD=") 1234 + password; 1236 connQStr = protocol + QLatin1String(";DATABASE=") + db + QLatin1String(";HOSTNAME=") + host 1237 + QLatin1String(";PORT=") + QString::number(port) + QLatin1String(";UID=") + user 1238 + QLatin1String(";PWD=") + password; 1239 1240 1235 1241 SQLTCHAR connOut[SQL_MAX_OPTION_STRING_LENGTH]; 1236 1242 SQLSMALLINT cb; … … 1251 1257 } 1252 1258 1253 d->user = user .toUpper();1259 d->user = user; 1254 1260 setOpen(true); 1255 1261 setOpenError(false); … … 1296 1302 SQLHANDLE hStmt; 1297 1303 QString catalog, schema, table; 1298 qSplitTableQualifier(tableName .toUpper(), &catalog, &schema, &table);1304 qSplitTableQualifier(tableName, &catalog, &schema, &table); 1299 1305 if (schema.isEmpty()) 1300 1306 schema = d->user; 1307 1308 if (isIdentifierEscaped(catalog, QSqlDriver::TableName)) 1309 catalog = stripDelimiters(catalog, QSqlDriver::TableName); 1310 else 1311 catalog = catalog.toUpper(); 1312 1313 if (isIdentifierEscaped(schema, QSqlDriver::TableName)) 1314 schema = stripDelimiters(schema, QSqlDriver::TableName); 1315 else 1316 schema = schema.toUpper(); 1317 1318 if (isIdentifierEscaped(table, QSqlDriver::TableName)) 1319 table = stripDelimiters(table, QSqlDriver::TableName); 1320 else 1321 table = table.toUpper(); 1301 1322 1302 1323 SQLRETURN r = SQLAllocHandle(SQL_HANDLE_STMT, … … 1313 1334 SQL_IS_UINTEGER); 1314 1335 1336 1337 //Aside: szSchemaName and szTableName parameters of SQLColumns 1338 //are case sensitive search patterns, so no escaping is used. 1315 1339 r = SQLColumns(hStmt, 1316 1340 NULL, … … 1393 1417 QString fieldVal = qGetStringData(hStmt, 2, -1, isNull); 1394 1418 QString userVal = qGetStringData(hStmt, 1, -1, isNull); 1395 if (userVal != d->user) 1419 QString user = d->user; 1420 if ( isIdentifierEscaped(user, QSqlDriver::TableName)) 1421 user = stripDelimiters(user, QSqlDriver::TableName); 1422 else 1423 user = user.toUpper(); 1424 1425 if (userVal != user) 1396 1426 fieldVal = userVal + QLatin1Char('.') + fieldVal; 1397 1427 tl.append(fieldVal); … … 1424 1454 } 1425 1455 QString catalog, schema, table; 1426 qSplitTableQualifier(tablename.toUpper(), &catalog, &schema, &table); 1456 qSplitTableQualifier(tablename, &catalog, &schema, &table); 1457 1458 if (isIdentifierEscaped(catalog, QSqlDriver::TableName)) 1459 catalog = stripDelimiters(catalog, QSqlDriver::TableName); 1460 else 1461 catalog = catalog.toUpper(); 1462 1463 if (isIdentifierEscaped(schema, QSqlDriver::TableName)) 1464 schema = stripDelimiters(schema, QSqlDriver::TableName); 1465 else 1466 schema = schema.toUpper(); 1467 1468 if (isIdentifierEscaped(table, QSqlDriver::TableName)) 1469 table = stripDelimiters(table, QSqlDriver::TableName); 1470 else 1471 table = table.toUpper(); 1472 1427 1473 r = SQLSetStmtAttr(hStmt, 1428 1474 SQL_ATTR_CURSOR_TYPE, … … 1468 1514 case LastInsertId: 1469 1515 case SimpleLocking: 1470 case LowPrecisionNumbers:1471 1516 case EventNotifications: 1472 1517 return false; … … 1476 1521 case PreparedQueries: 1477 1522 case PositionalPlaceholders: 1523 case LowPrecisionNumbers: 1524 case FinishQuery: 1478 1525 return true; 1479 1526 case Unicode: 1480 // this is the query that shows the codepage for the types:1481 // select typename, codepage from syscat.datatypes1482 #ifdef UNICODE1483 1527 return true; 1484 #else1485 return false;1486 #endif1487 1528 } 1488 1529 return false; … … 1598 1639 { 1599 1640 QString res = identifier; 1600 if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) {1641 if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) { 1601 1642 res.replace(QLatin1Char('"'), QLatin1String("\"\"")); 1602 1643 res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); -
trunk/src/sql/drivers/db2/qsql_db2.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtSql module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 **
Note:
See TracChangeset
for help on using the changeset viewer.