Changeset 561 for trunk/src/sql/drivers/ibase
- 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/ibase/qsql_ibase.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 ** … … 56 56 #include <math.h> 57 57 #include <qdebug.h> 58 #include <QVarLengthArray> 58 59 59 60 QT_BEGIN_NAMESPACE … … 67 68 enum { QIBaseChunkSize = SHRT_MAX / 2 }; 68 69 69 static bool getIBaseError(QString& msg, ISC_STATUS* status, ISC_LONG &sqlcode, 70 QTextCodec *tc) 70 #if defined(FB_API_VER) && FB_API_VER >= 20 71 static bool getIBaseError(QString& msg, const ISC_STATUS* status, ISC_LONG &sqlcode, QTextCodec *tc) 72 #else 73 static bool getIBaseError(QString& msg, ISC_STATUS* status, ISC_LONG &sqlcode, QTextCodec *tc) 74 #endif 71 75 { 72 76 if (status[0] != 1 || status[1] <= 0) … … 76 80 sqlcode = isc_sqlcode(status); 77 81 char buf[512]; 82 #if defined(FB_API_VER) && FB_API_VER >= 20 83 while(fb_interpret(buf, 512, &status)) { 84 #else 78 85 while(isc_interprete(buf, &status)) { 86 #endif 79 87 if(!msg.isEmpty()) 80 88 msg += QLatin1String(" - "); … … 90 98 { 91 99 sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(1)); 100 if (sqlda == (XSQLDA*)0) return; 92 101 sqlda->sqln = 1; 93 102 sqlda->sqld = 0; … … 99 108 static void enlargeDA(XSQLDA *&sqlda, int n) 100 109 { 101 free(sqlda); 110 if (sqlda != (XSQLDA*)0) 111 free(sqlda); 102 112 sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(n)); 113 if (sqlda == (XSQLDA*)0) return; 103 114 sqlda->sqln = n; 104 115 sqlda->version = SQLDA_CURRENT_VERSION; … … 119 130 case SQL_TEXT: 120 131 case SQL_BLOB: 121 sqlda->sqlvar[i].sqldata = (char*)malloc(sqlda->sqlvar[i].sqllen);132 sqlda->sqlvar[i].sqldata = new char[sqlda->sqlvar[i].sqllen]; 122 133 break; 123 134 case SQL_ARRAY: 124 sqlda->sqlvar[i].sqldata = (char*)malloc(sizeof(ISC_QUAD));135 sqlda->sqlvar[i].sqldata = new char[sizeof(ISC_QUAD)]; 125 136 memset(sqlda->sqlvar[i].sqldata, 0, sizeof(ISC_QUAD)); 126 137 break; 127 138 case SQL_VARYING: 128 sqlda->sqlvar[i].sqldata = (char*)malloc(sqlda->sqlvar[i].sqllen + sizeof(short));139 sqlda->sqlvar[i].sqldata = new char[sqlda->sqlvar[i].sqllen + sizeof(short)]; 129 140 break; 130 141 default: … … 134 145 } 135 146 if (sqlda->sqlvar[i].sqltype & 1) { 136 sqlda->sqlvar[i].sqlind = (short*)malloc(sizeof(short));147 sqlda->sqlvar[i].sqlind = new short[1]; 137 148 *(sqlda->sqlvar[i].sqlind) = 0; 138 149 } else { … … 147 158 return; 148 159 for (int i = 0; i < sqlda->sqld; ++i) { 149 free(sqlda->sqlvar[i].sqlind);150 free(sqlda->sqlvar[i].sqldata);160 delete [] sqlda->sqlvar[i].sqlind; 161 delete [] sqlda->sqlvar[i].sqldata; 151 162 } 152 163 free(sqlda); … … 293 304 ISC_LONG bufferLength; 294 305 ISC_LONG eventId; 295 306 296 307 enum QIBaseSubscriptionState { Starting, Subscribed, Finished }; 297 308 QIBaseSubscriptionState subscriptionState; … … 444 455 ba.resize(read); 445 456 446 bool isErr = (status[1] == isc_segstr_eof ? false : 447 isError(QT_TRANSLATE_NOOP("QIBaseResult", 457 bool isErr = (status[1] == isc_segstr_eof ? false : 458 isError(QT_TRANSLATE_NOOP("QIBaseResult", 448 459 "Unable to read BLOB"), 449 460 QSqlError::StatementError)); … … 512 523 else 513 524 valList.append(QString::fromUtf8(buffer, o)); 514 525 515 526 buffer += strLen; 516 527 } … … 577 588 int arraySize = 1, subArraySize; 578 589 short dimensions = desc.array_desc_dimensions; 579 short *numElements = new short[dimensions];590 QVarLengthArray<short> numElements(dimensions); 580 591 581 592 for(int i = 0; i < dimensions; ++i) { … … 606 617 return list; 607 618 608 readArrayBuffer(list, ba.data(), 0, numElements, &desc, tc); 609 610 delete[] numElements; 619 readArrayBuffer(list, ba.data(), 0, numElements.data(), &desc, tc); 611 620 612 621 return QVariant(list); … … 639 648 } 640 649 641 static char* qFillBufferWithString(char *buffer, const QString& string, 642 short buflen, bool varying, bool array, 650 static char* qFillBufferWithString(char *buffer, const QString& string, 651 short buflen, bool varying, bool array, 643 652 QTextCodec *tc) 644 653 { … … 872 881 bool QIBaseResult::prepare(const QString& query) 873 882 { 874 //qDebug("prepare: %s\n", qPrintable(query));883 // qDebug("prepare: %s", qPrintable(query)); 875 884 if (!driver() || !driver()->isOpen() || driver()->isOpenError()) 876 885 return false; … … 880 889 881 890 createDA(d->sqlda); 891 if (d->sqlda == (XSQLDA*)0) { 892 qWarning()<<"QIOBaseResult: createDA(): failed to allocate memory"; 893 return false; 894 } 895 882 896 createDA(d->inda); 897 if (d->inda == (XSQLDA*)0){ 898 qWarning()<<"QIOBaseResult: createDA(): failed to allocate memory"; 899 return false; 900 } 883 901 884 902 if (!d->transaction()) … … 901 919 if (d->inda->sqld > d->inda->sqln) { 902 920 enlargeDA(d->inda, d->inda->sqld); 921 if (d->inda == (XSQLDA*)0) { 922 qWarning()<<"QIOBaseResult: enlargeDA(): failed to allocate memory"; 923 return false; 924 } 903 925 904 926 isc_dsql_describe_bind(d->status, &d->stmt, FBVERSION, d->inda); … … 911 933 // need more field descriptors 912 934 enlargeDA(d->sqlda, d->sqlda->sqld); 935 if (d->sqlda == (XSQLDA*)0) { 936 qWarning()<<"QIOBaseResult: enlargeDA(): failed to allocate memory"; 937 return false; 938 } 913 939 914 940 isc_dsql_describe(d->status, &d->stmt, FBVERSION, d->sqlda); … … 978 1004 case SQL_LONG: 979 1005 if (d->inda->sqlvar[para].sqlscale < 0) 980 *((long*)d->inda->sqlvar[para].sqldata) = 1006 *((long*)d->inda->sqlvar[para].sqldata) = 981 1007 (long)floor(0.5 + val.toDouble() * pow(10.0, d->inda->sqlvar[para].sqlscale * -1)); 982 1008 else … … 985 1011 case SQL_SHORT: 986 1012 if (d->inda->sqlvar[para].sqlscale < 0) 987 *((short*)d->inda->sqlvar[para].sqldata) = 1013 *((short*)d->inda->sqlvar[para].sqldata) = 988 1014 (short)floor(0.5 + val.toDouble() * pow(10.0, d->inda->sqlvar[para].sqlscale * -1)); 989 1015 else … … 1026 1052 1027 1053 if (ok) { 1028 if (colCount() ) {1054 if (colCount() && d->queryType != isc_info_sql_stmt_exec_procedure) { 1029 1055 isc_dsql_free_statement(d->status, &d->stmt, DSQL_close); 1030 1056 if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", "Unable to close statement"))) … … 1040 1066 1041 1067 // Not all stored procedures necessarily return values. 1042 if (d->queryType == isc_info_sql_stmt_exec_procedure && d->sqlda ->sqld == 0)1068 if (d->queryType == isc_info_sql_stmt_exec_procedure && d->sqlda && d->sqlda->sqld == 0) 1043 1069 delDA(d->sqlda); 1044 1070 … … 1098 1124 QVariant v; 1099 1125 v.convert(qIBaseTypeName2(d->sqlda->sqlvar[i].sqltype, d->sqlda->sqlvar[i].sqlscale < 0)); 1126 if(v.type() == QVariant::Double) { 1127 switch(numericalPrecisionPolicy()) { 1128 case QSql::LowPrecisionInt32: 1129 v.convert(QVariant::Int); 1130 break; 1131 case QSql::LowPrecisionInt64: 1132 v.convert(QVariant::LongLong); 1133 break; 1134 case QSql::HighPrecision: 1135 v.convert(QVariant::String); 1136 break; 1137 } 1138 } 1100 1139 row[idx] = v; 1101 1140 continue; … … 1162 1201 row[idx] = QVariant(); 1163 1202 break; 1203 } 1204 if (d->sqlda->sqlvar[i].sqlscale < 0) { 1205 QVariant v = row[idx]; 1206 switch(numericalPrecisionPolicy()) { 1207 case QSql::LowPrecisionInt32: 1208 if(v.convert(QVariant::Int)) 1209 row[idx]=v; 1210 break; 1211 case QSql::LowPrecisionInt64: 1212 if(v.convert(QVariant::LongLong)) 1213 row[idx]=v; 1214 break; 1215 case QSql::LowPrecisionDouble: 1216 if(v.convert(QVariant::Double)) 1217 row[idx]=v; 1218 break; 1219 case QSql::HighPrecision: 1220 if(v.convert(QVariant::String)) 1221 row[idx]=v; 1222 break; 1223 } 1164 1224 } 1165 1225 } … … 1237 1297 cCountType = isc_info_req_insert_count; 1238 1298 break; 1299 default: 1300 qWarning() << "numRowsAffected: Unknown statement type (" << d->queryType << ")"; 1301 return -1; 1239 1302 } 1240 1303 … … 1271 1334 QSqlField f(QString::fromLatin1(v.aliasname, v.aliasname_length).simplified(), 1272 1335 qIBaseTypeName2(v.sqltype, v.sqlscale < 0)); 1273 QSqlQuery q(new QIBaseResult(d->db)); 1274 q.setForwardOnly(true); 1275 q.exec(QLatin1String("select b.RDB$FIELD_PRECISION, b.RDB$FIELD_SCALE, b.RDB$FIELD_LENGTH, a.RDB$NULL_FLAG " 1276 "FROM RDB$RELATION_FIELDS a, RDB$FIELDS b " 1277 "WHERE b.RDB$FIELD_NAME = a.RDB$FIELD_SOURCE " 1278 "AND a.RDB$RELATION_NAME = '") + QString::fromAscii(v.relname, v.relname_length).toUpper() + QLatin1String("' " 1279 "AND a.RDB$FIELD_NAME = '") + QString::fromAscii(v.sqlname, v.sqlname_length).toUpper() + QLatin1String("' ")); 1280 if(q.first()) { 1281 if(v.sqlscale < 0) { 1282 f.setLength(q.value(0).toInt()); 1283 f.setPrecision(qAbs(q.value(1).toInt())); 1284 } else { 1285 f.setLength(q.value(2).toInt()); 1286 f.setPrecision(0); 1336 f.setLength(v.sqllen); 1337 f.setPrecision(qAbs(v.sqlscale)); 1338 f.setRequiredStatus((v.sqltype & 1) == 0 ? QSqlField::Required : QSqlField::Optional); 1339 if(v.sqlscale < 0) { 1340 QSqlQuery q(new QIBaseResult(d->db)); 1341 q.setForwardOnly(true); 1342 q.exec(QLatin1String("select b.RDB$FIELD_PRECISION, b.RDB$FIELD_SCALE, b.RDB$FIELD_LENGTH, a.RDB$NULL_FLAG " 1343 "FROM RDB$RELATION_FIELDS a, RDB$FIELDS b " 1344 "WHERE b.RDB$FIELD_NAME = a.RDB$FIELD_SOURCE " 1345 "AND a.RDB$RELATION_NAME = '") + QString::fromAscii(v.relname, v.relname_length).toUpper() + QLatin1String("' " 1346 "AND a.RDB$FIELD_NAME = '") + QString::fromAscii(v.sqlname, v.sqlname_length).toUpper() + QLatin1String("' ")); 1347 if(q.first()) { 1348 if(v.sqlscale < 0) { 1349 f.setLength(q.value(0).toInt()); 1350 f.setPrecision(qAbs(q.value(1).toInt())); 1351 } else { 1352 f.setLength(q.value(2).toInt()); 1353 f.setPrecision(0); 1354 } 1355 f.setRequiredStatus(q.value(3).toBool() ? QSqlField::Required : QSqlField::Optional); 1287 1356 } 1288 f.setRequiredStatus(q.value(3).toBool() ? QSqlField::Required : QSqlField::Optional);1289 }1290 else {1291 f.setLength(0);1292 f.setPrecision(0);1293 f.setRequiredStatus(QSqlField::Unknown);1294 1357 } 1295 1358 f.setSqlType(v.sqltype); … … 1334 1397 case BatchOperations: 1335 1398 case SimpleLocking: 1336 case LowPrecisionNumbers:1337 1399 case FinishQuery: 1338 1400 case MultipleResultSets: … … 1344 1406 case BLOB: 1345 1407 case EventNotifications: 1408 case LowPrecisionNumbers: 1346 1409 return true; 1347 1410 } … … 1553 1616 QSqlQuery q(createResult()); 1554 1617 q.setForwardOnly(true); 1555 1618 QString table = tablename; 1619 if (isIdentifierEscaped(table, QSqlDriver::TableName)) 1620 table = stripDelimiters(table, QSqlDriver::TableName); 1621 else 1622 table = table.toUpper(); 1556 1623 q.exec(QLatin1String("SELECT a.RDB$FIELD_NAME, b.RDB$FIELD_TYPE, b.RDB$FIELD_LENGTH, " 1557 1624 "b.RDB$FIELD_SCALE, b.RDB$FIELD_PRECISION, a.RDB$NULL_FLAG " 1558 1625 "FROM RDB$RELATION_FIELDS a, RDB$FIELDS b " 1559 1626 "WHERE b.RDB$FIELD_NAME = a.RDB$FIELD_SOURCE " 1560 "AND a.RDB$RELATION_NAME = '") + table name.toUpper()+ QLatin1String("' "1627 "AND a.RDB$RELATION_NAME = '") + table + QLatin1String("' " 1561 1628 "ORDER BY a.RDB$FIELD_POSITION")); 1562 1629 … … 1586 1653 return index; 1587 1654 1655 QString tablename = table; 1656 if (isIdentifierEscaped(tablename, QSqlDriver::TableName)) 1657 tablename = stripDelimiters(tablename, QSqlDriver::TableName); 1658 else 1659 tablename = tablename.toUpper(); 1660 1588 1661 QSqlQuery q(createResult()); 1589 1662 q.setForwardOnly(true); … … 1591 1664 "FROM RDB$RELATION_CONSTRAINTS a, RDB$INDEX_SEGMENTS b, RDB$RELATION_FIELDS c, RDB$FIELDS d " 1592 1665 "WHERE a.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY' " 1593 "AND a.RDB$RELATION_NAME = '") + table .toUpper()+1666 "AND a.RDB$RELATION_NAME = '") + tablename + 1594 1667 QLatin1String(" 'AND a.RDB$INDEX_NAME = b.RDB$INDEX_NAME " 1595 1668 "AND c.RDB$RELATION_NAME = a.RDB$RELATION_NAME " … … 1668 1741 QIBaseDriver *driver = qBufferDriverMap()->value(result); 1669 1742 qMutex()->unlock(); 1670 1743 1671 1744 // We use an asynchronous call (i.e., queued connection) because the event callback 1672 1745 // is executed in a different thread than the one in which the driver lives. … … 1717 1790 1718 1791 if (status[0] == 1 && status[1]) { 1719 setLastError(QSqlError(QString (QLatin1String("Could not subscribe to event notifications for %1.")).arg(name)));1792 setLastError(QSqlError(QString::fromLatin1("Could not subscribe to event notifications for %1.").arg(name))); 1720 1793 d->eventBuffers.remove(name); 1721 1794 qFreeEventBuffer(eBuffer); … … 1745 1818 1746 1819 if (status[0] == 1 && status[1]) { 1747 setLastError(QSqlError(QString (QLatin1String("Could not unsubscribe from event notifications for %1.")).arg(name)));1820 setLastError(QSqlError(QString::fromLatin1("Could not unsubscribe from event notifications for %1.").arg(name))); 1748 1821 return false; 1749 1822 } … … 1803 1876 { 1804 1877 QString res = identifier; 1805 if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) {1878 if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) { 1806 1879 res.replace(QLatin1Char('"'), QLatin1String("\"\"")); 1807 1880 res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); -
trunk/src/sql/drivers/ibase/qsql_ibase.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.