diff options
author | axis <qt-info@nokia.com> | 2009-06-29 12:25:09 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-06-29 12:25:09 (GMT) |
commit | 1a8c89e9eaec05e9f38eae4fbc007d8344015de3 (patch) | |
tree | d87e517cfab9443926841b3ef92ca715a717f54a /src/sql | |
parent | 78166d5235a5045fdc887febe01d789cac333bb3 (diff) | |
parent | b6171cfbe3b1453a2c46f78db0df4819e4e5e54f (diff) | |
download | Qt-1a8c89e9eaec05e9f38eae4fbc007d8344015de3.zip Qt-1a8c89e9eaec05e9f38eae4fbc007d8344015de3.tar.gz Qt-1a8c89e9eaec05e9f38eae4fbc007d8344015de3.tar.bz2 |
Merge branch '4.5' of git@scm.dev.nokia.troll.no:qt/qt
Conflicts:
.gitignore
src/gui/dialogs/qfiledialog_p.h
src/gui/painting/qpaintengine_raster.cpp
src/gui/text/qfontdatabase.cpp
tests/auto/network-settings.h
tests/auto/qitemdelegate/tst_qitemdelegate.cpp
Diffstat (limited to 'src/sql')
50 files changed, 243 insertions, 680 deletions
diff --git a/src/sql/drivers/db2/qsql_db2.cpp b/src/sql/drivers/db2/qsql_db2.cpp index 11d0041..3009eed 100644 --- a/src/sql/drivers/db2/qsql_db2.cpp +++ b/src/sql/drivers/db2/qsql_db2.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -1182,7 +1182,7 @@ QDB2Driver::~QDB2Driver() delete d; } -bool QDB2Driver::open(const QString& db, const QString& user, const QString& password, const QString& host, int port, +bool QDB2Driver::open(const QString& db, const QString& user, const QString& password, const QString&, int, const QString& connOpts) { if (isOpen()) @@ -1205,8 +1205,6 @@ bool QDB2Driver::open(const QString& db, const QString& user, const QString& pas setOpenError(true); return false; } - - QString protocol; // Set connection attributes const QStringList opts(connOpts.split(QLatin1Char(';'), QString::SkipEmptyParts)); for (int i = 0; i < opts.count(); ++i) { @@ -1237,10 +1235,7 @@ bool QDB2Driver::open(const QString& db, const QString& user, const QString& pas } else if (opt == QLatin1String("SQL_ATTR_LOGIN_TIMEOUT")) { v = val.toUInt(); r = SQLSetConnectAttr(d->hDbc, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER) v, 0); - } else if (opt.compare(QLatin1String("PROTOCOL"), Qt::CaseInsensitive) == 0) { - protocol = tmp; - } - else { + } else { qWarning("QDB2Driver::open: Unknown connection attribute '%s'", tmp.toLocal8Bit().constData()); } @@ -1249,18 +1244,9 @@ bool QDB2Driver::open(const QString& db, const QString& user, const QString& pas "Unable to set connection attribute '%1'").arg(opt), d); } - if (protocol.isEmpty()) - protocol = QLatin1String("PROTOCOL=TCPIP"); - - if (port < 0 ) - port = 50000; - QString connQStr; - connQStr = protocol + QLatin1String(";DATABASE=") + db + QLatin1String(";HOSTNAME=") + host - + QLatin1String(";PORT=") + QString::number(port) + QLatin1String(";UID=") + user - + QLatin1String(";PWD=") + password; - - + connQStr = QLatin1String("DSN=") + db + QLatin1String(";UID=") + user + QLatin1String(";PWD=") + + password; SQLTCHAR connOut[SQL_MAX_OPTION_STRING_LENGTH]; SQLSMALLINT cb; @@ -1279,7 +1265,7 @@ bool QDB2Driver::open(const QString& db, const QString& user, const QString& pas return false; } - d->user = user; + d->user = user.toUpper(); setOpen(true); setOpenError(false); return true; @@ -1324,25 +1310,10 @@ QSqlRecord QDB2Driver::record(const QString& tableName) const SQLHANDLE hStmt; QString catalog, schema, table; - qSplitTableQualifier(tableName, &catalog, &schema, &table); + qSplitTableQualifier(tableName.toUpper(), &catalog, &schema, &table); if (schema.isEmpty()) schema = d->user; - if (isIdentifierEscaped(catalog, QSqlDriver::TableName)) - catalog = stripDelimiters(catalog, QSqlDriver::TableName); - else - catalog = catalog.toUpper(); - - if (isIdentifierEscaped(schema, QSqlDriver::TableName)) - schema = stripDelimiters(schema, QSqlDriver::TableName); - else - schema = schema.toUpper(); - - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - else - table = table.toUpper(); - SQLRETURN r = SQLAllocHandle(SQL_HANDLE_STMT, d->hDbc, &hStmt); @@ -1356,9 +1327,6 @@ QSqlRecord QDB2Driver::record(const QString& tableName) const (SQLPOINTER) SQL_CURSOR_FORWARD_ONLY, SQL_IS_UINTEGER); - - //Aside: szSchemaName and szTableName parameters of SQLColumns - //are case sensitive search patterns, so no escaping is used. r = SQLColumns(hStmt, NULL, 0, @@ -1439,13 +1407,7 @@ QStringList QDB2Driver::tables(QSql::TableType type) const bool isNull; QString fieldVal = qGetStringData(hStmt, 2, -1, isNull); QString userVal = qGetStringData(hStmt, 1, -1, isNull); - QString user = d->user; - if ( isIdentifierEscaped(user, QSqlDriver::TableName)) - user = stripDelimiters(user, QSqlDriver::TableName); - else - user = user.toUpper(); - - if (userVal != user) + if (userVal != d->user) fieldVal = userVal + QLatin1Char('.') + fieldVal; tl.append(fieldVal); r = SQLFetchScroll(hStmt, @@ -1476,23 +1438,7 @@ QSqlIndex QDB2Driver::primaryIndex(const QString& tablename) const return index; } QString catalog, schema, table; - qSplitTableQualifier(tablename, &catalog, &schema, &table); - - if (isIdentifierEscaped(catalog, QSqlDriver::TableName)) - catalog = stripDelimiters(catalog, QSqlDriver::TableName); - else - catalog = catalog.toUpper(); - - if (isIdentifierEscaped(schema, QSqlDriver::TableName)) - schema = stripDelimiters(schema, QSqlDriver::TableName); - else - schema = schema.toUpper(); - - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - else - table = table.toUpper(); - + qSplitTableQualifier(tablename.toUpper(), &catalog, &schema, &table); r = SQLSetStmtAttr(hStmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)SQL_CURSOR_FORWARD_ONLY, diff --git a/src/sql/drivers/db2/qsql_db2.h b/src/sql/drivers/db2/qsql_db2.h index 6923027..2ab63cc 100644 --- a/src/sql/drivers/db2/qsql_db2.h +++ b/src/sql/drivers/db2/qsql_db2.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/drivers/ibase/qsql_ibase.cpp b/src/sql/drivers/ibase/qsql_ibase.cpp index 1645555..0033418 100644 --- a/src/sql/drivers/ibase/qsql_ibase.cpp +++ b/src/sql/drivers/ibase/qsql_ibase.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -97,6 +97,7 @@ static bool getIBaseError(QString& msg, ISC_STATUS* status, ISC_LONG &sqlcode, Q static void createDA(XSQLDA *&sqlda) { sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(1)); + if (sqlda == (XSQLDA*)0) return; sqlda->sqln = 1; sqlda->sqld = 0; sqlda->version = SQLDA_CURRENT_VERSION; @@ -106,8 +107,10 @@ static void createDA(XSQLDA *&sqlda) static void enlargeDA(XSQLDA *&sqlda, int n) { - free(sqlda); + if (sqlda != (XSQLDA*)0) + free(sqlda); sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(n)); + if (sqlda == (XSQLDA*)0) return; sqlda->sqln = n; sqlda->version = SQLDA_CURRENT_VERSION; } @@ -126,14 +129,14 @@ static void initDA(XSQLDA *sqlda) case SQL_TYPE_DATE: case SQL_TEXT: case SQL_BLOB: - sqlda->sqlvar[i].sqldata = (char*)malloc(sqlda->sqlvar[i].sqllen); + sqlda->sqlvar[i].sqldata = new char[sqlda->sqlvar[i].sqllen]; break; case SQL_ARRAY: - sqlda->sqlvar[i].sqldata = (char*)malloc(sizeof(ISC_QUAD)); + sqlda->sqlvar[i].sqldata = new char[sizeof(ISC_QUAD)]; memset(sqlda->sqlvar[i].sqldata, 0, sizeof(ISC_QUAD)); break; case SQL_VARYING: - sqlda->sqlvar[i].sqldata = (char*)malloc(sqlda->sqlvar[i].sqllen + sizeof(short)); + sqlda->sqlvar[i].sqldata = new char[sqlda->sqlvar[i].sqllen + sizeof(short)]; break; default: // not supported - do not bind. @@ -141,7 +144,7 @@ static void initDA(XSQLDA *sqlda) break; } if (sqlda->sqlvar[i].sqltype & 1) { - sqlda->sqlvar[i].sqlind = (short*)malloc(sizeof(short)); + sqlda->sqlvar[i].sqlind = new short[1]; *(sqlda->sqlvar[i].sqlind) = 0; } else { sqlda->sqlvar[i].sqlind = 0; @@ -154,8 +157,8 @@ static void delDA(XSQLDA *&sqlda) if (!sqlda) return; for (int i = 0; i < sqlda->sqld; ++i) { - free(sqlda->sqlvar[i].sqlind); - free(sqlda->sqlvar[i].sqldata); + delete [] sqlda->sqlvar[i].sqlind; + delete [] sqlda->sqlvar[i].sqldata; } free(sqlda); sqlda = 0; @@ -300,7 +303,7 @@ struct QIBaseEventBuffer { #endif ISC_LONG bufferLength; ISC_LONG eventId; - + enum QIBaseSubscriptionState { Starting, Subscribed, Finished }; QIBaseSubscriptionState subscriptionState; }; @@ -451,8 +454,8 @@ QVariant QIBaseResultPrivate::fetchBlob(ISC_QUAD *bId) } ba.resize(read); - bool isErr = (status[1] == isc_segstr_eof ? false : - isError(QT_TRANSLATE_NOOP("QIBaseResult", + bool isErr = (status[1] == isc_segstr_eof ? false : + isError(QT_TRANSLATE_NOOP("QIBaseResult", "Unable to read BLOB"), QSqlError::StatementError)); @@ -519,7 +522,7 @@ static char* readArrayBuffer(QList<QVariant>& list, char *buffer, short curDim, valList.append(tc->toUnicode(buffer, o)); else valList.append(QString::fromUtf8(buffer, o)); - + buffer += strLen; } break; } @@ -644,8 +647,8 @@ char* fillList<float>(char *buffer, const QList<QVariant> &list, float*) return buffer; } -static char* qFillBufferWithString(char *buffer, const QString& string, - short buflen, bool varying, bool array, +static char* qFillBufferWithString(char *buffer, const QString& string, + short buflen, bool varying, bool array, QTextCodec *tc) { QByteArray str = encodeString(tc, string); // keep a copy of the string alive in this scope @@ -885,7 +888,16 @@ bool QIBaseResult::prepare(const QString& query) setAt(QSql::BeforeFirstRow); createDA(d->sqlda); + if (d->sqlda == (XSQLDA*)0) { + qWarning()<<"QIOBaseResult: createDA(): failed to allocate memory"; + return false; + } + createDA(d->inda); + if (d->inda == (XSQLDA*)0){ + qWarning()<<"QIOBaseResult: createDA(): failed to allocate memory"; + return false; + } if (!d->transaction()) return false; @@ -906,6 +918,10 @@ bool QIBaseResult::prepare(const QString& query) return false; if (d->inda->sqld > d->inda->sqln) { enlargeDA(d->inda, d->inda->sqld); + if (d->inda == (XSQLDA*)0) { + qWarning()<<"QIOBaseResult: enlargeDA(): failed to allocate memory"; + return false; + } isc_dsql_describe_bind(d->status, &d->stmt, FBVERSION, d->inda); if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", @@ -916,6 +932,10 @@ bool QIBaseResult::prepare(const QString& query) if (d->sqlda->sqld > d->sqlda->sqln) { // need more field descriptors enlargeDA(d->sqlda, d->sqlda->sqld); + if (d->sqlda == (XSQLDA*)0) { + qWarning()<<"QIOBaseResult: enlargeDA(): failed to allocate memory"; + return false; + } isc_dsql_describe(d->status, &d->stmt, FBVERSION, d->sqlda); if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not describe statement"), @@ -983,14 +1003,14 @@ bool QIBaseResult::exec() break; case SQL_LONG: if (d->inda->sqlvar[para].sqlscale < 0) - *((long*)d->inda->sqlvar[para].sqldata) = + *((long*)d->inda->sqlvar[para].sqldata) = (long)floor(0.5 + val.toDouble() * pow(10.0, d->inda->sqlvar[para].sqlscale * -1)); else *((long*)d->inda->sqlvar[para].sqldata) = (long)val.toLongLong(); break; case SQL_SHORT: if (d->inda->sqlvar[para].sqlscale < 0) - *((short*)d->inda->sqlvar[para].sqldata) = + *((short*)d->inda->sqlvar[para].sqldata) = (short)floor(0.5 + val.toDouble() * pow(10.0, d->inda->sqlvar[para].sqlscale * -1)); else *((short*)d->inda->sqlvar[para].sqldata) = (short)val.toInt(); @@ -1558,16 +1578,12 @@ QSqlRecord QIBaseDriver::record(const QString& tablename) const QSqlQuery q(createResult()); q.setForwardOnly(true); - QString table = tablename; - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - else - table = table.toUpper(); + q.exec(QLatin1String("SELECT a.RDB$FIELD_NAME, b.RDB$FIELD_TYPE, b.RDB$FIELD_LENGTH, " "b.RDB$FIELD_SCALE, b.RDB$FIELD_PRECISION, a.RDB$NULL_FLAG " "FROM RDB$RELATION_FIELDS a, RDB$FIELDS b " "WHERE b.RDB$FIELD_NAME = a.RDB$FIELD_SOURCE " - "AND a.RDB$RELATION_NAME = '") + table + QLatin1String("' " + "AND a.RDB$RELATION_NAME = '") + tablename.toUpper() + QLatin1String("' " "ORDER BY a.RDB$FIELD_POSITION")); while (q.next()) { @@ -1595,18 +1611,12 @@ QSqlIndex QIBaseDriver::primaryIndex(const QString &table) const if (!isOpen()) return index; - QString tablename = table; - if (isIdentifierEscaped(tablename, QSqlDriver::TableName)) - tablename = stripDelimiters(tablename, QSqlDriver::TableName); - else - tablename = tablename.toUpper(); - QSqlQuery q(createResult()); q.setForwardOnly(true); q.exec(QLatin1String("SELECT a.RDB$INDEX_NAME, b.RDB$FIELD_NAME, d.RDB$FIELD_TYPE, d.RDB$FIELD_SCALE " "FROM RDB$RELATION_CONSTRAINTS a, RDB$INDEX_SEGMENTS b, RDB$RELATION_FIELDS c, RDB$FIELDS d " "WHERE a.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY' " - "AND a.RDB$RELATION_NAME = '") + tablename + + "AND a.RDB$RELATION_NAME = '") + table.toUpper() + QLatin1String(" 'AND a.RDB$INDEX_NAME = b.RDB$INDEX_NAME " "AND c.RDB$RELATION_NAME = a.RDB$RELATION_NAME " "AND c.RDB$FIELD_NAME = b.RDB$FIELD_NAME " @@ -1683,7 +1693,7 @@ static isc_callback qEventCallback(char *result, short length, char *updated) qMutex()->lock(); QIBaseDriver *driver = qBufferDriverMap()->value(result); qMutex()->unlock(); - + // We use an asynchronous call (i.e., queued connection) because the event callback // is executed in a different thread than the one in which the driver lives. if (driver) diff --git a/src/sql/drivers/ibase/qsql_ibase.h b/src/sql/drivers/ibase/qsql_ibase.h index bf883b9..114120e 100644 --- a/src/sql/drivers/ibase/qsql_ibase.h +++ b/src/sql/drivers/ibase/qsql_ibase.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index 53645c9..dd4127c 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -1342,7 +1342,7 @@ QSqlIndex QMYSQLDriver::primaryIndex(const QString& tablename) const QSqlQuery i(createResult()); QString stmt(QLatin1String("show index from %1;")); QSqlRecord fil = record(tablename); - i.exec(stmt.arg(tablename)); + i.exec(stmt.arg(escapeIdentifier(tablename, QSqlDriver::TableName))); while (i.isActive() && i.next()) { if (i.value(2).toString() == QLatin1String("PRIMARY")) { idx.append(fil.field(i.value(4).toString())); @@ -1357,14 +1357,10 @@ QSqlIndex QMYSQLDriver::primaryIndex(const QString& tablename) const QSqlRecord QMYSQLDriver::record(const QString& tablename) const { - QString table=tablename; - if(isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - QSqlRecord info; if (!isOpen()) return info; - MYSQL_RES* r = mysql_list_fields(d->mysql, table.toLocal8Bit().constData(), 0); + MYSQL_RES* r = mysql_list_fields(d->mysql, tablename.toLocal8Bit().constData(), 0); if (!r) { return info; } @@ -1475,17 +1471,6 @@ QString QMYSQLDriver::escapeIdentifier(const QString &identifier, IdentifierType return res; } -bool QMYSQLDriver::isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const -{ - Q_UNUSED(type); - bool isLeftDelimited = (identifier.left(1) == QString(QLatin1Char('`'))); - bool isRightDelimited = (identifier.right(1) == QString(QLatin1Char('`'))); - if( identifier.size() > 2 && isLeftDelimited && isRightDelimited ) - return true; - else - return false; -} - QT_END_NAMESPACE #include "qsql_mysql.moc"
\ No newline at end of file diff --git a/src/sql/drivers/mysql/qsql_mysql.h b/src/sql/drivers/mysql/qsql_mysql.h index 31d9dcf..78ff746 100644 --- a/src/sql/drivers/mysql/qsql_mysql.h +++ b/src/sql/drivers/mysql/qsql_mysql.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -123,9 +123,6 @@ public: QVariant handle() const; QString escapeIdentifier(const QString &identifier, IdentifierType type) const; -protected Q_SLOTS: - bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const; - protected: bool beginTransaction(); bool commitTransaction(); diff --git a/src/sql/drivers/oci/qsql_oci.cpp b/src/sql/drivers/oci/qsql_oci.cpp index a7031b1..bbbbc22 100644 --- a/src/sql/drivers/oci/qsql_oci.cpp +++ b/src/sql/drivers/oci/qsql_oci.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -2108,7 +2108,7 @@ bool QOCIDriver::open(const QString & db, setOpen(true); setOpenError(false); - d->user = user; + d->user = user.toUpper(); return true; } @@ -2210,15 +2210,8 @@ QStringList QOCIDriver::tables(QSql::TableType type) const "and owner != 'WKSYS'" "and owner != 'CTXSYS'" "and owner != 'WMSYS'")); - - QString user = d->user; - if ( isIdentifierEscaped(user, QSqlDriver::TableName)) - user = stripDelimiters(user, QSqlDriver::TableName); - else - user = user.toUpper(); - while (t.next()) { - if (t.value(0).toString().toUpper() != user.toUpper()) + if (t.value(0).toString().toUpper() != d->user.toUpper()) tl.append(t.value(0).toString() + QLatin1String(".") + t.value(1).toString()); else tl.append(t.value(1).toString()); @@ -2254,10 +2247,10 @@ void qSplitTableAndOwner(const QString & tname, QString * tbl, { int i = tname.indexOf(QLatin1Char('.')); // prefixed with owner? if (i != -1) { - *tbl = tname.right(tname.length() - i - 1); - *owner = tname.left(i); + *tbl = tname.right(tname.length() - i - 1).toUpper(); + *owner = tname.left(i).toUpper(); } else { - *tbl = tname; + *tbl = tname.toUpper(); } } @@ -2273,7 +2266,7 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const QString stmt(QLatin1String("select column_name, data_type, data_length, " "data_precision, data_scale, nullable, data_default%1" "from all_tab_columns " - "where table_name=%2")); + "where upper(table_name)=%2")); if (d->serverVersion >= 9) stmt = stmt.arg(QLatin1String(", char_length ")); else @@ -2281,23 +2274,11 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const bool buildRecordInfo = false; QString table, owner, tmpStmt; qSplitTableAndOwner(tablename, &table, &owner); - - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - else - table = table.toUpper(); - tmpStmt = stmt.arg(QLatin1Char('\'') + table + QLatin1Char('\'')); if (owner.isEmpty()) { owner = d->user; } - - if (isIdentifierEscaped(owner, QSqlDriver::TableName)) - owner = stripDelimiters(owner, QSqlDriver::TableName); - else - owner = owner.toUpper(); - - tmpStmt += QLatin1String(" and owner='") + owner + QLatin1String("'"); + tmpStmt += QLatin1String(" and upper(owner)='") + owner + QLatin1String("'"); t.setForwardOnly(true); t.exec(tmpStmt); if (!t.next()) { // try and see if the tablename is a synonym @@ -2346,23 +2327,11 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const bool buildIndex = false; QString table, owner, tmpStmt; qSplitTableAndOwner(tablename, &table, &owner); - - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - else - table = table.toUpper(); - - tmpStmt = stmt + QLatin1String(" and a.table_name='") + table + QLatin1String("'"); + tmpStmt = stmt + QLatin1String(" and upper(a.table_name)='") + table + QLatin1String("'"); if (owner.isEmpty()) { owner = d->user; } - - if (isIdentifierEscaped(owner, QSqlDriver::TableName)) - owner = stripDelimiters(owner, QSqlDriver::TableName); - else - owner = owner.toUpper(); - - tmpStmt += QLatin1String(" and a.owner='") + owner + QLatin1String("'"); + tmpStmt += QLatin1String(" and upper(a.owner)='") + owner + QLatin1String("'"); t.setForwardOnly(true); t.exec(tmpStmt); @@ -2456,14 +2425,13 @@ QVariant QOCIDriver::handle() const return qVariantFromValue(d->env); } -QString QOCIDriver::escapeIdentifier(const QString &identifier, IdentifierType type) const +QString QOCIDriver::escapeIdentifier(const QString &identifier, IdentifierType /* type */) const { QString res = identifier; - if(!identifier.isEmpty() && !isIdentifierEscaped(identifier, type)) { - res.replace(QLatin1Char('"'), QLatin1String("\"\"")); + res.replace(QLatin1Char('"'), QLatin1String("\"\"")); + if (identifier.indexOf(QLatin1Char(' ')) != -1) res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); - res.replace(QLatin1Char('.'), QLatin1String("\".\"")); - } +// res.replace(QLatin1Char('.'), QLatin1String("\".\"")); return res; } diff --git a/src/sql/drivers/oci/qsql_oci.h b/src/sql/drivers/oci/qsql_oci.h index 069bfdc..8eace7c 100644 --- a/src/sql/drivers/oci/qsql_oci.h +++ b/src/sql/drivers/oci/qsql_oci.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index ee500a0..e0aa9b5 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -86,12 +86,10 @@ static const SQLSMALLINT qParamType[4] = { SQL_PARAM_INPUT, SQL_PARAM_INPUT, SQL class QODBCDriverPrivate { public: - enum DefaultCase{Lower, Mixed, Upper, Sensitive}; QODBCDriverPrivate() : hEnv(0), hDbc(0), useSchema(false), disconnectCount(0), isMySqlServer(false), isMSSqlServer(false), hasSQLFetchScroll(true), hasMultiResultSets(false) { - sql_char_type = sql_varchar_type = sql_longvarchar_type = QVariant::ByteArray; unicode = false; } @@ -100,9 +98,6 @@ public: uint unicode :1; uint useSchema :1; - QVariant::Type sql_char_type; - QVariant::Type sql_varchar_type; - QVariant::Type sql_longvarchar_type; int disconnectCount; bool isMySqlServer; bool isMSSqlServer; @@ -118,9 +113,6 @@ public: bool setConnectionOptions(const QString& connOpts); void splitTableQualifier(const QString &qualifier, QString &catalog, QString &schema, QString &table); - DefaultCase defaultCase() const; - QString adjustCase(const QString&) const; - QChar quoteChar() const; }; class QODBCPrivate @@ -129,7 +121,6 @@ public: QODBCPrivate() : hEnv(0), hDbc(0), hStmt(0), useSchema(false), hasSQLFetchScroll(true), precisionPolicy(QSql::HighPrecision) { - sql_char_type = sql_varchar_type = sql_longvarchar_type = QVariant::ByteArray; unicode = false; } @@ -142,9 +133,6 @@ public: uint unicode :1; uint useSchema :1; - QVariant::Type sql_char_type; - QVariant::Type sql_varchar_type; - QVariant::Type sql_longvarchar_type; QSqlRecord rInf; QVector<QVariant> fieldCache; @@ -295,14 +283,10 @@ static QVariant::Type qDecodeODBCType(SQLSMALLINT sqltype, const T* p, bool isSi break; #endif case SQL_CHAR: - type = p->sql_char_type; - break; case SQL_VARCHAR: case SQL_GUID: - type = p->sql_varchar_type; - break; case SQL_LONGVARCHAR: - type = p->sql_longvarchar_type; + type = QVariant::String; break; default: type = QVariant::ByteArray; @@ -557,28 +541,6 @@ static int qGetODBCVersion(const QString &connOpts) return SQL_OV_ODBC2; } -QChar QODBCDriverPrivate::quoteChar() const -{ - static bool isQuoteInitialized = false; - static QChar quote = QChar::fromLatin1('"'); - if (!isQuoteInitialized) { - char driverResponse[4]; - SQLSMALLINT length; - int r = SQLGetInfo(hDbc, - SQL_IDENTIFIER_QUOTE_CHAR, - &driverResponse, - sizeof(driverResponse), - &length); - if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) { - quote = QChar::fromLatin1(driverResponse[0]); - } else { - quote = QChar::fromLatin1('"'); - } - isQuoteInitialized = true; - } - return quote; -} - bool QODBCDriverPrivate::setConnectionOptions(const QString& connOpts) { // Set any connection attributes @@ -729,65 +691,6 @@ void QODBCDriverPrivate::splitTableQualifier(const QString & qualifier, QString } } -QODBCDriverPrivate::DefaultCase QODBCDriverPrivate::defaultCase() const -{ - static bool isInitialized = false; - static DefaultCase ret; - - if (!isInitialized) { - SQLUSMALLINT casing; - int r = SQLGetInfo(hDbc, - SQL_IDENTIFIER_CASE, - &casing, - sizeof(casing), - NULL); - if ( r != SQL_SUCCESS) - ret = Lower;//arbitrary case if driver cannot be queried - else { - switch (casing) { - case (SQL_IC_UPPER): - ret = Upper; - break; - case (SQL_IC_LOWER): - ret = Lower; - break; - case (SQL_IC_SENSITIVE): - ret = Sensitive; - break; - case (SQL_IC_MIXED): - ret = Mixed; - break; - default: - ret = Upper; - } - } - isInitialized = true; - } - return ret; -} - -/* - Adjust the casing of an identifier to match what the - database engine would have done to it. -*/ -QString QODBCDriverPrivate::adjustCase(const QString &identifier) const -{ - QString ret = identifier; - switch(defaultCase()) { - case (Lower): - ret = identifier.toLower(); - break; - case (Upper): - ret = identifier.toUpper(); - break; - case(Mixed): - case(Sensitive): - default: - ret = identifier; - } - return ret; -} - //////////////////////////////////////////////////////////////////////////// QODBCResult::QODBCResult(const QODBCDriver * db, QODBCDriverPrivate* p) @@ -798,9 +701,6 @@ QODBCResult::QODBCResult(const QODBCDriver * db, QODBCDriverPrivate* p) d->hDbc = p->hDbc; d->unicode = p->unicode; d->useSchema = p->useSchema; - d->sql_char_type = p->sql_char_type; - d->sql_varchar_type = p->sql_varchar_type; - d->sql_longvarchar_type = p->sql_longvarchar_type; d->disconnectCount = p->disconnectCount; d->hasSQLFetchScroll = p->hasSQLFetchScroll; } @@ -1867,7 +1767,6 @@ void QODBCDriverPrivate::checkUnicode() sizeof(fFunc), NULL); if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (fFunc & SQL_CVT_WCHAR)) { - sql_char_type = QVariant::String; unicode = true; } @@ -1877,7 +1776,6 @@ void QODBCDriverPrivate::checkUnicode() sizeof(fFunc), NULL); if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (fFunc & SQL_CVT_WVARCHAR)) { - sql_varchar_type = QVariant::String; unicode = true; } @@ -1887,7 +1785,6 @@ void QODBCDriverPrivate::checkUnicode() sizeof(fFunc), NULL); if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (fFunc & SQL_CVT_WLONGVARCHAR)) { - sql_longvarchar_type = QVariant::String; unicode = true; } } @@ -2171,22 +2068,6 @@ QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const } QString catalog, schema, table; d->splitTableQualifier(tablename, catalog, schema, table); - - if (isIdentifierEscaped(catalog, QSqlDriver::TableName)) - catalog = stripDelimiters(catalog, QSqlDriver::TableName); - else - catalog = d->adjustCase(catalog); - - if (isIdentifierEscaped(schema, QSqlDriver::TableName)) - schema = stripDelimiters(schema, QSqlDriver::TableName); - else - schema = d->adjustCase(schema); - - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - else - table = d->adjustCase(table); - r = SQLSetStmtAttr(hStmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)SQL_CURSOR_FORWARD_ONLY, @@ -2289,22 +2170,6 @@ QSqlRecord QODBCDriver::record(const QString& tablename) const SQLHANDLE hStmt; QString catalog, schema, table; d->splitTableQualifier(tablename, catalog, schema, table); - - if (isIdentifierEscaped(catalog, QSqlDriver::TableName)) - catalog = stripDelimiters(catalog, QSqlDriver::TableName); - else - catalog = d->adjustCase(catalog); - - if (isIdentifierEscaped(schema, QSqlDriver::TableName)) - schema = stripDelimiters(schema, QSqlDriver::TableName); - else - schema = d->adjustCase(schema); - - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - else - table = d->adjustCase(table); - SQLRETURN r = SQLAllocHandle(SQL_HANDLE_STMT, d->hDbc, &hStmt); @@ -2428,15 +2293,4 @@ QString QODBCDriver::escapeIdentifier(const QString &identifier, IdentifierType) return res; } -bool QODBCDriver::isIdentifierEscapedImplementation(const QString &identifier, IdentifierType) const -{ - QString quote = d->quoteChar(); - bool isLeftDelimited = identifier.left(1) == quote; - bool isRightDelimited = identifier.right(1) == quote; - if( identifier.size() > 2 && isLeftDelimited && isRightDelimited ) - return true; - else - return false; -} - QT_END_NAMESPACE diff --git a/src/sql/drivers/odbc/qsql_odbc.h b/src/sql/drivers/odbc/qsql_odbc.h index 51f53ea..936164e 100644 --- a/src/sql/drivers/odbc/qsql_odbc.h +++ b/src/sql/drivers/odbc/qsql_odbc.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -145,14 +145,10 @@ public: QString escapeIdentifier(const QString &identifier, IdentifierType type) const; -protected Q_SLOTS: - bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const; - protected: bool beginTransaction(); bool commitTransaction(); bool rollbackTransaction(); - private: void init(); bool endTrans(); diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp index 16d19f1..770df4c 100644 --- a/src/sql/drivers/psql/qsql_psql.cpp +++ b/src/sql/drivers/psql/qsql_psql.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -534,7 +534,7 @@ bool QPSQLResult::prepare(const QString &query) { if (!d->preparedQueriesEnabled) return QSqlResult::prepare(query); - + cleanup(); if (!d->preparedStmtId.isEmpty()) @@ -824,7 +824,20 @@ bool QPSQLDriver::commitTransaction() return false; } PGresult* res = PQexec(d->connection, "COMMIT"); - if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) { + + bool transaction_failed = false; + + // XXX + // This hack is used to tell if the transaction has succeeded for the protocol versions of + // PostgreSQL below. For 7.x and other protocol versions we are left in the dark. + // This hack can dissapear once there is an API to query this sort of information. + if (d->pro == QPSQLDriver::Version8 || + d->pro == QPSQLDriver::Version81 || + d->pro == QPSQLDriver::Version82) { + transaction_failed = qstrcmp(PQcmdStatus(res), "ROLLBACK") == 0; + } + + if (!res || PQresultStatus(res) != PGRES_COMMAND_OK || transaction_failed) { PQclear(res); setLastError(qMakeError(tr("Could not commit transaction"), QSqlError::TransactionError, d)); @@ -894,16 +907,6 @@ QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const QString schema; qSplitTableName(tbl, schema); - if (isIdentifierEscaped(tbl, QSqlDriver::TableName)) - tbl = stripDelimiters(tbl, QSqlDriver::TableName); - else - tbl = tbl.toLower(); - - if (isIdentifierEscaped(schema, QSqlDriver::TableName)) - schema = stripDelimiters(schema, QSqlDriver::TableName); - else - schema = schema.toLower(); - switch(d->pro) { case QPSQLDriver::Version6: stmt = QLatin1String("select pg_att1.attname, int(pg_att1.atttypid), pg_cl.relname " @@ -936,7 +939,7 @@ QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const "FROM pg_attribute, pg_class " "WHERE %1 pg_class.oid IN " "(SELECT indexrelid FROM pg_index WHERE indisprimary = true AND indrelid IN " - " (SELECT oid FROM pg_class WHERE relname = '%2')) " + " (SELECT oid FROM pg_class WHERE lower(relname) = '%2')) " "AND pg_attribute.attrelid = pg_class.oid " "AND pg_attribute.attisdropped = false " "ORDER BY pg_attribute.attnum"); @@ -944,11 +947,11 @@ QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const stmt = stmt.arg(QLatin1String("pg_table_is_visible(pg_class.oid) AND")); else stmt = stmt.arg(QString::fromLatin1("pg_class.relnamespace = (select oid from " - "pg_namespace where pg_namespace.nspname = '%1') AND ").arg(schema)); + "pg_namespace where pg_namespace.nspname = '%1') AND ").arg(schema.toLower())); break; } - i.exec(stmt.arg(tbl)); + i.exec(stmt.arg(tbl.toLower())); while (i.isActive() && i.next()) { QSqlField f(i.value(0).toString(), qDecodePSQLType(i.value(1).toInt())); idx.append(f); @@ -967,16 +970,6 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const QString schema; qSplitTableName(tbl, schema); - if (isIdentifierEscaped(tbl, QSqlDriver::TableName)) - tbl = stripDelimiters(tbl, QSqlDriver::TableName); - else - tbl = tbl.toLower(); - - if (isIdentifierEscaped(schema, QSqlDriver::TableName)) - schema = stripDelimiters(schema, QSqlDriver::TableName); - else - schema = schema.toLower(); - QString stmt; switch(d->pro) { case QPSQLDriver::Version6: @@ -1021,7 +1014,7 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const "left join pg_attrdef on (pg_attrdef.adrelid = " "pg_attribute.attrelid and pg_attrdef.adnum = pg_attribute.attnum) " "where %1 " - "and pg_class.relname = '%2' " + "and lower(pg_class.relname) = '%2' " "and pg_attribute.attnum > 0 " "and pg_attribute.attrelid = pg_class.oid " "and pg_attribute.attisdropped = false " @@ -1030,12 +1023,12 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const stmt = stmt.arg(QLatin1String("pg_table_is_visible(pg_class.oid)")); else stmt = stmt.arg(QString::fromLatin1("pg_class.relnamespace = (select oid from " - "pg_namespace where pg_namespace.nspname = '%1')").arg(schema)); + "pg_namespace where pg_namespace.nspname = '%1')").arg(schema.toLower())); break; } QSqlQuery query(createResult()); - query.exec(stmt.arg(tbl)); + query.exec(stmt.arg(tbl.toLower())); if (d->pro >= QPSQLDriver::Version71) { while (query.next()) { int len = query.value(3).toInt(); @@ -1192,12 +1185,12 @@ bool QPSQLDriver::subscribeToNotificationImplementation(const QString &name) qPrintable(name)); return false; } - + int socket = PQsocket(d->connection); if (socket) { QString query = QString(QLatin1String("LISTEN %1")).arg(escapeIdentifier(name, QSqlDriver::TableName)); - if (PQresultStatus(PQexec(d->connection, - d->isUtf8 ? query.toUtf8().constData() + if (PQresultStatus(PQexec(d->connection, + d->isUtf8 ? query.toUtf8().constData() : query.toLocal8Bit().constData()) ) != PGRES_COMMAND_OK) { setLastError(qMakeError(tr("Unable to subscribe"), QSqlError::StatementError, d)); @@ -1228,8 +1221,8 @@ bool QPSQLDriver::unsubscribeFromNotificationImplementation(const QString &name) } QString query = QString(QLatin1String("UNLISTEN %1")).arg(escapeIdentifier(name, QSqlDriver::TableName)); - if (PQresultStatus(PQexec(d->connection, - d->isUtf8 ? query.toUtf8().constData() + if (PQresultStatus(PQexec(d->connection, + d->isUtf8 ? query.toUtf8().constData() : query.toLocal8Bit().constData()) ) != PGRES_COMMAND_OK) { setLastError(qMakeError(tr("Unable to unsubscribe"), QSqlError::StatementError, d)); @@ -1262,7 +1255,7 @@ void QPSQLDriver::_q_handleNotification(int) if (d->seid.contains(name)) emit notification(name); else - qWarning("QPSQLDriver: received notification for '%s' which isn't subscribed to.", + qWarning("QPSQLDriver: received notification for '%s' which isn't subscribed to.", qPrintable(name)); qPQfreemem(notify); diff --git a/src/sql/drivers/psql/qsql_psql.h b/src/sql/drivers/psql/qsql_psql.h index ca4dedf..e13add4 100644 --- a/src/sql/drivers/psql/qsql_psql.h +++ b/src/sql/drivers/psql/qsql_psql.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index f732077..8a38f7d 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -661,13 +661,9 @@ QSqlIndex QSQLiteDriver::primaryIndex(const QString &tblname) const if (!isOpen()) return QSqlIndex(); - QString table = tblname; - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - QSqlQuery q(createResult()); q.setForwardOnly(true); - return qGetTableInfo(q, table, true); + return qGetTableInfo(q, tblname, true); } QSqlRecord QSQLiteDriver::record(const QString &tbl) const @@ -675,13 +671,9 @@ QSqlRecord QSQLiteDriver::record(const QString &tbl) const if (!isOpen()) return QSqlRecord(); - QString table = tbl; - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - QSqlQuery q(createResult()); q.setForwardOnly(true); - return qGetTableInfo(q, table); + return qGetTableInfo(q, tbl); } QVariant QSQLiteDriver::handle() const @@ -689,10 +681,10 @@ QVariant QSQLiteDriver::handle() const return qVariantFromValue(d->access); } -QString QSQLiteDriver::escapeIdentifier(const QString &identifier, IdentifierType type) const +QString QSQLiteDriver::escapeIdentifier(const QString &identifier, IdentifierType /*type*/) const { QString res = identifier; - if(!identifier.isEmpty() && !isIdentifierEscaped(identifier, type) ) { + if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) { res.replace(QLatin1Char('"'), QLatin1String("\"\"")); res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); res.replace(QLatin1Char('.'), QLatin1String("\".\"")); diff --git a/src/sql/drivers/sqlite/qsql_sqlite.h b/src/sql/drivers/sqlite/qsql_sqlite.h index 459ea3b..481c2d2 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.h +++ b/src/sql/drivers/sqlite/qsql_sqlite.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp index d0c6e18..76bef08 100644 --- a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp +++ b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -167,15 +167,7 @@ void QSQLite2ResultPrivate::init(const char **cnames, int numCols) for (int i = 0; i < numCols; ++i) { const char* lastDot = strrchr(cnames[i], '.'); const char* fieldName = lastDot ? lastDot + 1 : cnames[i]; - - //remove quotations around the field name if any - QString fieldStr = QString::fromAscii(fieldName); - QString quote = QString::fromLatin1("\""); - if ( fieldStr.length() > 2 && fieldStr.left(1) == quote && fieldStr.right(1) == quote) { - fieldStr = fieldStr.mid(1); - fieldStr.chop(1); - } - rInf.append(QSqlField(fieldStr, + rInf.append(QSqlField(QString::fromAscii(fieldName), nameToType(QString::fromAscii(cnames[i+numCols])))); } } @@ -511,11 +503,8 @@ QSqlIndex QSQLite2Driver::primaryIndex(const QString &tblname) const QSqlQuery q(createResult()); q.setForwardOnly(true); - QString table = tblname; - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); // finrst find a UNIQUE INDEX - q.exec(QLatin1String("PRAGMA index_list('") + table + QLatin1String("');")); + q.exec(QLatin1String("PRAGMA index_list('") + tblname + QLatin1String("');")); QString indexname; while(q.next()) { if (q.value(2).toInt()==1) { @@ -528,7 +517,7 @@ QSqlIndex QSQLite2Driver::primaryIndex(const QString &tblname) const q.exec(QLatin1String("PRAGMA index_info('") + indexname + QLatin1String("');")); - QSqlIndex index(table, indexname); + QSqlIndex index(tblname, indexname); while(q.next()) { QString name = q.value(2).toString(); QVariant::Type type = QVariant::Invalid; @@ -543,9 +532,6 @@ QSqlRecord QSQLite2Driver::record(const QString &tbl) const { if (!isOpen()) return QSqlRecord(); - QString table = tbl; - if (isIdentifierEscaped(tbl, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); QSqlQuery q(createResult()); q.setForwardOnly(true); diff --git a/src/sql/drivers/sqlite2/qsql_sqlite2.h b/src/sql/drivers/sqlite2/qsql_sqlite2.h index 9f039e2..8eb262b 100644 --- a/src/sql/drivers/sqlite2/qsql_sqlite2.h +++ b/src/sql/drivers/sqlite2/qsql_sqlite2.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/drivers/tds/qsql_tds.cpp b/src/sql/drivers/tds/qsql_tds.cpp index 515f0de..d0f440c 100644 --- a/src/sql/drivers/tds/qsql_tds.cpp +++ b/src/sql/drivers/tds/qsql_tds.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -293,8 +293,6 @@ QTDSResult::QTDSResult(const QTDSDriver* db) // insert d in error handler dict errs()->insert(d->dbproc, d); - dbcmd(d->dbproc, "set quoted_identifier on"); - dbsqlexec(d->dbproc); } QTDSResult::~QTDSResult() @@ -369,7 +367,7 @@ bool QTDSResult::gotoNext(QSqlCachedResult::ValueCache &values, int index) if (qIsNull(d->buffer.at(i * 2 + 1))) values[idx] = QVariant(QVariant::String); else - values[idx] = QString::fromLocal8Bit((const char*)d->buffer.at(i * 2)).trimmed(); + values[idx] = QString::fromLocal8Bit((const char*)d->buffer.at(i * 2)); break; case QVariant::ByteArray: { if (qIsNull(d->buffer.at(i * 2 + 1))) @@ -700,14 +698,9 @@ QSqlRecord QTDSDriver::record(const QString& tablename) const return info; QSqlQuery t(createResult()); t.setForwardOnly(true); - - QString table = tablename; - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - QString stmt (QLatin1String("select name, type, length, prec from syscolumns " "where id = (select id from sysobjects where name = '%1')")); - t.exec(stmt.arg(table)); + t.exec(stmt.arg(tablename)); while (t.next()) { QSqlField f(t.value(0).toString().simplified(), qDecodeTDSType(t.value(1).toInt())); f.setLength(t.value(2).toInt()); @@ -777,17 +770,13 @@ QSqlIndex QTDSDriver::primaryIndex(const QString& tablename) const { QSqlRecord rec = record(tablename); - QString table = tablename; - if (isIdentifierEscaped(table, QSqlDriver::TableName)) - table = stripDelimiters(table, QSqlDriver::TableName); - - QSqlIndex idx(table); - if ((!isOpen()) || (table.isEmpty())) + QSqlIndex idx(tablename); + if ((!isOpen()) || (tablename.isEmpty())) return QSqlIndex(); QSqlQuery t(createResult()); t.setForwardOnly(true); - t.exec(QString::fromLatin1("sp_helpindex '%1'").arg(table)); + t.exec(QString::fromLatin1("sp_helpindex '%1'").arg(tablename)); if (t.next()) { QStringList fNames = t.value(2).toString().simplified().split(QLatin1Char(',')); QRegExp regx(QLatin1String("\\s*(\\S+)(?:\\s+(DESC|desc))?\\s*")); diff --git a/src/sql/drivers/tds/qsql_tds.h b/src/sql/drivers/tds/qsql_tds.h index 3a5dc65..817ca54 100644 --- a/src/sql/drivers/tds/qsql_tds.h +++ b/src/sql/drivers/tds/qsql_tds.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsql.h b/src/sql/kernel/qsql.h index 0e3388a..971a152 100644 --- a/src/sql/kernel/qsql.h +++ b/src/sql/kernel/qsql.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlcachedresult.cpp b/src/sql/kernel/qsqlcachedresult.cpp index e85229f..4b094c6 100644 --- a/src/sql/kernel/qsqlcachedresult.cpp +++ b/src/sql/kernel/qsqlcachedresult.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -184,8 +184,11 @@ bool QSqlCachedResult::fetch(int i) if (d->rowCacheEnd > 0) setAt(d->cacheCount()); while (at() < i + 1) { - if (!cacheNext()) + if (!cacheNext()) { + if (d->canSeek(i)) + break; return false; + } } setAt(i); diff --git a/src/sql/kernel/qsqlcachedresult_p.h b/src/sql/kernel/qsqlcachedresult_p.h index 8a4869c..d19435c 100644 --- a/src/sql/kernel/qsqlcachedresult_p.h +++ b/src/sql/kernel/qsqlcachedresult_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp index a270c0e..848f213 100644 --- a/src/sql/kernel/qsqldatabase.cpp +++ b/src/sql/kernel/qsqldatabase.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqldatabase.h b/src/sql/kernel/qsqldatabase.h index ca6f0b0..74e6315 100644 --- a/src/sql/kernel/qsqldatabase.h +++ b/src/sql/kernel/qsqldatabase.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqldriver.cpp b/src/sql/kernel/qsqldriver.cpp index 40bc0df..135ec306 100644 --- a/src/sql/kernel/qsqldriver.cpp +++ b/src/sql/kernel/qsqldriver.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -49,17 +49,6 @@ QT_BEGIN_NAMESPACE -static QString prepareIdentifier(const QString &identifier, - QSqlDriver::IdentifierType type, const QSqlDriver *driver) -{ - Q_ASSERT( driver != NULL ); - QString ret = identifier; - if (!driver->isIdentifierEscaped(identifier, type)) { - ret = driver->escapeIdentifier(identifier, type); - } - return ret; -} - class QSqlDriverPrivate : public QObjectPrivate { public: @@ -383,7 +372,6 @@ QSqlRecord QSqlDriver::record(const QString & /* tableName */) const on \a type. The default implementation does nothing. - \sa isIdentifierEscaped() */ QString QSqlDriver::escapeIdentifier(const QString &identifier, IdentifierType) const { @@ -391,55 +379,6 @@ QString QSqlDriver::escapeIdentifier(const QString &identifier, IdentifierType) } /*! - Returns whether \a identifier is escaped according to the database rules. - \a identifier can either be a table name or field name, dependent - on \a type. - - \warning Because of binary compatability constraints, this function is not virtual. - If you want to provide your own implementation in your QSqlDriver subclass, - reimplement the isIdentifierEscapedImplementation() slot in your subclass instead. - The isIdentifierEscapedFunction() will dynamically detect the slot and call it. - - \sa stripDelimiters(), escapeIdentifier() - */ -bool QSqlDriver::isIdentifierEscaped(const QString &identifier, IdentifierType type) const -{ - bool result; - QMetaObject::invokeMethod(const_cast<QSqlDriver*>(this), - "isIdentifierEscapedImplementation", Qt::DirectConnection, - Q_RETURN_ARG(bool, result), - Q_ARG(QString, identifier), - Q_ARG(IdentifierType, type)); - return result; -} - -/*! - Returns the \a identifier with the leading and trailing delimiters removed, - \a identifier can either be a table name or field name, - dependent on \a type. If \a identifier does not have leading - and trailing delimiter characters, \a identifier is returned without - modification. - - \warning Because of binary compatability constraints, this function is not virtual, - If you want to provide your own implementation in your QSqlDriver subclass, - reimplement the stripDelimitersImplementation() slot in your subclass instead. - The stripDelimiters() function will dynamically detect the slot and call it. - - \since 4.5 - \sa isIdentifierEscaped() - */ -QString QSqlDriver::stripDelimiters(const QString &identifier, IdentifierType type) const -{ - QString result; - QMetaObject::invokeMethod(const_cast<QSqlDriver*>(this), - "stripDelimitersImplementation", Qt::DirectConnection, - Q_RETURN_ARG(QString, result), - Q_ARG(QString, identifier), - Q_ARG(IdentifierType, type)); - return result; -} - -/*! Returns a SQL statement of type \a type for the table \a tableName with the values from \a rec. If \a preparedStatement is true, the string will contain placeholders instead of values. @@ -458,17 +397,17 @@ QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, case SelectStatement: for (i = 0; i < rec.count(); ++i) { if (rec.isGenerated(i)) - s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); + s.append(escapeIdentifier(rec.fieldName(i), FieldName)).append(QLatin1String(", ")); } if (s.isEmpty()) return s; s.chop(2); - s.prepend(QLatin1String("SELECT ")).append(QLatin1String(" FROM ")).append(tableName); + s.prepend(QLatin1String("SELECT ")).append(QLatin1String(" FROM ")).append(escapeIdentifier(tableName, TableName)); break; case WhereStatement: if (preparedStatement) { for (int i = 0; i < rec.count(); ++i) { - s.append(prepareIdentifier(rec.fieldName(i), FieldName,this)); + s.append(escapeIdentifier(rec.fieldName(i), FieldName)); if (rec.isNull(i)) s.append(QLatin1String(" IS NULL")); else @@ -477,7 +416,7 @@ QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, } } else { for (i = 0; i < rec.count(); ++i) { - s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)); + s.append(escapeIdentifier(rec.fieldName(i), FieldName)); QString val = formatValue(rec.field(i)); if (val == QLatin1String("NULL")) s.append(QLatin1String(" IS NULL")); @@ -492,12 +431,12 @@ QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, } break; case UpdateStatement: - s.append(QLatin1String("UPDATE ")).append(tableName).append( + s.append(QLatin1String("UPDATE ")).append(escapeIdentifier(tableName, TableName)).append( QLatin1String(" SET ")); for (i = 0; i < rec.count(); ++i) { if (!rec.isGenerated(i) || !rec.value(i).isValid()) continue; - s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1Char('=')); + s.append(escapeIdentifier(rec.fieldName(i), FieldName)).append(QLatin1Char('=')); if (preparedStatement) s.append(QLatin1Char('?')); else @@ -510,15 +449,15 @@ QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, s.clear(); break; case DeleteStatement: - s.append(QLatin1String("DELETE FROM ")).append(tableName); + s.append(QLatin1String("DELETE FROM ")).append(escapeIdentifier(tableName, TableName)); break; case InsertStatement: { - s.append(QLatin1String("INSERT INTO ")).append(tableName).append(QLatin1String(" (")); + s.append(QLatin1String("INSERT INTO ")).append(escapeIdentifier(tableName, TableName)).append(QLatin1String(" (")); QString vals; for (i = 0; i < rec.count(); ++i) { if (!rec.isGenerated(i) || !rec.value(i).isValid()) continue; - s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); + s.append(escapeIdentifier(rec.fieldName(i), FieldName)).append(QLatin1String(", ")); if (preparedStatement) vals.append(QLatin1String("?")); else @@ -866,56 +805,4 @@ QStringList QSqlDriver::subscribedToNotificationsImplementation() const return QStringList(); } -/*! - This slot returns whether \a identifier is escaped according to the database rules. - \a identifier can either be a table name or field name, dependent - on \a type. - - Because of binary compatability constraints, isIdentifierEscaped() function - (introduced in Qt 4.5) is not virtual. Instead, isIdentifierEscaped() will - dynamically detect and call \e this slot. The default implementation - assumes the escape/delimiter character is a double quote. Reimplement this - slot in your own QSqlDriver if your database engine uses a different - delimiter character. - - \since 4.5 - \sa isIdentifierEscaped() - */ -bool QSqlDriver::isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const -{ - Q_UNUSED(type); - bool isLeftDelimited = identifier.left(1) == QString(QLatin1Char('"')); - bool isRightDelimited = identifier.right(1) == QString(QLatin1Char('"')); - if( identifier.size() > 2 && isLeftDelimited && isRightDelimited ) - return true; - else - return false; -} - -/*! - This slot returns \a identifier with the leading and trailing delimiters removed, - \a identifier can either be a tablename or field name, dependent on \a type. - If \a identifier does not have leading and trailing delimiter characters, \a - identifier is returned without modification. - - Because of binary compatability constraints, the stripDelimiters() function - (introduced in Qt 4.5) is not virtual. Instead, stripDelimiters() will - dynamically detect and call \e this slot. It generally unnecessary - to reimplement this slot. - - \since 4.5 - \sa stripDelimiters() - */ -QString QSqlDriver::stripDelimitersImplementation(const QString &identifier, IdentifierType type) const -{ - QString ret; - if (this->isIdentifierEscaped(identifier, type)) { - ret = identifier.mid(1); - ret.chop(1); - } else { - ret = identifier; - } - return ret; -} - QT_END_NAMESPACE diff --git a/src/sql/kernel/qsqldriver.h b/src/sql/kernel/qsqldriver.h index 8ac1471..9e3d291 100644 --- a/src/sql/kernel/qsqldriver.h +++ b/src/sql/kernel/qsqldriver.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -127,9 +127,6 @@ public: bool unsubscribeFromNotification(const QString &name); // ### Qt 5: make virtual QStringList subscribedToNotifications() const; // ### Qt 5: make virtual - bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const; // ### Qt 5: make virtual - QString stripDelimiters(const QString &identifier, IdentifierType type) const; // ### Qt 5: make virtual - Q_SIGNALS: void notification(const QString &name); @@ -143,9 +140,6 @@ protected Q_SLOTS: bool unsubscribeFromNotificationImplementation(const QString &name); // ### Qt 5: eliminate, see unsubscribeFromNotification() QStringList subscribedToNotificationsImplementation() const; // ### Qt 5: eliminate, see subscribedNotifications() - bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const; // ### Qt 5: eliminate, see isIdentifierEscaped() - QString stripDelimitersImplementation(const QString &identifier, IdentifierType type) const; // ### Qt 5: eliminate, see stripDelimiters() - private: Q_DISABLE_COPY(QSqlDriver) }; diff --git a/src/sql/kernel/qsqldriverplugin.cpp b/src/sql/kernel/qsqldriverplugin.cpp index b3de2cd..149762f 100644 --- a/src/sql/kernel/qsqldriverplugin.cpp +++ b/src/sql/kernel/qsqldriverplugin.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqldriverplugin.h b/src/sql/kernel/qsqldriverplugin.h index 1150360..e101ba3 100644 --- a/src/sql/kernel/qsqldriverplugin.h +++ b/src/sql/kernel/qsqldriverplugin.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlerror.cpp b/src/sql/kernel/qsqlerror.cpp index 14fc050..b59e7bc 100644 --- a/src/sql/kernel/qsqlerror.cpp +++ b/src/sql/kernel/qsqlerror.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlerror.h b/src/sql/kernel/qsqlerror.h index 9e09c27..884a824 100644 --- a/src/sql/kernel/qsqlerror.h +++ b/src/sql/kernel/qsqlerror.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlfield.cpp b/src/sql/kernel/qsqlfield.cpp index 4c1f1f4..9608622 100644 --- a/src/sql/kernel/qsqlfield.cpp +++ b/src/sql/kernel/qsqlfield.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlfield.h b/src/sql/kernel/qsqlfield.h index a5bd8c4..d70af15 100644 --- a/src/sql/kernel/qsqlfield.h +++ b/src/sql/kernel/qsqlfield.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlindex.cpp b/src/sql/kernel/qsqlindex.cpp index 02cdfb3..431d64e 100644 --- a/src/sql/kernel/qsqlindex.cpp +++ b/src/sql/kernel/qsqlindex.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlindex.h b/src/sql/kernel/qsqlindex.h index 82c0fb9..19f85c6 100644 --- a/src/sql/kernel/qsqlindex.h +++ b/src/sql/kernel/qsqlindex.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlnulldriver_p.h b/src/sql/kernel/qsqlnulldriver_p.h index e899a0b..3983c93 100644 --- a/src/sql/kernel/qsqlnulldriver_p.h +++ b/src/sql/kernel/qsqlnulldriver_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp index 2a07e28..778fd28 100644 --- a/src/sql/kernel/qsqlquery.cpp +++ b/src/sql/kernel/qsqlquery.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlquery.h b/src/sql/kernel/qsqlquery.h index e042fbd..0bfe1bd 100644 --- a/src/sql/kernel/qsqlquery.h +++ b/src/sql/kernel/qsqlquery.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlrecord.cpp b/src/sql/kernel/qsqlrecord.cpp index 0162664..e599d37 100644 --- a/src/sql/kernel/qsqlrecord.cpp +++ b/src/sql/kernel/qsqlrecord.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlrecord.h b/src/sql/kernel/qsqlrecord.h index 239ecdd..47b87bf 100644 --- a/src/sql/kernel/qsqlrecord.h +++ b/src/sql/kernel/qsqlrecord.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp index cffc570..ee827e2 100644 --- a/src/sql/kernel/qsqlresult.cpp +++ b/src/sql/kernel/qsqlresult.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/kernel/qsqlresult.h b/src/sql/kernel/qsqlresult.h index 0a3d8b9..94e7f0e 100644 --- a/src/sql/kernel/qsqlresult.h +++ b/src/sql/kernel/qsqlresult.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/models/qsqlquerymodel.cpp b/src/sql/models/qsqlquerymodel.cpp index 973d715..7b80b5a 100644 --- a/src/sql/models/qsqlquerymodel.cpp +++ b/src/sql/models/qsqlquerymodel.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/models/qsqlquerymodel.h b/src/sql/models/qsqlquerymodel.h index 14e01c0..c81fa2c 100644 --- a/src/sql/models/qsqlquerymodel.h +++ b/src/sql/models/qsqlquerymodel.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/models/qsqlquerymodel_p.h b/src/sql/models/qsqlquerymodel_p.h index ef331d7..8e5edb2 100644 --- a/src/sql/models/qsqlquerymodel_p.h +++ b/src/sql/models/qsqlquerymodel_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/models/qsqlrelationaldelegate.cpp b/src/sql/models/qsqlrelationaldelegate.cpp index 1043ef9..8a38c3d 100644 --- a/src/sql/models/qsqlrelationaldelegate.cpp +++ b/src/sql/models/qsqlrelationaldelegate.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/models/qsqlrelationaldelegate.h b/src/sql/models/qsqlrelationaldelegate.h index dd9ad8f..592ea57 100644 --- a/src/sql/models/qsqlrelationaldelegate.h +++ b/src/sql/models/qsqlrelationaldelegate.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp index 12eae84..93d1733 100644 --- a/src/sql/models/qsqlrelationaltablemodel.cpp +++ b/src/sql/models/qsqlrelationaltablemodel.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -182,21 +182,10 @@ void QRelation::populateDictionary() populateModel(); QSqlRecord record; - QString indexColumn; - QString displayColumn; for (int i=0; i < model->rowCount(); ++i) { record = model->record(i); - - indexColumn = rel.indexColumn(); - if (m_parent->database().driver()->isIdentifierEscaped(indexColumn, QSqlDriver::FieldName)) - indexColumn = m_parent->database().driver()->stripDelimiters(indexColumn, QSqlDriver::FieldName); - - displayColumn = rel.displayColumn(); - if (m_parent->database().driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName)) - displayColumn = m_parent->database().driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); - - dictionary[record.field(indexColumn).value().toString()] = - record.field(displayColumn).value(); + dictionary[record.field(rel.indexColumn()).value().toString()] = + record.field(rel.displayColumn()).value(); } m_dictInitialized = true; } @@ -226,7 +215,7 @@ public: QSqlRelationalTableModelPrivate() : QSqlTableModelPrivate() {} - QString relationField(const QString &tableName, const QString &fieldName) const; + QString escapedRelationField(const QString &tableName, const QString &fieldName) const; int nameToIndex(const QString &name) const; mutable QVector<QRelation> relations; @@ -266,10 +255,7 @@ void QSqlRelationalTableModelPrivate::revertCachedRow(int row) int QSqlRelationalTableModelPrivate::nameToIndex(const QString &name) const { - QString fieldname = name; - if (db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName)) - fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName); - return baseRec.indexOf(fieldname); + return baseRec.indexOf(name); } void QSqlRelationalTableModelPrivate::clearEditBuffer() @@ -495,14 +481,14 @@ QSqlRelation QSqlRelationalTableModel::relation(int column) const return d->relations.value(column).rel; } -QString QSqlRelationalTableModelPrivate::relationField(const QString &tableName, +QString QSqlRelationalTableModelPrivate::escapedRelationField(const QString &tableName, const QString &fieldName) const { - QString ret; - ret.reserve(tableName.size() + fieldName.size() + 1); - ret.append(tableName).append(QLatin1Char('.')).append(fieldName); + QString esc; + esc.reserve(tableName.size() + fieldName.size() + 1); + esc.append(tableName).append(QLatin1Char('.')).append(fieldName); - return ret; + return db.driver()->escapeIdentifier(esc, QSqlDriver::FieldName); } /*! @@ -528,29 +514,15 @@ QString QSqlRelationalTableModel::selectStatement() const // Count how many times each field name occurs in the record QHash<QString, int> fieldNames; - QStringList fieldList; for (int i = 0; i < rec.count(); ++i) { QSqlRelation relation = d->relations.value(i, nullRelation).rel; QString name; if (relation.isValid()) - { // Count the display column name, not the original foreign key name = relation.displayColumn(); - if (d->db.driver()->isIdentifierEscaped(name, QSqlDriver::FieldName)) - name = d->db.driver()->stripDelimiters(name, QSqlDriver::FieldName); - - QSqlRecord rec = database().record(relation.tableName()); - for (int i = 0; i < rec.count(); ++i) { - if (name.compare(rec.fieldName(i), Qt::CaseInsensitive) == 0) { - name = rec.fieldName(i); - break; - } - } - } else name = rec.fieldName(i); fieldNames.insert(name, fieldNames.value(name, 0) + 1); - fieldList.append(name); } for (int i = 0; i < rec.count(); ++i) { @@ -559,30 +531,27 @@ QString QSqlRelationalTableModel::selectStatement() const QString relTableAlias = QString::fromLatin1("relTblAl_%1").arg(i); if (!fList.isEmpty()) fList.append(QLatin1String(", ")); - fList.append(d->relationField(relTableAlias,relation.displayColumn())); + fList.append(d->escapedRelationField(relTableAlias, relation.displayColumn())); // If there are duplicate field names they must be aliased - if (fieldNames.value(fieldList[i]) > 1) { - QString relTableName = relation.tableName(); - if (d->db.driver()->isIdentifierEscaped(relTableName, QSqlDriver::TableName)) - relTableName = d->db.driver()->stripDelimiters(relTableName, QSqlDriver::TableName); - QString displayColumn = relation.displayColumn(); - if (d->db.driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName)) - displayColumn = d->db.driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); - fList.append(QString::fromLatin1(" AS %1_%2").arg(relTableName).arg(displayColumn)); + if (fieldNames.value(relation.displayColumn()) > 1) { + fList.append(QString::fromLatin1(" AS %1_%2").arg(relation.tableName()).arg(relation.displayColumn())); } // this needs fixing!! the below if is borken. - tables.append(relation.tableName().append(QLatin1String(" ")).append(relTableAlias)); + if (!tables.contains(relation.tableName())) + tables.append(d->db.driver()->escapeIdentifier(relation.tableName(),QSqlDriver::TableName) + .append(QLatin1String(" ")) + .append(d->db.driver()->escapeIdentifier(relTableAlias, QSqlDriver::TableName))); if(!where.isEmpty()) where.append(QLatin1String(" AND ")); - where.append(d->relationField(tableName(), d->db.driver()->escapeIdentifier(rec.fieldName(i), QSqlDriver::FieldName))); + where.append(d->escapedRelationField(tableName(), rec.fieldName(i))); where.append(QLatin1String(" = ")); - where.append(d->relationField(relTableAlias, relation.indexColumn())); + where.append(d->escapedRelationField(relTableAlias, relation.indexColumn())); } else { if (!fList.isEmpty()) fList.append(QLatin1String(", ")); - fList.append(d->relationField(tableName(), d->db.driver()->escapeIdentifier(rec.fieldName(i), QSqlDriver::FieldName))); + fList.append(d->escapedRelationField(tableName(), rec.fieldName(i))); } } if (!tables.isEmpty()) @@ -591,7 +560,7 @@ QString QSqlRelationalTableModel::selectStatement() const return query; if(!tList.isEmpty()) tList.prepend(QLatin1String(", ")); - tList.prepend(tableName()); + tList.prepend(d->db.driver()->escapeIdentifier(tableName(),QSqlDriver::TableName)); query.append(QLatin1String("SELECT ")); query.append(fList).append(QLatin1String(" FROM ")).append(tList); qAppendWhereClause(query, where, filter()); @@ -721,7 +690,7 @@ QString QSqlRelationalTableModel::orderByClause() const return QSqlTableModel::orderByClause(); QString s = QLatin1String("ORDER BY "); - s.append(d->relationField(QLatin1String("relTblAl_") + QString::number(d->sortColumn), + s.append(d->escapedRelationField(QLatin1String("relTblAl_") + QString::number(d->sortColumn), rel.displayColumn())); s += d->sortOrder == Qt::AscendingOrder ? QLatin1String(" ASC") : QLatin1String(" DESC"); return s; diff --git a/src/sql/models/qsqlrelationaltablemodel.h b/src/sql/models/qsqlrelationaltablemodel.h index fb11bae..f476a48 100644 --- a/src/sql/models/qsqlrelationaltablemodel.h +++ b/src/sql/models/qsqlrelationaltablemodel.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index c2442c5..1acc846 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -98,10 +98,7 @@ bool QSqlTableModelPrivate::setRecord(int row, const QSqlRecord &record) int QSqlTableModelPrivate::nameToIndex(const QString &name) const { - QString fieldname = name; - if (db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName)) - fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName); - return rec.indexOf(fieldname); + return rec.indexOf(name); } void QSqlTableModelPrivate::initRecordAndPrimaryIndex() @@ -370,7 +367,10 @@ void QSqlTableModel::setTable(const QString &tableName) { Q_D(QSqlTableModel); clear(); - d->tableName = tableName; + if(d->db.tables().contains(tableName.toUpper())) + d->tableName = tableName.toUpper(); + else + d->tableName = tableName; d->initRecordAndPrimaryIndex(); d->initColOffsets(d->rec.count()); @@ -976,9 +976,7 @@ QString QSqlTableModel::orderByClause() const if (!f.isValid()) return s; - QString table = d->tableName; - //we can safely escape the field because it would have been obtained from the database - //and have the correct case + QString table = d->db.driver()->escapeIdentifier(d->tableName, QSqlDriver::TableName); QString field = d->db.driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName); s.append(QLatin1String("ORDER BY ")).append(table).append(QLatin1Char('.')).append(field); s += d->sortOrder == Qt::AscendingOrder ? QLatin1String(" ASC") : QLatin1String(" DESC"); @@ -1319,12 +1317,8 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record) mrow.rec = d->rec; mrow.primaryValues = d->primaryValues(indexInQuery(createIndex(row, 0)).row()); } - QString fieldName; for (int i = 0; i < record.count(); ++i) { - fieldName = record.fieldName(i); - if (d->db.driver()->isIdentifierEscaped(fieldName, QSqlDriver::FieldName)) - fieldName = d->db.driver()->stripDelimiters(fieldName, QSqlDriver::FieldName); - int idx = mrow.rec.indexOf(fieldName); + int idx = mrow.rec.indexOf(record.fieldName(i)); if (idx == -1) isOk = false; else diff --git a/src/sql/models/qsqltablemodel.h b/src/sql/models/qsqltablemodel.h index 14c4c4f..a6f4469 100644 --- a/src/sql/models/qsqltablemodel.h +++ b/src/sql/models/qsqltablemodel.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/sql/models/qsqltablemodel_p.h b/src/sql/models/qsqltablemodel_p.h index fa3b44b..1d06292 100644 --- a/src/sql/models/qsqltablemodel_p.h +++ b/src/sql/models/qsqltablemodel_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtSql module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ |