Changeset 769 for trunk/src/sql/drivers/odbc
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/src/sql/drivers/odbc/qsql_odbc.cpp
r651 r769 67 67 # undef UNICODE 68 68 # define SQLTCHAR SQLCHAR 69 # define SQL_C_ WCHAR SQL_C_CHAR69 # define SQL_C_TCHAR SQL_C_CHAR 70 70 #endif 71 71 … … 79 79 #endif 80 80 81 82 81 static const int COLNAMESIZE = 256; 83 82 //Map Qt parameter types to ODBC types 84 83 static const SQLSMALLINT qParamType[4] = { SQL_PARAM_INPUT, SQL_PARAM_INPUT, SQL_PARAM_OUTPUT, SQL_PARAM_INPUT_OUTPUT }; 85 84 85 inline static QString fromSQLTCHAR(const QVarLengthArray<SQLTCHAR>& input, int size=-1) 86 { 87 QString result; 88 89 int realsize = qMin(size, input.size()); 90 if(realsize > 0 && input[realsize-1] == 0) 91 realsize--; 92 switch(sizeof(SQLTCHAR)) { 93 case 1: 94 result=QString::fromUtf8((const char *)input.constData(), realsize); 95 break; 96 case 2: 97 result=QString::fromUtf16((const ushort *)input.constData(), realsize); 98 break; 99 case 4: 100 result=QString::fromUcs4((const uint *)input.constData(), realsize); 101 break; 102 default: 103 qCritical() << "sizeof(SQLTCHAR) is " << sizeof(SQLTCHAR) << "Don't know how to handle this"; 104 } 105 return result; 106 } 107 108 inline static QVarLengthArray<SQLTCHAR> toSQLTCHAR(const QString &input) 109 { 110 QVarLengthArray<SQLTCHAR> result; 111 result.resize(input.size()); 112 switch(sizeof(SQLTCHAR)) { 113 case 1: 114 memcpy(result.data(), input.toUtf8().data(), input.size()); 115 break; 116 case 2: 117 memcpy(result.data(), input.unicode(), input.size() * 2); 118 break; 119 case 4: 120 memcpy(result.data(), input.toUcs4().data(), input.size() * 4); 121 break; 122 default: 123 qCritical() << "sizeof(SQLTCHAR) is " << sizeof(SQLTCHAR) << "Don't know how to handle this"; 124 } 125 result.append(0); // make sure it's null terminated, doesn't matter if it already is, it does if it isn't. 126 return result; 127 } 128 86 129 class QODBCDriverPrivate 87 130 { … … 89 132 enum DefaultCase{Lower, Mixed, Upper, Sensitive}; 90 133 QODBCDriverPrivate() 91 : hEnv(0), hDbc(0), u seSchema(false), disconnectCount(0), isMySqlServer(false),92 isMSSqlServer(false), hasSQLFetchScroll(true), hasMultiResultSets(false),93 isQuoteInitialized(false), quote(QLatin1Char('"'))134 : hEnv(0), hDbc(0), unicode(false), useSchema(false), disconnectCount(0), isMySqlServer(false), 135 isMSSqlServer(false), isFreeTDSDriver(false), hasSQLFetchScroll(true), 136 hasMultiResultSets(false), isQuoteInitialized(false), quote(QLatin1Char('"')) 94 137 { 95 unicode = false;96 138 } 97 139 … … 99 141 SQLHANDLE hDbc; 100 142 101 uint unicode :1;102 uint useSchema :1;143 bool unicode; 144 bool useSchema; 103 145 int disconnectCount; 104 146 bool isMySqlServer; 105 147 bool isMSSqlServer; 148 bool isFreeTDSDriver; 106 149 bool hasSQLFetchScroll; 107 150 bool hasMultiResultSets; … … 130 173 : hStmt(0), useSchema(false), hasSQLFetchScroll(true), driverPrivate(dpp), userForwardOnly(false) 131 174 { 132 unicode = false; 175 unicode = dpp->unicode; 176 useSchema = dpp->useSchema; 177 disconnectCount = dpp->disconnectCount; 178 hasSQLFetchScroll = dpp->hasSQLFetchScroll; 133 179 } 134 180 … … 140 186 SQLHANDLE hStmt; 141 187 142 uint unicode :1;143 uint useSchema :1;188 bool unicode; 189 bool useSchema; 144 190 145 191 QSqlRecord rInf; … … 178 224 179 225 description_[0] = 0; 180 r = SQLGetDiagRec(handleType,181 handle,182 i,183 state_,184 &nativeCode_,185 0,186 NULL,187 &msgLen);188 if(r == SQL_NO_DATA)189 return QString();190 description_.resize(msgLen+1);191 226 do { 227 r = SQLGetDiagRec(handleType, 228 handle, 229 i, 230 state_, 231 &nativeCode_, 232 0, 233 NULL, 234 &msgLen); 235 if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && msgLen > 0) 236 description_.resize(msgLen+1); 192 237 r = SQLGetDiagRec(handleType, 193 238 handle, … … 203 248 QString tmpstore; 204 249 #ifdef UNICODE 205 tmpstore = QString((const QChar*)description_.data(), msgLen);250 tmpstore = fromSQLTCHAR(description_, msgLen); 206 251 #else 207 tmpstore = QString::from Local8Bit((const char*)description_.data(), msgLen);252 tmpstore = QString::fromUtf8((const char*)description_.constData(), msgLen); 208 253 #endif 209 254 if(result != tmpstore) { … … 224 269 return (qWarnODBCHandle(SQL_HANDLE_ENV, odbc->dpEnv()) + QLatin1Char(' ') 225 270 + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->dpDbc()) + QLatin1Char(' ') 226 + qWarnODBCHandle(SQL_HANDLE_STMT, odbc->hStmt, nativeCode)) ;271 + qWarnODBCHandle(SQL_HANDLE_STMT, odbc->hStmt, nativeCode)).simplified(); 227 272 } 228 273 … … 230 275 { 231 276 return (qWarnODBCHandle(SQL_HANDLE_ENV, odbc->hEnv) + QLatin1Char(' ') 232 + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->hDbc, nativeCode)) ;277 + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->hDbc, nativeCode)).simplified(); 233 278 } 234 279 … … 308 353 case SQL_CHAR: 309 354 case SQL_VARCHAR: 355 #if (ODBCVER >= 0x0350) 310 356 case SQL_GUID: 357 #endif 311 358 case SQL_LONGVARCHAR: 312 359 type = QVariant::String; … … 332 379 } else { 333 380 colSize++; // make sure there is room for more than the 0 termination 334 if (unicode) { 335 colSize *= 2; // a tiny bit faster, since it saves a SQLGetData() call 336 } 337 } 338 QVarLengthArray<char> buf(colSize); 339 while (true) { 381 } 382 if(unicode) { 340 383 r = SQLGetData(hStmt, 341 384 column+1, 342 unicode ? SQL_C_WCHAR : SQL_C_CHAR,343 (SQLPOINTER)buf.data(),344 colSize,385 SQL_C_TCHAR, 386 NULL, 387 0, 345 388 &lengthIndicator); 346 if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) { 347 if (lengthIndicator == SQL_NULL_DATA || lengthIndicator == SQL_NO_TOTAL) { 389 if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && lengthIndicator > 0) 390 colSize = lengthIndicator/sizeof(SQLTCHAR) + 1; 391 QVarLengthArray<SQLTCHAR> buf(colSize); 392 memset(buf.data(), 0, colSize*sizeof(SQLTCHAR)); 393 while (true) { 394 r = SQLGetData(hStmt, 395 column+1, 396 SQL_C_TCHAR, 397 (SQLPOINTER)buf.data(), 398 colSize*sizeof(SQLTCHAR), 399 &lengthIndicator); 400 if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) { 401 if (lengthIndicator == SQL_NULL_DATA || lengthIndicator == SQL_NO_TOTAL) { 402 fieldVal.clear(); 403 break; 404 } 405 // if SQL_SUCCESS_WITH_INFO is returned, indicating that 406 // more data can be fetched, the length indicator does NOT 407 // contain the number of bytes returned - it contains the 408 // total number of bytes that CAN be fetched 409 // colSize-1: remove 0 termination when there is more data to fetch 410 int rSize = (r == SQL_SUCCESS_WITH_INFO) ? colSize : lengthIndicator/sizeof(SQLTCHAR); 411 fieldVal += fromSQLTCHAR(buf, rSize); 412 if (lengthIndicator < (unsigned int)colSize*sizeof(SQLTCHAR)) { 413 // workaround for Drivermanagers that don't return SQL_NO_DATA 414 break; 415 } 416 } else if (r == SQL_NO_DATA) { 417 break; 418 } else { 419 qWarning() << "qGetStringData: Error while fetching data (" << qWarnODBCHandle(SQL_HANDLE_STMT, hStmt) << ')'; 348 420 fieldVal.clear(); 349 421 break; 350 422 } 351 // if SQL_SUCCESS_WITH_INFO is returned, indicating that 352 // more data can be fetched, the length indicator does NOT 353 // contain the number of bytes returned - it contains the 354 // total number of bytes that CAN be fetched 355 // colSize-1: remove 0 termination when there is more data to fetch 356 int rSize = (r == SQL_SUCCESS_WITH_INFO) ? (unicode ? colSize-2 : colSize-1) : lengthIndicator; 357 if (unicode) { 358 fieldVal += QString((const QChar*) buf.constData(), rSize / 2); 423 } 424 } else { 425 r = SQLGetData(hStmt, 426 column+1, 427 SQL_C_CHAR, 428 NULL, 429 0, 430 &lengthIndicator); 431 if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && lengthIndicator > 0) 432 colSize = lengthIndicator + 1; 433 QVarLengthArray<SQLCHAR> buf(colSize); 434 while (true) { 435 r = SQLGetData(hStmt, 436 column+1, 437 SQL_C_CHAR, 438 (SQLPOINTER)buf.data(), 439 colSize, 440 &lengthIndicator); 441 if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) { 442 if (lengthIndicator == SQL_NULL_DATA || lengthIndicator == SQL_NO_TOTAL) { 443 fieldVal.clear(); 444 break; 445 } 446 // if SQL_SUCCESS_WITH_INFO is returned, indicating that 447 // more data can be fetched, the length indicator does NOT 448 // contain the number of bytes returned - it contains the 449 // total number of bytes that CAN be fetched 450 // colSize-1: remove 0 termination when there is more data to fetch 451 int rSize = (r == SQL_SUCCESS_WITH_INFO) ? colSize : lengthIndicator; 452 fieldVal += QString::fromUtf8((const char *)buf.constData(), rSize); 453 if (lengthIndicator < (unsigned int)colSize) { 454 // workaround for Drivermanagers that don't return SQL_NO_DATA 455 break; 456 } 457 } else if (r == SQL_NO_DATA) { 458 break; 359 459 } else { 360 fieldVal += QString::fromAscii(buf.constData(), rSize); 361 } 362 memset(buf.data(), 0, colSize); 363 if (lengthIndicator < colSize) { 364 // workaround for Drivermanagers that don't return SQL_NO_DATA 460 qWarning() << "qGetStringData: Error while fetching data (" << qWarnODBCHandle(SQL_HANDLE_STMT, hStmt) << ')'; 461 fieldVal.clear(); 365 462 break; 366 463 } 367 } else if (r == SQL_NO_DATA) {368 break;369 } else {370 qWarning() << "qGetStringData: Error while fetching data (" << qWarnODBCHandle(SQL_HANDLE_STMT, hStmt) << ')';371 fieldVal.clear();372 break;373 464 } 374 465 } … … 387 478 SQLRETURN r = SQL_ERROR; 388 479 389 SQLTCHAR colName[COLNAMESIZE]; 480 QVarLengthArray<SQLTCHAR> colName(COLNAMESIZE); 481 390 482 r = SQLDescribeCol(hStmt, 391 483 column + 1, 392 colName ,484 colName.data(), 393 485 COLNAMESIZE, 394 486 &colNameLen, … … 523 615 SQLSMALLINT nullable; 524 616 SQLRETURN r = SQL_ERROR; 525 SQLTCHAR colName[COLNAMESIZE];617 QVarLengthArray<SQLTCHAR> colName(COLNAMESIZE); 526 618 r = SQLDescribeCol(p->hStmt, 527 619 i+1, 528 colName ,620 colName.data(), 529 621 (SQLSMALLINT)COLNAMESIZE, 530 622 &colNameLen, … … 552 644 553 645 #ifdef UNICODE 554 QString qColName( (const QChar*)colName, colNameLen);646 QString qColName(fromSQLTCHAR(colName, colNameLen)); 555 647 #else 556 QString qColName = QString::from Local8Bit((const char*)colName);648 QString qColName = QString::fromUtf8((const char *)colName.constData()); 557 649 #endif 558 650 // nullable can be SQL_NO_NULLS, SQL_NULLABLE or SQL_NULLABLE_UNKNOWN … … 582 674 return SQL_OV_ODBC3; 583 675 #endif 676 if (connOpts.contains(QLatin1String("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC2"), Qt::CaseInsensitive)) 677 return SQL_OV_ODBC2; 678 #ifdef _IODBCUNIX_H 679 return SQL_OV_ODBC3; 680 #else 584 681 return SQL_OV_ODBC2; 682 #endif 585 683 } 586 684 … … 588 686 { 589 687 if (!isQuoteInitialized) { 590 chardriverResponse[4];688 SQLTCHAR driverResponse[4]; 591 689 SQLSMALLINT length; 592 690 int r = SQLGetInfo(hDbc, … … 595 693 sizeof(driverResponse), 596 694 &length); 597 if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) { 695 if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) 696 #ifdef UNICODE 697 quote = QChar(driverResponse[0]); 698 #else 598 699 quote = QLatin1Char(driverResponse[0]); 599 } else { 700 #endif 701 else 600 702 quote = QLatin1Char('"'); 601 }602 703 isQuoteInitialized = true; 603 704 } … … 643 744 r = SQLSetConnectAttr(hDbc, SQL_ATTR_CURRENT_CATALOG, 644 745 #ifdef UNICODE 645 (SQLWCHAR*) val.unicode(),746 toSQLTCHAR(val).data(), 646 747 #else 647 (SQLCHAR*) val.to Latin1().constData(),648 #endif 649 SQL_NTS);748 (SQLCHAR*) val.toUtf8().data(), 749 #endif 750 val.length()*sizeof(SQLTCHAR)); 650 751 } else if (opt.toUpper() == QLatin1String("SQL_ATTR_METADATA_ID")) { 651 752 if (val.toUpper() == QLatin1String("SQL_TRUE")) { … … 665 766 r = SQLSetConnectAttr(hDbc, SQL_ATTR_TRACEFILE, 666 767 #ifdef UNICODE 667 (SQLWCHAR*) val.unicode(),768 toSQLTCHAR(val).data(), 668 769 #else 669 (SQLCHAR*) val.to Latin1().constData(),670 #endif 671 SQL_NTS);770 (SQLCHAR*) val.toUtf8().data(), 771 #endif 772 val.length()*sizeof(SQLTCHAR)); 672 773 } else if (opt.toUpper() == QLatin1String("SQL_ATTR_TRACE")) { 673 774 if (val.toUpper() == QLatin1String("SQL_OPT_TRACE_OFF")) { … … 815 916 { 816 917 d = new QODBCPrivate(p); 817 d->unicode = p->unicode;818 d->useSchema = p->useSchema;819 d->disconnectCount = p->disconnectCount;820 d->hasSQLFetchScroll = p->hasSQLFetchScroll;821 918 } 822 919 … … 881 978 #ifdef UNICODE 882 979 r = SQLExecDirect(d->hStmt, 883 (SQLWCHAR*) query.unicode(),980 toSQLTCHAR(query).data(), 884 981 (SQLINTEGER) query.length()); 885 982 #else 886 QByteArray query8 = query.to Local8Bit();983 QByteArray query8 = query.toUtf8(); 887 984 r = SQLExecDirect(d->hStmt, 888 (SQLCHAR*) query8. constData(),985 (SQLCHAR*) query8.data(), 889 986 (SQLINTEGER) query8.length()); 890 987 #endif … … 1232 1329 #ifdef UNICODE 1233 1330 r = SQLPrepare(d->hStmt, 1234 (SQLWCHAR*) query.unicode(),1331 toSQLTCHAR(query).data(), 1235 1332 (SQLINTEGER) query.length()); 1236 1333 #else 1237 QByteArray query8 = query.to Local8Bit();1334 QByteArray query8 = query.toUtf8(); 1238 1335 r = SQLPrepare(d->hStmt, 1239 (SQLCHAR*) query8. constData(),1336 (SQLCHAR*) query8.data(), 1240 1337 (SQLINTEGER) query8.length()); 1241 1338 #endif … … 1436 1533 if (d->unicode) { 1437 1534 QString str = val.toString(); 1438 str.utf16();1439 1535 if (*ind != SQL_NULL_DATA) 1440 *ind = str.length() * sizeof( QChar);1441 int strSize = str.length() * sizeof( QChar);1536 *ind = str.length() * sizeof(SQLTCHAR); 1537 int strSize = str.length() * sizeof(SQLTCHAR); 1442 1538 1443 1539 if (bindValueType(i) & QSql::Out) { 1444 QByteArray ba((char*)str.constData(), str.capacity() * sizeof(QChar)); 1540 QVarLengthArray<SQLTCHAR> ba(toSQLTCHAR(str)); 1541 ba.reserve(str.capacity()); 1445 1542 r = SQLBindParameter(d->hStmt, 1446 1543 i + 1, 1447 1544 qParamType[(QFlag)(bindValueType(i)) & QSql::InOut], 1448 SQL_C_ WCHAR,1545 SQL_C_TCHAR, 1449 1546 strSize > 254 ? SQL_WLONGVARCHAR : SQL_WVARCHAR, 1450 1547 0, // god knows... don't change this! … … 1453 1550 ba.size(), 1454 1551 ind); 1455 tmpStorage.append( ba);1552 tmpStorage.append(QByteArray((const char *)ba.constData(), ba.size()*sizeof(SQLTCHAR))); 1456 1553 break; 1457 1554 } 1458 1555 QByteArray strba((const char *)toSQLTCHAR(str).constData(), str.size()*sizeof(SQLTCHAR)); 1459 1556 r = SQLBindParameter(d->hStmt, 1460 1557 i + 1, 1461 1558 qParamType[(QFlag)(bindValueType(i)) & QSql::InOut], 1462 SQL_C_ WCHAR,1559 SQL_C_TCHAR, 1463 1560 strSize > 254 ? SQL_WLONGVARCHAR : SQL_WVARCHAR, 1464 1561 strSize, 1465 1562 0, 1466 ( void *)str.constData(),1467 str Size,1563 (SQLPOINTER)strba.constData(), 1564 strba.size(), 1468 1565 ind); 1566 tmpStorage.append(strba); 1469 1567 break; 1470 1568 } … … 1472 1570 #endif 1473 1571 { 1474 QByteArray str = val.toString().to Ascii();1572 QByteArray str = val.toString().toUtf8(); 1475 1573 if (*ind != SQL_NULL_DATA) 1476 1574 *ind = str.length(); … … 1573 1671 case QVariant::String: 1574 1672 if (d->unicode) { 1575 if (bindValueType(i) & QSql::Out) 1576 values[i] = QString::fromUtf16((ushort*)tmpStorage.takeFirst().constData()); 1673 if (bindValueType(i) & QSql::Out) { 1674 QByteArray first = tmpStorage.takeFirst(); 1675 QVarLengthArray<SQLTCHAR> array; 1676 array.append((SQLTCHAR *)first.constData(), first.size()); 1677 values[i] = fromSQLTCHAR(array, first.size()/sizeof(SQLTCHAR*)); 1678 } 1577 1679 break; 1578 1680 } 1579 1681 // fall through 1580 1682 default: { 1581 QByteArray ba = tmpStorage.takeFirst();1582 1683 if (bindValueType(i) & QSql::Out) 1583 values[i] = QString::fromAscii(ba.constData());1684 values[i] = tmpStorage.takeFirst(); 1584 1685 break; } 1585 1686 } … … 1790 1891 1791 1892 SQLSMALLINT cb; 1792 SQLTCHAR connOut[1024]; 1893 QVarLengthArray<SQLTCHAR> connOut(1024); 1894 memset(connOut.data(), 0, connOut.size() * sizeof(SQLTCHAR)); 1793 1895 r = SQLDriverConnect(d->hDbc, 1794 1896 NULL, 1795 1897 #ifdef UNICODE 1796 (SQLWCHAR*)connQStr.unicode(),1898 toSQLTCHAR(connQStr).data(), 1797 1899 #else 1798 (SQLCHAR*)connQStr.to Latin1().constData(),1900 (SQLCHAR*)connQStr.toUtf8().data(), 1799 1901 #endif 1800 1902 (SQLSMALLINT)connQStr.length(), 1801 connOut ,1903 connOut.data(), 1802 1904 1024, 1803 1905 &cb, 1804 SQL_DRIVER_NOPROMPT); 1906 /*SQL_DRIVER_NOPROMPT*/0); 1907 1805 1908 if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) { 1806 1909 setLastError(qMakeError(tr("Unable to connect"), QSqlError::ConnectionError, d)); … … 1887 1990 if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (fFunc & SQL_CVT_WCHAR)) { 1888 1991 unicode = true; 1992 return; 1889 1993 } 1890 1994 … … 1896 2000 if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (fFunc & SQL_CVT_WVARCHAR)) { 1897 2001 unicode = true; 2002 return; 1898 2003 } 1899 2004 … … 1905 2010 if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (fFunc & SQL_CVT_WLONGVARCHAR)) { 1906 2011 unicode = true; 1907 } 2012 return; 2013 } 2014 SQLHANDLE hStmt; 2015 r = SQLAllocHandle(SQL_HANDLE_STMT, 2016 hDbc, 2017 &hStmt); 2018 2019 r = SQLExecDirect(hStmt, toSQLTCHAR(QLatin1String("select 'test'")).data(), SQL_NTS); 2020 if(r == SQL_SUCCESS) { 2021 r = SQLFetch(hStmt); 2022 if(r == SQL_SUCCESS) { 2023 QVarLengthArray<SQLWCHAR> buffer(10); 2024 r = SQLGetData(hStmt, 1, SQL_C_WCHAR, buffer.data(), buffer.size() * sizeof(SQLWCHAR), NULL); 2025 if(r == SQL_SUCCESS && fromSQLTCHAR(buffer) == QLatin1String("test")) { 2026 unicode = true; 2027 } 2028 } 2029 } 2030 r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt); 1908 2031 } 1909 2032 … … 1978 2101 { 1979 2102 SQLRETURN r; 1980 char serverString[200];2103 QVarLengthArray<SQLTCHAR> serverString(200); 1981 2104 SQLSMALLINT t; 2105 memset(serverString.data(), 0, serverString.size() * sizeof(SQLTCHAR)); 1982 2106 1983 2107 r = SQLGetInfo(hDbc, 1984 2108 SQL_DBMS_NAME, 1985 serverString ,1986 s izeof(serverString),2109 serverString.data(), 2110 serverString.size() * sizeof(SQLTCHAR), 1987 2111 &t); 1988 2112 if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) { 1989 2113 QString serverType; 1990 2114 #ifdef UNICODE 1991 serverType = QString(reinterpret_cast<const QChar*>(serverString), t/sizeof(QChar));2115 serverType = fromSQLTCHAR(serverString, t/sizeof(SQLTCHAR)); 1992 2116 #else 1993 serverType = QString::from Local8Bit(serverString, t);2117 serverType = QString::fromUtf8((const char *)serverString.constData(), t); 1994 2118 #endif 1995 2119 isMySqlServer = serverType.contains(QLatin1String("mysql"), Qt::CaseInsensitive); 1996 2120 isMSSqlServer = serverType.contains(QLatin1String("Microsoft SQL Server"), Qt::CaseInsensitive); 2121 } 2122 r = SQLGetInfo(hDbc, 2123 SQL_DRIVER_NAME, 2124 serverString.data(), 2125 serverString.size() * sizeof(SQLTCHAR), 2126 &t); 2127 if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) { 2128 QString serverType; 2129 #ifdef UNICODE 2130 serverType = fromSQLTCHAR(serverString, t/sizeof(SQLTCHAR)); 2131 #else 2132 serverType = QString::fromUtf8((const char *)serverString.constData(), t); 2133 #endif 2134 isFreeTDSDriver = serverType.contains(QLatin1String("tdsodbc"), Qt::CaseInsensitive); 2135 unicode = isFreeTDSDriver == false; 1997 2136 } 1998 2137 } … … 2010 2149 void QODBCDriverPrivate::checkHasMultiResults() 2011 2150 { 2012 char driverResponse[4];2151 QVarLengthArray<SQLTCHAR> driverResponse(2); 2013 2152 SQLSMALLINT length; 2014 2153 SQLRETURN r = SQLGetInfo(hDbc, 2015 2154 SQL_MULT_RESULT_SETS, 2016 driverResponse ,2017 sizeof(driverResponse),2155 driverResponse.data(), 2156 driverResponse.size() * sizeof(SQLTCHAR), 2018 2157 &length); 2019 2158 if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) 2020 2159 #ifdef UNICODE 2021 hasMultiResultSets = QString(reinterpret_cast<const QChar*>(driverResponse), length/sizeof(QChar)).startsWith(QLatin1Char('Y'));2160 hasMultiResultSets = fromSQLTCHAR(driverResponse, length/sizeof(SQLTCHAR)).startsWith(QLatin1Char('Y')); 2022 2161 #else 2023 hasMultiResultSets = QString::from Local8Bit(driverResponse, length).startsWith(QLatin1Char('Y'));2162 hasMultiResultSets = QString::fromUtf8((const char *)driverResponse.constData(), length).startsWith(QLatin1Char('Y')); 2024 2163 #endif 2025 2164 } … … 2135 2274 0, 2136 2275 #ifdef UNICODE 2137 (SQLWCHAR*)joinedTableTypeString.unicode(),2276 toSQLTCHAR(joinedTableTypeString).data(), 2138 2277 #else 2139 (SQLCHAR*)joinedTableTypeString.to Latin1().constData(),2278 (SQLCHAR*)joinedTableTypeString.toUtf8().data(), 2140 2279 #endif 2141 2280 joinedTableTypeString.length() /* characters, not bytes */); … … 2150 2289 else 2151 2290 r = SQLFetch(hStmt); 2291 2292 if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO && r != SQL_NO_DATA) { 2293 qWarning() << "QODBCDriver::tables failed to retrieve table/view list: (" << r << "," << qWarnODBCHandle(SQL_HANDLE_STMT, hStmt) << ")"; 2294 return QStringList(); 2295 } 2152 2296 2153 2297 while (r == SQL_SUCCESS) { … … 2209 2353 r = SQLPrimaryKeys(hStmt, 2210 2354 #ifdef UNICODE 2211 catalog.length() == 0 ? NULL : (SQLWCHAR*)catalog.unicode(),2355 catalog.length() == 0 ? NULL : toSQLTCHAR(catalog).data(), 2212 2356 #else 2213 catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.to Latin1().constData(),2357 catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toUtf8().data(), 2214 2358 #endif 2215 2359 catalog.length(), 2216 2360 #ifdef UNICODE 2217 schema.length() == 0 ? NULL : (SQLWCHAR*)schema.unicode(),2361 schema.length() == 0 ? NULL : toSQLTCHAR(schema).data(), 2218 2362 #else 2219 schema.length() == 0 ? NULL : (SQLCHAR*)schema.to Latin1().constData(),2363 schema.length() == 0 ? NULL : (SQLCHAR*)schema.toUtf8().data(), 2220 2364 #endif 2221 2365 schema.length(), 2222 2366 #ifdef UNICODE 2223 (SQLWCHAR*)table.unicode(),2367 toSQLTCHAR(table).data(), 2224 2368 #else 2225 (SQLCHAR*)table.to Latin1().constData(),2369 (SQLCHAR*)table.toUtf8().data(), 2226 2370 #endif 2227 2371 table.length() /* in characters, not in bytes */); … … 2234 2378 SQL_BEST_ROWID, 2235 2379 #ifdef UNICODE 2236 catalog.length() == 0 ? NULL : (SQLWCHAR*)catalog.unicode(),2380 catalog.length() == 0 ? NULL : toSQLTCHAR(catalog).data(), 2237 2381 #else 2238 catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.to Latin1().constData(),2382 catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toUtf8().data(), 2239 2383 #endif 2240 2384 catalog.length(), 2241 2385 #ifdef UNICODE 2242 schema.length() == 0 ? NULL : (SQLWCHAR*)schema.unicode(),2386 schema.length() == 0 ? NULL : toSQLTCHAR(schema).data(), 2243 2387 #else 2244 schema.length() == 0 ? NULL : (SQLCHAR*)schema.to Latin1().constData(),2388 schema.length() == 0 ? NULL : (SQLCHAR*)schema.toUtf8().data(), 2245 2389 #endif 2246 2390 schema.length(), 2247 2391 #ifdef UNICODE 2248 (SQLWCHAR*)table.unicode(),2392 toSQLTCHAR(table).data(), 2249 2393 #else 2250 (SQLCHAR*)table.to Latin1().constData(),2394 (SQLCHAR*)table.toUtf8().data(), 2251 2395 #endif 2252 2396 table.length(), … … 2334 2478 r = SQLColumns(hStmt, 2335 2479 #ifdef UNICODE 2336 catalog.length() == 0 ? NULL : (SQLWCHAR*)catalog.unicode(),2480 catalog.length() == 0 ? NULL : toSQLTCHAR(catalog).data(), 2337 2481 #else 2338 catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.to Latin1().constData(),2482 catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toUtf8().data(), 2339 2483 #endif 2340 2484 catalog.length(), 2341 2485 #ifdef UNICODE 2342 schema.length() == 0 ? NULL : (SQLWCHAR*)schema.unicode(),2486 schema.length() == 0 ? NULL : toSQLTCHAR(schema).data(), 2343 2487 #else 2344 schema.length() == 0 ? NULL : (SQLCHAR*)schema.to Latin1().constData(),2488 schema.length() == 0 ? NULL : (SQLCHAR*)schema.toUtf8().data(), 2345 2489 #endif 2346 2490 schema.length(), 2347 2491 #ifdef UNICODE 2348 (SQLWCHAR*)table.unicode(),2492 toSQLTCHAR(table).data(), 2349 2493 #else 2350 (SQLCHAR*)table.to Latin1().constData(),2494 (SQLCHAR*)table.toUtf8().data(), 2351 2495 #endif 2352 2496 table.length(), -
trunk/src/sql/drivers/odbc/qsql_odbc.h
r651 r769 74 74 #if defined(Q_CC_BOR) 75 75 # undef _MSC_VER 76 #endif77 78 #ifndef Q_ODBC_VERSION_279 #include <sqlucode.h>80 76 #endif 81 77
Note:
See TracChangeset
for help on using the changeset viewer.