src/sql/drivers/oci/qsql_oci.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   515                 break;
   515                 break;
   516         }
   516         }
   517     }
   517     }
   518     else if (ocitype == QLatin1String("LONG") || ocitype == QLatin1String("NCLOB")
   518     else if (ocitype == QLatin1String("LONG") || ocitype == QLatin1String("NCLOB")
   519              || ocitype == QLatin1String("CLOB"))
   519              || ocitype == QLatin1String("CLOB"))
   520         type = QVariant::ByteArray;
   520         type = QVariant::String;
   521     else if (ocitype == QLatin1String("RAW") || ocitype == QLatin1String("LONG RAW")
   521     else if (ocitype == QLatin1String("RAW") || ocitype == QLatin1String("LONG RAW")
   522              || ocitype == QLatin1String("ROWID") || ocitype == QLatin1String("BLOB")
   522              || ocitype == QLatin1String("ROWID") || ocitype == QLatin1String("BLOB")
   523              || ocitype == QLatin1String("CFILE") || ocitype == QLatin1String("BFILE"))
   523              || ocitype == QLatin1String("CFILE") || ocitype == QLatin1String("BFILE"))
   524         type = QVariant::ByteArray;
   524         type = QVariant::ByteArray;
   525     else if (ocitype == QLatin1String("DATE") ||  ocitype.startsWith(QLatin1String("TIME")))
   525     else if (ocitype == QLatin1String("DATE") ||  ocitype.startsWith(QLatin1String("TIME")))
   541     case SQLT_AFC:
   541     case SQLT_AFC:
   542     case SQLT_VCS:
   542     case SQLT_VCS:
   543     case SQLT_AVC:
   543     case SQLT_AVC:
   544     case SQLT_RDD:
   544     case SQLT_RDD:
   545     case SQLT_LNG:
   545     case SQLT_LNG:
       
   546     case SQLT_CLOB:
   546 #ifdef SQLT_INTERVAL_YM
   547 #ifdef SQLT_INTERVAL_YM
   547     case SQLT_INTERVAL_YM:
   548     case SQLT_INTERVAL_YM:
   548 #endif
   549 #endif
   549 #ifdef SQLT_INTERVAL_DS
   550 #ifdef SQLT_INTERVAL_DS
   550     case SQLT_INTERVAL_DS:
   551     case SQLT_INTERVAL_DS:
   582     case SQLT_BLOB:
   583     case SQLT_BLOB:
   583     case SQLT_FILE:
   584     case SQLT_FILE:
   584     case SQLT_NTY:
   585     case SQLT_NTY:
   585     case SQLT_REF:
   586     case SQLT_REF:
   586     case SQLT_RID:
   587     case SQLT_RID:
   587     case SQLT_CLOB:
       
   588         type = QVariant::ByteArray;
   588         type = QVariant::ByteArray;
   589         break;
   589         break;
   590     case SQLT_DAT:
   590     case SQLT_DAT:
   591     case SQLT_ODT:
   591     case SQLT_ODT:
   592 #ifdef SQLT_TIMESTAMP
   592 #ifdef SQLT_TIMESTAMP
  1255                 break;
  1255                 break;
  1256 
  1256 
  1257             case QVariant::String: {
  1257             case QVariant::String: {
  1258                 col.bindAs = SQLT_STR;
  1258                 col.bindAs = SQLT_STR;
  1259                 for (uint j = 0; j < col.recordCount; ++j) {
  1259                 for (uint j = 0; j < col.recordCount; ++j) {
  1260                     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;
  1261                     if (len > col.maxLen)
  1265                     if (len > col.maxLen)
  1262                         col.maxLen = len;
  1266                         col.maxLen = len;
  1263                 }
  1267                 }
  1264                 col.maxLen *= sizeof(QChar);
  1268                 col.maxLen *= sizeof(QChar);
  1265                 break; }
  1269                 break; }
  1266 
  1270 
  1267             case QVariant::ByteArray:
  1271             case QVariant::ByteArray:
  1268             default: {
  1272             default: {
  1269                 col.bindAs = SQLT_LBI;
  1273                 col.bindAs = SQLT_LBI;
  1270                 for (uint j = 0; j < col.recordCount; ++j) {
  1274                 for (uint j = 0; j < col.recordCount; ++j) {
  1271                     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();
  1272                     if (col.lengths[j] > col.maxLen)
  1279                     if (col.lengths[j] > col.maxLen)
  1273                         col.maxLen = col.lengths[j];
  1280                         col.maxLen = col.lengths[j];
  1274                 }
  1281                 }
  1275                 break; }
  1282                 break; }
  1276         }
  1283         }
  2191 }
  2198 }
  2192 
  2199 
  2193 QStringList QOCIDriver::tables(QSql::TableType type) const
  2200 QStringList QOCIDriver::tables(QSql::TableType type) const
  2194 {
  2201 {
  2195     QStringList tl;
  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 
  2196     if (!isOpen())
  2220     if (!isOpen())
  2197         return tl;
  2221         return tl;
  2198 
  2222 
  2199     QSqlQuery t(createResult());
  2223     QSqlQuery t(createResult());
  2200     t.setForwardOnly(true);
  2224     t.setForwardOnly(true);
  2201     if (type & QSql::Tables) {
  2225     if (type & QSql::Tables) {
  2202         t.exec(QLatin1String("select owner, table_name from all_tables "
  2226         QString query = QLatin1String("select owner, table_name from all_tables where ");
  2203                 "where owner != 'MDSYS' "
  2227         QStringList whereList;
  2204                 "and owner != 'LBACSYS' "
  2228         foreach(const QString &sysUserName, sysUsers)
  2205                 "and owner != 'SYS' "
  2229             whereList << QLatin1String("owner != '") + sysUserName + QLatin1String("' ");
  2206                 "and owner != 'SYSTEM' "
  2230         t.exec(query + whereList.join(QLatin1String(" and ")));
  2207                 "and owner != 'WKSYS'"
       
  2208                 "and owner != 'CTXSYS'"
       
  2209                 "and owner != '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 
  2231 
  2217         while (t.next()) {
  2232         while (t.next()) {
  2218             if (t.value(0).toString().toUpper() != user.toUpper())
  2233             if (t.value(0).toString().toUpper() != user.toUpper())
  2219                 tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
  2234                 tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
  2220             else
  2235             else
  2221                 tl.append(t.value(1).toString());
  2236                 tl.append(t.value(1).toString());
  2222         }
  2237         }
  2223 
  2238 
  2224         // list all table synonyms as well
  2239         // list all table synonyms as well
  2225         t.exec(QLatin1String("select owner, synonym_name from all_synonyms "
  2240         query = QLatin1String("select owner, synonym_name from all_synonyms where ");
  2226                 "where owner != 'MDSYS' "
  2241         t.exec(query + whereList.join(QLatin1String(" and ")));
  2227                 "and owner != 'LBACSYS' "
  2242         while (t.next()) {
  2228                 "and owner != 'SYS' "
  2243             if (t.value(0).toString() != d->user)
  2229                 "and owner != 'SYSTEM' "
  2244                 tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
  2230                 "and owner != 'WKSYS'"
  2245             else
  2231                 "and owner != 'CTXSYS'"
  2246                 tl.append(t.value(1).toString());
  2232                 "and owner != 'WMSYS'"));
  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 ")));
  2233         while (t.next()) {
  2283         while (t.next()) {
  2234             if (t.value(0).toString() != d->user)
  2284             if (t.value(0).toString() != d->user)
  2235                 tl.append(t.value(0).toString() + QLatin1String(".") + t.value(1).toString());
  2285                 tl.append(t.value(0).toString() + QLatin1String(".") + t.value(1).toString());
  2236             else
  2286             else
  2237                 tl.append(t.value(1).toString());
  2287                 tl.append(t.value(1).toString());
  2238         }
       
  2239     }
       
  2240     if (type & QSql::Views) {
       
  2241         t.exec(QLatin1String("select owner, view_name from all_views "
       
  2242                 "where owner != 'MDSYS' "
       
  2243                 "and owner != 'LBACSYS' "
       
  2244                 "and owner != 'SYS' "
       
  2245                 "and owner != 'SYSTEM' "
       
  2246                 "and owner != 'WKSYS'"
       
  2247                 "and owner != 'CTXSYS'"
       
  2248                 "and owner != 'WMSYS'"));
       
  2249         while (t.next()) {
       
  2250             if (t.value(0).toString().toUpper() != d->user.toUpper())
       
  2251                 tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
       
  2252             else
       
  2253                 tl.append(t.value(1).toString());
       
  2254         }
       
  2255     }
       
  2256     if (type & QSql::SystemTables) {
       
  2257         t.exec(QLatin1String("select table_name from dictionary"));
       
  2258         while (t.next()) {
       
  2259             tl.append(t.value(0).toString());
       
  2260         }
  2288         }
  2261     }
  2289     }
  2262     return tl;
  2290     return tl;
  2263 }
  2291 }
  2264 
  2292