summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerick Hawcroft <derick.hawcroft@nokia.com>2009-08-18 00:39:16 (GMT)
committerDerick Hawcroft <derick.hawcroft@nokia.com>2009-08-18 00:39:16 (GMT)
commit95cb2bb6cbdf2dcc0a035105104a4c08ecc43e83 (patch)
tree915b18dfdcd2b37e68df04cf7717fecec8b1eaaf
parent26af3b384094bcb9f9f844e21f5770e595805398 (diff)
downloadQt-95cb2bb6cbdf2dcc0a035105104a4c08ecc43e83.zip
Qt-95cb2bb6cbdf2dcc0a035105104a4c08ecc43e83.tar.gz
Qt-95cb2bb6cbdf2dcc0a035105104a4c08ecc43e83.tar.bz2
Fix a SQLITE whitespace in identifiers issue.
Whitespaces in identifiers now past autotests Reviewed-by:Bill King
-rw-r--r--src/sql/drivers/sqlite/qsql_sqlite.cpp21
1 files 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