From 95cb2bb6cbdf2dcc0a035105104a4c08ecc43e83 Mon Sep 17 00:00:00 2001 From: Derick Hawcroft Date: Tue, 18 Aug 2009 10:39:16 +1000 Subject: Fix a SQLITE whitespace in identifiers issue. Whitespaces in identifiers now past autotests Reviewed-by:Bill King --- src/sql/drivers/sqlite/qsql_sqlite.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index 3235830..877baea 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -64,6 +64,17 @@ Q_DECLARE_METATYPE(sqlite3_stmt*) QT_BEGIN_NAMESPACE +static QString _q_escapeIdentifier(const QString &identifier) +{ + QString res = identifier; + 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("\".\"")); + } + return res; +} + static QVariant::Type qGetColumnType(const QString &tpName) { const QString typeName = tpName.toLower(); @@ -636,7 +647,7 @@ static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool only schema = tableName.left(indexOfSeparator).append(QLatin1String(".")); table = tableName.mid(indexOfSeparator + 1); } - q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info ('") + table + QLatin1String("')")); + q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info (") + _q_escapeIdentifier(table) + QLatin1String(")")); QSqlIndex ind; while (q.next()) { @@ -683,13 +694,7 @@ QVariant QSQLiteDriver::handle() const QString QSQLiteDriver::escapeIdentifier(const QString &identifier, IdentifierType /*type*/) const { - QString res = identifier; - 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("\".\"")); - } - return res; + return _q_escapeIdentifier(identifier); } QT_END_NAMESPACE -- cgit v0.12