Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/sql/drivers/oci/qsql_oci.cpp

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtSql module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    149149    int serverVersion;
    150150    int prefetchRows, prefetchMem;
    151     QSql::NumericalPrecisionPolicy precisionPolicy;
    152151
    153152    void setCharset(OCIBind* hbnd);
     
    406405    ub4 prefetchRows;
    407406    ub2 prefetchMem;
    408     QSql::NumericalPrecisionPolicy precisionPolicy;
    409407    QString user;
    410408
     
    414412QOCIDriverPrivate::QOCIDriverPrivate()
    415413    : 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)
    417415{
    418416}
     
    520518    else if (ocitype == QLatin1String("LONG") || ocitype == QLatin1String("NCLOB")
    521519             || ocitype == QLatin1String("CLOB"))
    522         type = QVariant::ByteArray;
     520        type = QVariant::String;
    523521    else if (ocitype == QLatin1String("RAW") || ocitype == QLatin1String("LONG RAW")
    524522             || ocitype == QLatin1String("ROWID") || ocitype == QLatin1String("BLOB")
     
    546544    case SQLT_RDD:
    547545    case SQLT_LNG:
     546    case SQLT_CLOB:
    548547#ifdef SQLT_INTERVAL_YM
    549548    case SQLT_INTERVAL_YM:
     
    587586    case SQLT_REF:
    588587    case SQLT_RID:
    589     case SQLT_CLOB:
    590588        type = QVariant::ByteArray;
    591589        break;
     
    612610    f.setRequired(ofi.oraIsNull == 0);
    613611
    614     if (ofi.type == QVariant::String)
     612    if (ofi.type == QVariant::String && ofi.oraType != SQLT_NUM && ofi.oraType != SQLT_VNU)
    615613        f.setLength(ofi.oraFieldLength);
    616614    else
     
    621619    return f;
    622620}
    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_SIZE
    666     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 #else
    675     // for Oracle8.
    676     colFieldLength = colLength;
    677 #endif
    678 
    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 it
    723     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 it
    729     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 bytes
    741     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 
    753621
    754622/*!
     
    807675    char* create(int position, int size);
    808676    OCILobLocator ** createLobLocator(int position, OCIEnv* env);
     677    OraFieldInfo qMakeOraField(const QOCIResultPrivate* p, OCIParam* param) const;
    809678
    810679    class OraFieldInf
     
    11381007}
    11391008
     1009OraFieldInfo 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
    11401138struct QOCIBatchColumn
    11411139{
     
    12601258                col.bindAs = SQLT_STR;
    12611259                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;
    12631265                    if (len > col.maxLen)
    12641266                        col.maxLen = len;
     
    12711273                col.bindAs = SQLT_LBI;
    12721274                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();
    12741279                    if (col.lengths[j] > col.maxLen)
    12751280                        col.maxLen = col.lengths[j];
     
    15811586        case QVariant::Int:
    15821587        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)
    15851590                        && (fld.typ == QVariant::Double)) {
    15861591                    v[index + i] = *reinterpret_cast<double *>(fld.data);
    15871592                    break;
    1588                 } else if ((d->precisionPolicy == QSql::LowPrecisionInt64)
     1593                } else if ((d->q->numericalPrecisionPolicy() == QSql::LowPrecisionInt64)
    15891594                        && (fld.typ == QVariant::LongLong)) {
    15901595                    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),
    15921597                                   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();
    15941602                    break;
    1595                 } else if ((d->precisionPolicy == QSql::LowPrecisionInt32)
     1603                } else if ((d->q->numericalPrecisionPolicy() == QSql::LowPrecisionInt32)
    15961604                        && (fld.typ == QVariant::Int)) {
    15971605                    v[index + i] = *reinterpret_cast<int *>(fld.data);
     
    16191627    : cols(0), q(result), env(driver->env), err(0), svc(const_cast<OCISvcCtx*&>(driver->svc)),
    16201628      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)
    16231630{
    16241631    int r = OCIHandleAlloc(env,
     
    17901797{
    17911798    int r = 0;
    1792     ub2 stmtType;
     1799    ub2 stmtType=0;
    17931800    ub4 iters;
    17941801    ub4 mode;
     
    18031810                    OCI_ATTR_STMT_TYPE,
    18041811                    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    }
    18051822
    18061823    if (stmtType == OCI_STMT_SELECT) {
     
    18921909        QOCICols::execBatch(d, boundValues(), *reinterpret_cast<bool *>(data));
    18931910        break;
    1894     case QSqlResult::SetNumericalPrecision:
    1895         d->precisionPolicy = *reinterpret_cast<QSql::NumericalPrecisionPolicy *>(data);
    1896         break;
    18971911    default:
    1898         QSqlResult::virtual_hook(id, data);
     1912        QSqlCachedResult::virtual_hook(id, data);
    18991913    }
    19001914}
     
    20312045    if (!hostname.isEmpty())
    20322046        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);
    20352049
    20362050    r = OCIHandleAlloc(d->env, reinterpret_cast<void **>(&d->srvhp), OCI_HTYPE_SERVER, 0, 0);
     
    20992113    setOpen(true);
    21002114    setOpenError(false);
    2101     d->user = user.toUpper();
     2115    d->user = user;
    21022116
    21032117    return true;
     
    21872201{
    21882202    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
    21892220    if (!isOpen())
    21902221        return tl;
     
    21932224    t.setForwardOnly(true);
    21942225    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 ")));
    22032283        while (t.next()) {
    22042284            if (t.value(0).toString() != d->user)
     
    22082288        }
    22092289    }
    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             else
    2223                 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     }
    22322290    return tl;
    22332291}
     
    22382296    int i = tname.indexOf(QLatin1Char('.')); // prefixed with owner?
    22392297    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);
    22422300    } else {
    2243         *tbl = tname.toUpper();
     2301        *tbl = tname;
    22442302    }
    22452303}
     
    22562314    QString stmt(QLatin1String("select column_name, data_type, data_length, "
    22572315                  "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"));
    22602318    if (d->serverVersion >= 9)
    22612319        stmt = stmt.arg(QLatin1String(", char_length "));
     
    22652323    QString table, owner, tmpStmt;
    22662324    qSplitTableAndOwner(tablename, &table, &owner);
     2325
     2326    if (isIdentifierEscaped(table, QSqlDriver::TableName))
     2327        table = stripDelimiters(table, QSqlDriver::TableName);
     2328    else
     2329        table = table.toUpper();
     2330
    22672331    tmpStmt = stmt.arg(QLatin1Char('\'') + table + QLatin1Char('\''));
    22682332    if (owner.isEmpty()) {
    22692333        owner = d->user;
    22702334    }
    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('\'');
    22722342    t.setForwardOnly(true);
    22732343    t.exec(tmpStmt);
    22742344    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('\'');
    22772350        t.setForwardOnly(true);
    22782351        t.exec(stmt);
     
    22862359    if (buildRecordInfo) {
    22872360        do {
    2288             QVariant::Type ty = qDecodeOCIType(t.value(1).toString(),t.numericalPrecisionPolicy());
     2361            QVariant::Type ty = qDecodeOCIType(t.value(1).toString(), t.numericalPrecisionPolicy());
    22892362            QSqlField f(t.value(0).toString(), ty);
    22902363            f.setRequired(t.value(5).toString() == QLatin1String("N"));
     
    23182391    QString table, owner, tmpStmt;
    23192392    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('\'');
    23212400    if (owner.isEmpty()) {
    23222401        owner = d->user;
    23232402    }
    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('\'');
    23252410    t.setForwardOnly(true);
    23262411    t.exec(tmpStmt);
     
    23462431                     t.value(2).toString() + QLatin1String("' and column_name='") +
    23472432                     t.value(0).toString() + QLatin1String("' and owner='") +
    2348                      owner +QLatin1String("'"));
     2433                     owner + QLatin1Char('\''));
    23492434            if (!tt.next()) {
    23502435                return QSqlIndex();
     
    24162501}
    24172502
    2418 QString QOCIDriver::escapeIdentifier(const QString &identifier, IdentifierType /* type */) const
     2503QString QOCIDriver::escapeIdentifier(const QString &identifier, IdentifierType type) const
    24192504{
    24202505    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("\"\""));
    24232508        res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
    2424 //     res.replace(QLatin1Char('.'), QLatin1String("\".\""));
     2509        res.replace(QLatin1Char('.'), QLatin1String("\".\""));
     2510    }
    24252511    return res;
    24262512}
  • trunk/src/sql/drivers/oci/qsql_oci.h

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtSql module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
Note: See TracChangeset for help on using the changeset viewer.