Changeset 846 for trunk/src/sql/drivers/oci
- 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/oci/qsql_oci.cpp
r769 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) … … 57 57 #include <qdebug.h> 58 58 59 // This is needed for oracle oci when compiling with mingw-w64 headers 60 #if defined(__MINGW64_VERSION_MAJOR) && defined(_WIN64) 61 #define _int64 __int64 62 #endif 63 64 59 65 #include <oci.h> 60 66 #ifdef max … … 88 94 #endif 89 95 90 static const ub1 CSID_NCHAR = SQLCS_NCHAR; 96 #ifdef OCI_ATTR_CHARSET_FORM 97 // Always set the OCI_ATTR_CHARSET_FORM to SQLCS_NCHAR is safe 98 // because Oracle server will deal with the implicit Conversion 99 // Between CHAR and NCHAR. 100 // see: http://download.oracle.com/docs/cd/A91202_01/901_doc/appdev.901/a89857/oci05bnd.htm#422705 101 static const ub1 qOraCharsetForm = SQLCS_NCHAR; 102 #endif 103 104 #if defined (OCI_UTF16ID) 105 static const ub2 qOraCharset = OCI_UTF16ID; 106 #else 91 107 static const ub2 qOraCharset = OCI_UCS2ID; 108 #endif 92 109 93 110 typedef QVarLengthArray<sb2, 32> IndicatorArray; … … 96 113 static QByteArray qMakeOraDate(const QDateTime& dt); 97 114 static QDateTime qMakeDate(const char* oraDate); 115 116 static QByteArray qMakeOCINumber(const qlonglong &ll, OCIError *err); 117 static QByteArray qMakeOCINumber(const qulonglong& ull, OCIError* err); 118 119 static qlonglong qMakeLongLong(const char* ociNumber, OCIError* err); 120 static qulonglong qMakeULongLong(const char* ociNumber, OCIError* err); 121 98 122 static QString qOraWarn(OCIError *err, int *errorCode = 0); 123 99 124 #ifndef Q_CC_SUN 100 125 static // for some reason, Sun CC can't use qOraWarning when it's declared static … … 102 127 void qOraWarning(const char* msg, OCIError *err); 103 128 static QSqlError qMakeError(const QString& errString, QSqlError::ErrorType type, OCIError *err); 129 130 104 131 105 132 class QOCIRowId: public QSharedData … … 150 177 int prefetchRows, prefetchMem; 151 178 152 void setCharset(OCIBind* hbnd);153 179 void setStatementAttributes(); 154 180 int bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, int pos, … … 162 188 inline bool isBinaryValue(int i) const 163 189 { return q->bindValueType(i) & QSql::Binary; } 190 191 void setCharset(dvoid* handle, ub4 type) const 192 { 193 int r = 0; 194 Q_ASSERT(handle); 195 196 #ifdef OCI_ATTR_CHARSET_FORM 197 r = OCIAttrSet(handle, 198 type, 199 // this const cast is safe since OCI doesn't touch 200 // the charset. 201 const_cast<void *>(static_cast<const void *>(&qOraCharsetForm)), 202 0, 203 OCI_ATTR_CHARSET_FORM, 204 //Strange Oracle bug: some Oracle servers crash the server process with non-zero error handle (mostly for 10g). 205 //So ignore the error message here. 206 0); 207 #ifdef QOCI_DEBUG 208 if (r != 0) 209 qWarning("QOCIResultPrivate::setCharset: Couldn't set OCI_ATTR_CHARSET_FORM."); 210 #endif 211 #endif 212 213 r = OCIAttrSet(handle, 214 type, 215 // this const cast is safe since OCI doesn't touch 216 // the charset. 217 const_cast<void *>(static_cast<const void *>(&qOraCharset)), 218 0, 219 OCI_ATTR_CHARSET_ID, 220 err); 221 if (r != 0) 222 qOraWarning("QOCIResultPrivate::setCharsetI Couldn't set OCI_ATTR_CHARSET_ID: ", err); 223 224 } 164 225 }; 165 226 … … 192 253 " Couldn't set OCI_ATTR_PREFETCH_MEMORY: ", err); 193 254 } 194 }195 196 void QOCIResultPrivate::setCharset(OCIBind* hbnd)197 {198 int r = 0;199 200 Q_ASSERT(hbnd);201 202 r = OCIAttrSet(hbnd,203 OCI_HTYPE_BIND,204 // this const cast is safe since OCI doesn't touch205 // the charset.206 const_cast<void *>(static_cast<const void *>(&qOraCharset)),207 0,208 OCI_ATTR_CHARSET_ID,209 err);210 if (r != 0)211 qOraWarning("QOCIResultPrivate::setCharset: Couldn't set OCI_ATTR_CHARSET_ID: ", err);212 255 } 213 256 … … 257 300 SQLT_UIN, indPtr, 0, 0, 0, 0, OCI_DEFAULT); 258 301 break; 302 case QVariant::LongLong: 303 { 304 QByteArray ba = qMakeOCINumber(val.toLongLong(), err); 305 r = OCIBindByPos(sql, hbnd, err, 306 pos + 1, 307 ba.data(), 308 ba.size(), 309 SQLT_VNU, indPtr, 0, 0, 0, 0, OCI_DEFAULT); 310 tmpStorage.append(ba); 311 break; 312 } 313 case QVariant::ULongLong: 314 { 315 QByteArray ba = qMakeOCINumber(val.toULongLong(), err); 316 r = OCIBindByPos(sql, hbnd, err, 317 pos + 1, 318 ba.data(), 319 ba.size(), 320 SQLT_VNU, indPtr, 0, 0, 0, 0, OCI_DEFAULT); 321 tmpStorage.append(ba); 322 break; 323 } 259 324 case QVariant::Double: 260 325 r = OCIBindByPos(sql, hbnd, err, … … 299 364 SQLT_STR, indPtr, 0, 0, 0, 0, OCI_DEFAULT); 300 365 if (r == OCI_SUCCESS) 301 setCharset(*hbnd );366 setCharset(*hbnd, OCI_HTYPE_BIND); 302 367 break; 303 368 } … … 323 388 } 324 389 if (r == OCI_SUCCESS) 325 setCharset(*hbnd );390 setCharset(*hbnd, OCI_HTYPE_BIND); 326 391 tmpStorage.append(ba); 327 392 break; … … 352 417 353 418 // will assign out value and remove its temp storage. 354 static void qOraOutValue(QVariant &value, QList<QByteArray> &storage )419 static void qOraOutValue(QVariant &value, QList<QByteArray> &storage, OCIError* err) 355 420 { 356 421 switch (value.type()) { … … 364 429 value = qMakeDate(storage.takeFirst()); 365 430 break; 431 case QVariant::LongLong: 432 value = qMakeLongLong(storage.takeFirst(), err); 433 break; 434 case QVariant::ULongLong: 435 value = qMakeULongLong(storage.takeFirst(), err); 436 break; 366 437 case QVariant::String: 367 value = QString ::fromUtf16(368 reinterpret_cast<const ushort*>(storage.takeFirst().constData()));438 value = QString( 439 reinterpret_cast<const QChar *>(storage.takeFirst().constData())); 369 440 break; 370 441 default: … … 381 452 continue; 382 453 383 qOraOutValue(values[i], tmpStorage );454 qOraOutValue(values[i], tmpStorage, err); 384 455 385 456 QVariant::Type typ = values.at(i).type(); … … 455 526 if (errorCode) 456 527 *errorCode = errcode; 457 return QString ::fromUtf16(reinterpret_cast<const ushort*>(errbuf));528 return QString(reinterpret_cast<const QChar *>(errbuf)); 458 529 } 459 530 … … 641 712 } 642 713 714 /*! 715 \internal 716 717 Convert qlonglong to the internal Oracle OCINumber format. 718 */ 719 QByteArray qMakeOCINumber(const qlonglong& ll, OCIError* err) 720 { 721 QByteArray ba(sizeof(OCINumber), 0); 722 723 OCINumberFromInt(err, 724 &ll, 725 sizeof(qlonglong), 726 OCI_NUMBER_SIGNED, 727 reinterpret_cast<OCINumber*>(ba.data())); 728 return ba; 729 } 730 731 /*! 732 \internal 733 734 Convert qulonglong to the internal Oracle OCINumber format. 735 */ 736 QByteArray qMakeOCINumber(const qulonglong& ull, OCIError* err) 737 { 738 QByteArray ba(sizeof(OCINumber), 0); 739 740 OCINumberFromInt(err, 741 &ull, 742 sizeof(qlonglong), 743 OCI_NUMBER_UNSIGNED, 744 reinterpret_cast<OCINumber*>(ba.data())); 745 return ba; 746 } 747 748 qlonglong qMakeLongLong(const char* ociNumber, OCIError* err) 749 { 750 qlonglong qll = 0; 751 OCINumberToInt(err, reinterpret_cast<const OCINumber *>(ociNumber), sizeof(qlonglong), 752 OCI_NUMBER_SIGNED, &qll); 753 return qll; 754 } 755 756 qulonglong qMakeULongLong(const char* ociNumber, OCIError* err) 757 { 758 qulonglong qull = 0; 759 OCINumberToInt(err, reinterpret_cast<const OCINumber *>(ociNumber), sizeof(qulonglong), 760 OCI_NUMBER_UNSIGNED, &qull); 761 return qull; 762 } 763 643 764 QDateTime qMakeDate(const char* oraDate) 644 765 { 645 int century = oraDate[0];766 int century = uchar(oraDate[0]); 646 767 if(century >= 100){ 647 768 int year = uchar(oraDate[1]); … … 662 783 QOCICols(int size, QOCIResultPrivate* dp); 663 784 ~QOCICols(); 664 void setCharset(OCIDefine* dfn);665 785 int readPiecewise(QVector<QVariant> &values, int index = 0); 666 786 int readLOBs(QVector<QVariant> &values, int index = 0); … … 864 984 0, 0, OCI_DEFAULT); 865 985 if (r == 0) 866 setCharset(dfn);986 d->setCharset(dfn, OCI_HTYPE_DEFINE); 867 987 } 868 988 break; … … 922 1042 } 923 1043 return &lob; 924 }925 926 void QOCICols::setCharset(OCIDefine* dfn)927 {928 int r = 0;929 930 Q_ASSERT(dfn);931 932 r = OCIAttrSet(dfn,933 OCI_HTYPE_DEFINE,934 // this const cast is safe since OCI doesn't touch935 // the charset.936 const_cast<void *>(static_cast<const void *>(&qOraCharset)),937 0,938 OCI_ATTR_CHARSET_ID,939 d->err);940 if (r != 0)941 qOraWarning("QOCICols::setCharset: Couldn't set OCI_ATTR_CHARSET_ID: ", d->err);942 1044 } 943 1045 … … 990 1092 if (isStringField) { 991 1093 QString str = values.at(fieldNum + index).toString(); 992 str += QString::fromUtf16(reinterpret_cast<const ushort *>(col), 993 chunkSize / 2); 1094 str += QString(reinterpret_cast<const QChar *>(col), chunkSize / 2); 994 1095 values[fieldNum + index] = str; 995 1096 fieldInf[fieldNum].ind = 0; … … 1245 1346 break; 1246 1347 1348 case QVariant::LongLong: 1349 col.bindAs = SQLT_VNU; 1350 col.maxLen = sizeof(OCINumber); 1351 break; 1352 1353 case QVariant::ULongLong: 1354 col.bindAs = SQLT_VNU; 1355 col.maxLen = sizeof(OCINumber); 1356 break; 1357 1247 1358 case QVariant::Double: 1248 1359 col.bindAs = SQLT_FLT; … … 1316 1427 break; 1317 1428 1429 case QVariant::LongLong: 1430 { 1431 columns[i].lengths[row] = columns[i].maxLen; 1432 const QByteArray ba = qMakeOCINumber(val.toLongLong(), d->err); 1433 Q_ASSERT(ba.size() == int(columns[i].maxLen)); 1434 memcpy(dataPtr, ba.constData(), columns[i].maxLen); 1435 break; 1436 } 1437 case QVariant::ULongLong: 1438 { 1439 columns[i].lengths[row] = columns[i].maxLen; 1440 const QByteArray ba = qMakeOCINumber(val.toULongLong(), d->err); 1441 Q_ASSERT(ba.size() == int(columns[i].maxLen)); 1442 memcpy(dataPtr, ba.constData(), columns[i].maxLen); 1443 break; 1444 } 1318 1445 case QVariant::Double: 1319 1446 columns[i].lengths[row] = columns[i].maxLen; … … 1423 1550 QVariant::Type tp = boundValues.at(i).type(); 1424 1551 if (tp != QVariant::List) { 1425 qOraOutValue(boundValues[i], tmpStorage );1552 qOraOutValue(boundValues[i], tmpStorage, d->err); 1426 1553 if (*columns[i].indicators == -1) 1427 1554 boundValues[i] = QVariant(tp); … … 1453 1580 break; 1454 1581 1582 case SQLT_VNU: 1583 { 1584 switch (boundValues.at(i).type()) { 1585 case QVariant::LongLong: 1586 (*list)[r] = qMakeLongLong(data + r * columns[i].maxLen, d->err); 1587 break; 1588 case QVariant::ULongLong: 1589 (*list)[r] = qMakeULongLong(data + r * columns[i].maxLen, d->err); 1590 break; 1591 default: 1592 break; 1593 } 1594 break; 1595 } 1596 1455 1597 case SQLT_FLT: 1456 1598 (*list)[r] = *reinterpret_cast<double*>(data + r * columns[i].maxLen); … … 1458 1600 1459 1601 case SQLT_STR: 1460 (*list)[r] = QString ::fromUtf16(reinterpret_cast<ushort*>(data1602 (*list)[r] = QString(reinterpret_cast<const QChar *>(data 1461 1603 + r * columns[i].maxLen)); 1462 1604 break; … … 1609 1751 // else fall through 1610 1752 case QVariant::String: 1611 v[index + i] = QString ::fromUtf16(reinterpret_cast<const ushort*>(fld.data));1753 v[index + i] = QString(reinterpret_cast<const QChar *>(fld.data)); 1612 1754 break; 1613 1755 case QVariant::ByteArray: … … 2103 2245 } else { 2104 2246 QString versionStr; 2105 versionStr = QString ::fromUtf16(reinterpret_cast<ushort*>(vertxt));2247 versionStr = QString(reinterpret_cast<const QChar *>(vertxt)); 2106 2248 QRegExp vers(QLatin1String("([0-9]+)\\.[0-9\\.]+[0-9]")); 2107 2249 if (vers.indexIn(versionStr) >= 0) -
trunk/src/sql/drivers/oci/qsql_oci.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) … … 55 55 QT_BEGIN_HEADER 56 56 57 typedef struct OCIEnv OCIEnv; 58 typedef struct OCISvcCtx OCISvcCtx; 59 57 60 QT_BEGIN_NAMESPACE 58 61 … … 61 64 struct QOCIDriverPrivate; 62 65 struct QOCIResultPrivate; 63 64 typedef struct OCIEnv OCIEnv;65 typedef struct OCISvcCtx OCISvcCtx;66 66 67 67 class Q_EXPORT_SQLDRIVER_OCI QOCIResult : public QSqlCachedResult
Note:
See TracChangeset
for help on using the changeset viewer.