Changeset 561 for trunk/src/sql/drivers/oci
- 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/oci/qsql_oci.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 ** … … 149 149 int serverVersion; 150 150 int prefetchRows, prefetchMem; 151 QSql::NumericalPrecisionPolicy precisionPolicy;152 151 153 152 void setCharset(OCIBind* hbnd); … … 406 405 ub4 prefetchRows; 407 406 ub2 prefetchMem; 408 QSql::NumericalPrecisionPolicy precisionPolicy;409 407 QString user; 410 408 … … 414 412 QOCIDriverPrivate::QOCIDriverPrivate() 415 413 : env(0), svc(0), srvhp(0), authp(0), err(0), transaction(false), serverVersion(-1), 416 prefetchRows(-1), prefetchMem(QOCI_PREFETCH_MEM) , precisionPolicy(QSql::HighPrecision)414 prefetchRows(-1), prefetchMem(QOCI_PREFETCH_MEM) 417 415 { 418 416 } … … 520 518 else if (ocitype == QLatin1String("LONG") || ocitype == QLatin1String("NCLOB") 521 519 || ocitype == QLatin1String("CLOB")) 522 type = QVariant:: ByteArray;520 type = QVariant::String; 523 521 else if (ocitype == QLatin1String("RAW") || ocitype == QLatin1String("LONG RAW") 524 522 || ocitype == QLatin1String("ROWID") || ocitype == QLatin1String("BLOB") … … 546 544 case SQLT_RDD: 547 545 case SQLT_LNG: 546 case SQLT_CLOB: 548 547 #ifdef SQLT_INTERVAL_YM 549 548 case SQLT_INTERVAL_YM: … … 587 586 case SQLT_REF: 588 587 case SQLT_RID: 589 case SQLT_CLOB:590 588 type = QVariant::ByteArray; 591 589 break; … … 612 610 f.setRequired(ofi.oraIsNull == 0); 613 611 614 if (ofi.type == QVariant::String )612 if (ofi.type == QVariant::String && ofi.oraType != SQLT_NUM && ofi.oraType != SQLT_VNU) 615 613 f.setLength(ofi.oraFieldLength); 616 614 else … … 621 619 return f; 622 620 } 623 624 static OraFieldInfo qMakeOraField(const QOCIResultPrivate* p, OCIParam* param)625 {626 OraFieldInfo ofi;627 ub2 colType(0);628 text *colName = 0;629 ub4 colNameLen(0);630 sb1 colScale(0);631 ub2 colLength(0);632 ub2 colFieldLength(0);633 sb2 colPrecision(0);634 ub1 colIsNull(0);635 int r(0);636 QVariant::Type type(QVariant::Invalid);637 638 r = OCIAttrGet(param,639 OCI_DTYPE_PARAM,640 &colType,641 0,642 OCI_ATTR_DATA_TYPE,643 p->err);644 if (r != 0)645 qOraWarning("qMakeOraField:", p->err);646 647 r = OCIAttrGet(param,648 OCI_DTYPE_PARAM,649 &colName,650 &colNameLen,651 OCI_ATTR_NAME,652 p->err);653 if (r != 0)654 qOraWarning("qMakeOraField:", p->err);655 656 r = OCIAttrGet(param,657 OCI_DTYPE_PARAM,658 &colLength,659 0,660 OCI_ATTR_DATA_SIZE, /* in bytes */661 p->err);662 if (r != 0)663 qOraWarning("qMakeOraField:", p->err);664 665 #ifdef OCI_ATTR_CHAR_SIZE666 r = OCIAttrGet(param,667 OCI_DTYPE_PARAM,668 &colFieldLength,669 0,670 OCI_ATTR_CHAR_SIZE,671 p->err);672 if (r != 0)673 qOraWarning("qMakeOraField:", p->err);674 #else675 // for Oracle8.676 colFieldLength = colLength;677 #endif678 679 r = OCIAttrGet(param,680 OCI_DTYPE_PARAM,681 &colPrecision,682 0,683 OCI_ATTR_PRECISION,684 p->err);685 if (r != 0)686 qOraWarning("qMakeOraField:", p->err);687 688 r = OCIAttrGet(param,689 OCI_DTYPE_PARAM,690 &colScale,691 0,692 OCI_ATTR_SCALE,693 p->err);694 if (r != 0)695 qOraWarning("qMakeOraField:", p->err);696 r = OCIAttrGet(param,697 OCI_DTYPE_PARAM,698 &colType,699 0,700 OCI_ATTR_DATA_TYPE,701 p->err);702 if (r != 0)703 qOraWarning("qMakeOraField:", p->err);704 r = OCIAttrGet(param,705 OCI_DTYPE_PARAM,706 &colIsNull,707 0,708 OCI_ATTR_IS_NULL,709 p->err);710 if (r != 0)711 qOraWarning("qMakeOraField:", p->err);712 713 type = qDecodeOCIType(colType, p->precisionPolicy);714 715 if (type == QVariant::Int) {716 if (colLength == 22 && colPrecision == 0 && colScale == 0)717 type = QVariant::String;718 if (colScale > 0)719 type = QVariant::String;720 }721 722 // bind as double if the precision policy asks for it723 if (((colType == SQLT_FLT) || (colType == SQLT_NUM))724 && (p->precisionPolicy == QSql::LowPrecisionDouble)) {725 type = QVariant::Double;726 }727 728 // bind as int32 or int64 if the precision policy asks for it729 if ((colType == SQLT_NUM) || (colType == SQLT_VNU) || (colType == SQLT_UIN)730 || (colType == SQLT_INT)) {731 if (p->precisionPolicy == QSql::LowPrecisionInt64)732 type = QVariant::LongLong;733 else if (p->precisionPolicy == QSql::LowPrecisionInt32)734 type = QVariant::Int;735 }736 737 if (colType == SQLT_BLOB)738 colLength = 0;739 740 // colNameLen is length in bytes741 ofi.name = QString(reinterpret_cast<const QChar*>(colName), colNameLen / 2);742 ofi.type = type;743 ofi.oraType = colType;744 ofi.oraFieldLength = colFieldLength;745 ofi.oraLength = colLength;746 ofi.oraScale = colScale;747 ofi.oraPrecision = colPrecision;748 ofi.oraIsNull = colIsNull;749 750 return ofi;751 }752 753 621 754 622 /*! … … 807 675 char* create(int position, int size); 808 676 OCILobLocator ** createLobLocator(int position, OCIEnv* env); 677 OraFieldInfo qMakeOraField(const QOCIResultPrivate* p, OCIParam* param) const; 809 678 810 679 class OraFieldInf … … 1138 1007 } 1139 1008 1009 OraFieldInfo QOCICols::qMakeOraField(const QOCIResultPrivate* p, OCIParam* param) const 1010 { 1011 OraFieldInfo ofi; 1012 ub2 colType(0); 1013 text *colName = 0; 1014 ub4 colNameLen(0); 1015 sb1 colScale(0); 1016 ub2 colLength(0); 1017 ub2 colFieldLength(0); 1018 sb2 colPrecision(0); 1019 ub1 colIsNull(0); 1020 int r(0); 1021 QVariant::Type type(QVariant::Invalid); 1022 1023 r = OCIAttrGet(param, 1024 OCI_DTYPE_PARAM, 1025 &colType, 1026 0, 1027 OCI_ATTR_DATA_TYPE, 1028 p->err); 1029 if (r != 0) 1030 qOraWarning("qMakeOraField:", p->err); 1031 1032 r = OCIAttrGet(param, 1033 OCI_DTYPE_PARAM, 1034 &colName, 1035 &colNameLen, 1036 OCI_ATTR_NAME, 1037 p->err); 1038 if (r != 0) 1039 qOraWarning("qMakeOraField:", p->err); 1040 1041 r = OCIAttrGet(param, 1042 OCI_DTYPE_PARAM, 1043 &colLength, 1044 0, 1045 OCI_ATTR_DATA_SIZE, /* in bytes */ 1046 p->err); 1047 if (r != 0) 1048 qOraWarning("qMakeOraField:", p->err); 1049 1050 #ifdef OCI_ATTR_CHAR_SIZE 1051 r = OCIAttrGet(param, 1052 OCI_DTYPE_PARAM, 1053 &colFieldLength, 1054 0, 1055 OCI_ATTR_CHAR_SIZE, 1056 p->err); 1057 if (r != 0) 1058 qOraWarning("qMakeOraField:", p->err); 1059 #else 1060 // for Oracle8. 1061 colFieldLength = colLength; 1062 #endif 1063 1064 r = OCIAttrGet(param, 1065 OCI_DTYPE_PARAM, 1066 &colPrecision, 1067 0, 1068 OCI_ATTR_PRECISION, 1069 p->err); 1070 if (r != 0) 1071 qOraWarning("qMakeOraField:", p->err); 1072 1073 r = OCIAttrGet(param, 1074 OCI_DTYPE_PARAM, 1075 &colScale, 1076 0, 1077 OCI_ATTR_SCALE, 1078 p->err); 1079 if (r != 0) 1080 qOraWarning("qMakeOraField:", p->err); 1081 r = OCIAttrGet(param, 1082 OCI_DTYPE_PARAM, 1083 &colType, 1084 0, 1085 OCI_ATTR_DATA_TYPE, 1086 p->err); 1087 if (r != 0) 1088 qOraWarning("qMakeOraField:", p->err); 1089 r = OCIAttrGet(param, 1090 OCI_DTYPE_PARAM, 1091 &colIsNull, 1092 0, 1093 OCI_ATTR_IS_NULL, 1094 p->err); 1095 if (r != 0) 1096 qOraWarning("qMakeOraField:", p->err); 1097 1098 type = qDecodeOCIType(colType, p->q->numericalPrecisionPolicy()); 1099 1100 if (type == QVariant::Int) { 1101 if (colLength == 22 && colPrecision == 0 && colScale == 0) 1102 type = QVariant::String; 1103 if (colScale > 0) 1104 type = QVariant::String; 1105 } 1106 1107 // bind as double if the precision policy asks for it 1108 if (((colType == SQLT_FLT) || (colType == SQLT_NUM)) 1109 && (p->q->numericalPrecisionPolicy() == QSql::LowPrecisionDouble)) { 1110 type = QVariant::Double; 1111 } 1112 1113 // bind as int32 or int64 if the precision policy asks for it 1114 if ((colType == SQLT_NUM) || (colType == SQLT_VNU) || (colType == SQLT_UIN) 1115 || (colType == SQLT_INT)) { 1116 if (p->q->numericalPrecisionPolicy() == QSql::LowPrecisionInt64) 1117 type = QVariant::LongLong; 1118 else if (p->q->numericalPrecisionPolicy() == QSql::LowPrecisionInt32) 1119 type = QVariant::Int; 1120 } 1121 1122 if (colType == SQLT_BLOB) 1123 colLength = 0; 1124 1125 // colNameLen is length in bytes 1126 ofi.name = QString(reinterpret_cast<const QChar*>(colName), colNameLen / 2); 1127 ofi.type = type; 1128 ofi.oraType = colType; 1129 ofi.oraFieldLength = colFieldLength; 1130 ofi.oraLength = colLength; 1131 ofi.oraScale = colScale; 1132 ofi.oraPrecision = colPrecision; 1133 ofi.oraIsNull = colIsNull; 1134 1135 return ofi; 1136 } 1137 1140 1138 struct QOCIBatchColumn 1141 1139 { … … 1260 1258 col.bindAs = SQLT_STR; 1261 1259 for (uint j = 0; j < col.recordCount; ++j) { 1262 uint len = boundValues.at(i).toList().at(j).toString().length() + 1; 1260 uint len; 1261 if(d->isOutValue(i)) 1262 len = boundValues.at(i).toList().at(j).toString().capacity() + 1; 1263 else 1264 len = boundValues.at(i).toList().at(j).toString().length() + 1; 1263 1265 if (len > col.maxLen) 1264 1266 col.maxLen = len; … … 1271 1273 col.bindAs = SQLT_LBI; 1272 1274 for (uint j = 0; j < col.recordCount; ++j) { 1273 col.lengths[j] = boundValues.at(i).toList().at(j).toByteArray().size(); 1275 if(d->isOutValue(i)) 1276 col.lengths[j] = boundValues.at(i).toList().at(j).toByteArray().capacity(); 1277 else 1278 col.lengths[j] = boundValues.at(i).toList().at(j).toByteArray().size(); 1274 1279 if (col.lengths[j] > col.maxLen) 1275 1280 col.maxLen = col.lengths[j]; … … 1581 1586 case QVariant::Int: 1582 1587 case QVariant::LongLong: 1583 if (d-> precisionPolicy!= QSql::HighPrecision) {1584 if ((d-> precisionPolicy== QSql::LowPrecisionDouble)1588 if (d->q->numericalPrecisionPolicy() != QSql::HighPrecision) { 1589 if ((d->q->numericalPrecisionPolicy() == QSql::LowPrecisionDouble) 1585 1590 && (fld.typ == QVariant::Double)) { 1586 1591 v[index + i] = *reinterpret_cast<double *>(fld.data); 1587 1592 break; 1588 } else if ((d-> precisionPolicy== QSql::LowPrecisionInt64)1593 } else if ((d->q->numericalPrecisionPolicy() == QSql::LowPrecisionInt64) 1589 1594 && (fld.typ == QVariant::LongLong)) { 1590 1595 qint64 qll = 0; 1591 OCINumberToInt(d->err, reinterpret_cast<OCINumber *>(fld.data), sizeof(qint64),1596 int r = OCINumberToInt(d->err, reinterpret_cast<OCINumber *>(fld.data), sizeof(qint64), 1592 1597 OCI_NUMBER_SIGNED, &qll); 1593 v[index + i] = qll; 1598 if(r == OCI_SUCCESS) 1599 v[index + i] = qll; 1600 else 1601 v[index + i] = QVariant(); 1594 1602 break; 1595 } else if ((d-> precisionPolicy== QSql::LowPrecisionInt32)1603 } else if ((d->q->numericalPrecisionPolicy() == QSql::LowPrecisionInt32) 1596 1604 && (fld.typ == QVariant::Int)) { 1597 1605 v[index + i] = *reinterpret_cast<int *>(fld.data); … … 1619 1627 : cols(0), q(result), env(driver->env), err(0), svc(const_cast<OCISvcCtx*&>(driver->svc)), 1620 1628 sql(0), transaction(driver->transaction), serverVersion(driver->serverVersion), 1621 prefetchRows(driver->prefetchRows), prefetchMem(driver->prefetchMem), 1622 precisionPolicy(driver->precisionPolicy) 1629 prefetchRows(driver->prefetchRows), prefetchMem(driver->prefetchMem) 1623 1630 { 1624 1631 int r = OCIHandleAlloc(env, … … 1790 1797 { 1791 1798 int r = 0; 1792 ub2 stmtType ;1799 ub2 stmtType=0; 1793 1800 ub4 iters; 1794 1801 ub4 mode; … … 1803 1810 OCI_ATTR_STMT_TYPE, 1804 1811 d->err); 1812 1813 if (r != OCI_SUCCESS && r != OCI_SUCCESS_WITH_INFO) { 1814 qOraWarning("QOCIResult::exec: Unable to get statement type:", d->err); 1815 setLastError(qMakeError(QCoreApplication::translate("QOCIResult", 1816 "Unable to get statement type"), QSqlError::StatementError, d->err)); 1817 #ifdef QOCI_DEBUG 1818 qDebug() << "lastQuery()" << lastQuery(); 1819 #endif 1820 return false; 1821 } 1805 1822 1806 1823 if (stmtType == OCI_STMT_SELECT) { … … 1892 1909 QOCICols::execBatch(d, boundValues(), *reinterpret_cast<bool *>(data)); 1893 1910 break; 1894 case QSqlResult::SetNumericalPrecision:1895 d->precisionPolicy = *reinterpret_cast<QSql::NumericalPrecisionPolicy *>(data);1896 break;1897 1911 default: 1898 QSql Result::virtual_hook(id, data);1912 QSqlCachedResult::virtual_hook(id, data); 1899 1913 } 1900 1914 } … … 2031 2045 if (!hostname.isEmpty()) 2032 2046 connectionString = 2033 QString(QLatin1String("(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=%1)(Port=%2))"2034 "(CONNECT_DATA=(SID=%3)))") ).arg(hostname).arg((port > -1 ? port : 1521)).arg(db);2047 QString::fromLatin1("(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=%1)(Port=%2))" 2048 "(CONNECT_DATA=(SID=%3)))").arg(hostname).arg((port > -1 ? port : 1521)).arg(db); 2035 2049 2036 2050 r = OCIHandleAlloc(d->env, reinterpret_cast<void **>(&d->srvhp), OCI_HTYPE_SERVER, 0, 0); … … 2099 2113 setOpen(true); 2100 2114 setOpenError(false); 2101 d->user = user .toUpper();2115 d->user = user; 2102 2116 2103 2117 return true; … … 2187 2201 { 2188 2202 QStringList tl; 2203 QStringList sysUsers = QStringList() << QLatin1String("MDSYS") 2204 << QLatin1String("LBACSYS") 2205 << QLatin1String("SYS") 2206 << QLatin1String("SYSTEM") 2207 << QLatin1String("WKSYS") 2208 << QLatin1String("CTXSYS") 2209 << QLatin1String("WMSYS"); 2210 2211 QString user = d->user; 2212 if ( isIdentifierEscaped(user, QSqlDriver::TableName)) 2213 user = stripDelimiters(user, QSqlDriver::TableName); 2214 else 2215 user = user.toUpper(); 2216 2217 if(sysUsers.contains(user)) 2218 sysUsers.removeAll(user);; 2219 2189 2220 if (!isOpen()) 2190 2221 return tl; … … 2193 2224 t.setForwardOnly(true); 2194 2225 if (type & QSql::Tables) { 2195 t.exec(QLatin1String("select owner, table_name from all_tables " 2196 "where owner != 'MDSYS' " 2197 "and owner != 'LBACSYS' " 2198 "and owner != 'SYS' " 2199 "and owner != 'SYSTEM' " 2200 "and owner != 'WKSYS'" 2201 "and owner != 'CTXSYS'" 2202 "and owner != 'WMSYS'")); 2226 QString query = QLatin1String("select owner, table_name from all_tables where "); 2227 QStringList whereList; 2228 foreach(const QString &sysUserName, sysUsers) 2229 whereList << QLatin1String("owner != '") + sysUserName + QLatin1String("' "); 2230 t.exec(query + whereList.join(QLatin1String(" and "))); 2231 2232 while (t.next()) { 2233 if (t.value(0).toString().toUpper() != user.toUpper()) 2234 tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString()); 2235 else 2236 tl.append(t.value(1).toString()); 2237 } 2238 2239 // list all table synonyms as well 2240 query = QLatin1String("select owner, synonym_name from all_synonyms where "); 2241 t.exec(query + whereList.join(QLatin1String(" and "))); 2242 while (t.next()) { 2243 if (t.value(0).toString() != d->user) 2244 tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString()); 2245 else 2246 tl.append(t.value(1).toString()); 2247 } 2248 } 2249 if (type & QSql::Views) { 2250 QString query = QLatin1String("select owner, view_name from all_views where "); 2251 QStringList whereList; 2252 foreach(const QString &sysUserName, sysUsers) 2253 whereList << QLatin1String("owner != '") + sysUserName + QLatin1String("' "); 2254 t.exec(query + whereList.join(QLatin1String(" and "))); 2255 while (t.next()) { 2256 if (t.value(0).toString().toUpper() != d->user.toUpper()) 2257 tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString()); 2258 else 2259 tl.append(t.value(1).toString()); 2260 } 2261 } 2262 if (type & QSql::SystemTables) { 2263 t.exec(QLatin1String("select table_name from dictionary")); 2264 while (t.next()) { 2265 tl.append(t.value(0).toString()); 2266 } 2267 QString query = QLatin1String("select owner, table_name from all_tables where "); 2268 QStringList whereList; 2269 foreach(const QString &sysUserName, sysUsers) 2270 whereList << QLatin1String("owner = '") + sysUserName + QLatin1String("' "); 2271 t.exec(query + whereList.join(QLatin1String(" or "))); 2272 2273 while (t.next()) { 2274 if (t.value(0).toString().toUpper() != user.toUpper()) 2275 tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString()); 2276 else 2277 tl.append(t.value(1).toString()); 2278 } 2279 2280 // list all table synonyms as well 2281 query = QLatin1String("select owner, synonym_name from all_synonyms where "); 2282 t.exec(query + whereList.join(QLatin1String(" or "))); 2203 2283 while (t.next()) { 2204 2284 if (t.value(0).toString() != d->user) … … 2208 2288 } 2209 2289 } 2210 if (type & QSql::Views) {2211 t.exec(QLatin1String("select owner, view_name from all_views "2212 "where owner != 'MDSYS' "2213 "and owner != 'LBACSYS' "2214 "and owner != 'SYS' "2215 "and owner != 'SYSTEM' "2216 "and owner != 'WKSYS'"2217 "and owner != 'CTXSYS'"2218 "and owner != 'WMSYS'"));2219 while (t.next()) {2220 if (t.value(0).toString() != d->user)2221 tl.append(t.value(0).toString() + QLatin1String(".") + t.value(1).toString());2222 else2223 tl.append(t.value(1).toString());2224 }2225 }2226 if (type & QSql::SystemTables) {2227 t.exec(QLatin1String("select table_name from dictionary"));2228 while (t.next()) {2229 tl.append(t.value(0).toString());2230 }2231 }2232 2290 return tl; 2233 2291 } … … 2238 2296 int i = tname.indexOf(QLatin1Char('.')); // prefixed with owner? 2239 2297 if (i != -1) { 2240 *tbl = tname.right(tname.length() - i - 1) .toUpper();2241 *owner = tname.left(i) .toUpper();2298 *tbl = tname.right(tname.length() - i - 1); 2299 *owner = tname.left(i); 2242 2300 } else { 2243 *tbl = tname .toUpper();2301 *tbl = tname; 2244 2302 } 2245 2303 } … … 2256 2314 QString stmt(QLatin1String("select column_name, data_type, data_length, " 2257 2315 "data_precision, data_scale, nullable, data_default%1" 2258 "from all_tab_columns "2259 "where upper(table_name)=%2"));2316 "from all_tab_columns a " 2317 "where a.table_name=%2")); 2260 2318 if (d->serverVersion >= 9) 2261 2319 stmt = stmt.arg(QLatin1String(", char_length ")); … … 2265 2323 QString table, owner, tmpStmt; 2266 2324 qSplitTableAndOwner(tablename, &table, &owner); 2325 2326 if (isIdentifierEscaped(table, QSqlDriver::TableName)) 2327 table = stripDelimiters(table, QSqlDriver::TableName); 2328 else 2329 table = table.toUpper(); 2330 2267 2331 tmpStmt = stmt.arg(QLatin1Char('\'') + table + QLatin1Char('\'')); 2268 2332 if (owner.isEmpty()) { 2269 2333 owner = d->user; 2270 2334 } 2271 tmpStmt += QLatin1String(" and upper(owner)='") + owner + QLatin1String("'"); 2335 2336 if (isIdentifierEscaped(owner, QSqlDriver::TableName)) 2337 owner = stripDelimiters(owner, QSqlDriver::TableName); 2338 else 2339 owner = owner.toUpper(); 2340 2341 tmpStmt += QLatin1String(" and a.owner='") + owner + QLatin1Char('\''); 2272 2342 t.setForwardOnly(true); 2273 2343 t.exec(tmpStmt); 2274 2344 if (!t.next()) { // try and see if the tablename is a synonym 2275 stmt= stmt.arg(QLatin1String("(select tname from sys.synonyms where sname='") 2276 + table + QLatin1String("' and creator=owner)")); 2345 stmt = stmt + QLatin1String(" join all_synonyms b " 2346 "on a.owner=b.table_owner and a.table_name=b.table_name " 2347 "where b.owner='") + owner + 2348 QLatin1String("' and b.synonym_name='") + table + 2349 QLatin1Char('\''); 2277 2350 t.setForwardOnly(true); 2278 2351 t.exec(stmt); … … 2286 2359 if (buildRecordInfo) { 2287 2360 do { 2288 QVariant::Type ty = qDecodeOCIType(t.value(1).toString(), t.numericalPrecisionPolicy());2361 QVariant::Type ty = qDecodeOCIType(t.value(1).toString(), t.numericalPrecisionPolicy()); 2289 2362 QSqlField f(t.value(0).toString(), ty); 2290 2363 f.setRequired(t.value(5).toString() == QLatin1String("N")); … … 2318 2391 QString table, owner, tmpStmt; 2319 2392 qSplitTableAndOwner(tablename, &table, &owner); 2320 tmpStmt = stmt + QLatin1String(" and upper(a.table_name)='") + table + QLatin1String("'"); 2393 2394 if (isIdentifierEscaped(table, QSqlDriver::TableName)) 2395 table = stripDelimiters(table, QSqlDriver::TableName); 2396 else 2397 table = table.toUpper(); 2398 2399 tmpStmt = stmt + QLatin1String(" and a.table_name='") + table + QLatin1Char('\''); 2321 2400 if (owner.isEmpty()) { 2322 2401 owner = d->user; 2323 2402 } 2324 tmpStmt += QLatin1String(" and upper(a.owner)='") + owner + QLatin1String("'"); 2403 2404 if (isIdentifierEscaped(owner, QSqlDriver::TableName)) 2405 owner = stripDelimiters(owner, QSqlDriver::TableName); 2406 else 2407 owner = owner.toUpper(); 2408 2409 tmpStmt += QLatin1String(" and a.owner='") + owner + QLatin1Char('\''); 2325 2410 t.setForwardOnly(true); 2326 2411 t.exec(tmpStmt); … … 2346 2431 t.value(2).toString() + QLatin1String("' and column_name='") + 2347 2432 t.value(0).toString() + QLatin1String("' and owner='") + 2348 owner + QLatin1String("'"));2433 owner + QLatin1Char('\'')); 2349 2434 if (!tt.next()) { 2350 2435 return QSqlIndex(); … … 2416 2501 } 2417 2502 2418 QString QOCIDriver::escapeIdentifier(const QString &identifier, IdentifierType /* type */) const2503 QString QOCIDriver::escapeIdentifier(const QString &identifier, IdentifierType type) const 2419 2504 { 2420 2505 QString res = identifier; 2421 res.replace(QLatin1Char('"'), QLatin1String("\"\""));2422 if (identifier.indexOf(QLatin1Char(' ')) != -1)2506 if(!identifier.isEmpty() && !isIdentifierEscaped(identifier, type)) { 2507 res.replace(QLatin1Char('"'), QLatin1String("\"\"")); 2423 2508 res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); 2424 // res.replace(QLatin1Char('.'), QLatin1String("\".\"")); 2509 res.replace(QLatin1Char('.'), QLatin1String("\".\"")); 2510 } 2425 2511 return res; 2426 2512 } -
trunk/src/sql/drivers/oci/qsql_oci.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.