From 18be0749eb58316036d6eaff9dc5fecc1379f31a Mon Sep 17 00:00:00 2001 From: Marko Kangas Date: Fri, 8 Feb 2013 12:10:26 +0200 Subject: [PATCH] Fix for Sql query aliases with dots Task-number: QTBUG-14904 Change-Id: I98a02d4bbf28522cd5c2f65ea606b6b26977e8e6 Reviewed-by: Mark Brand --- src/sql/drivers/sqlite/qsql_sqlite.cpp | 3 +- .../sql/kernel/qsqlquery/tst_qsqlquery.cpp | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index f11279f262..04c88dd188 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -206,8 +206,7 @@ void QSQLiteResultPrivate::initColumns(bool emptyResultset) } } - int dotIdx = colName.lastIndexOf(QLatin1Char('.')); - QSqlField fld(colName.mid(dotIdx == -1 ? 0 : dotIdx + 1), fieldType); + QSqlField fld(colName, fieldType); fld.setSqlType(stp); rInf.append(fld); } diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 1d2a60506f..2bc5581c88 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -221,6 +221,9 @@ private slots: void QTBUG_16967(); //clean close void QTBUG_23895_data() { generic_data("QSQLITE"); } void QTBUG_23895(); //sqlite boolean type + void QTBUG_14904_data() { generic_data("QSQLITE"); } + void QTBUG_14904(); + void QTBUG_2192_data() { generic_data(); } void QTBUG_2192(); @@ -3407,6 +3410,42 @@ void tst_QSqlQuery::QTBUG_23895() QVERIFY(!q.next()); } +/** + * Test for aliases with dots + */ +void tst_QSqlQuery::QTBUG_14904() +{ + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QSqlQuery q(db); + + QString tableName(qTableName("bug14904", __FILE__ )); + tst_Databases::safeDropTable( db, tableName ); + + q.prepare("create table " + tableName + "(val1 bool)"); + QVERIFY_SQL(q, exec()); + q.prepare("insert into " + tableName + "(val1) values(?);"); + q.addBindValue(true); + QVERIFY_SQL(q, exec()); + + QString sql="select val1 AS value1 from " + tableName; + QVERIFY_SQL(q, exec(sql)); + QVERIFY_SQL(q, next()); + + QCOMPARE(q.record().indexOf("value1"), 0); + QCOMPARE(q.record().field(0).type(), QVariant::Bool); + QCOMPARE(q.value(0).toBool(), true); + + sql="select val1 AS 'value.one' from " + tableName; + QVERIFY_SQL(q, exec(sql)); + QVERIFY_SQL(q, next()); + QCOMPARE(q.record().indexOf("value.one"), 0); // was -1 before bug fix + QCOMPARE(q.record().field(0).type(), QVariant::Bool); + QCOMPARE(q.value(0).toBool(), true); +} + void tst_QSqlQuery::QTBUG_2192() { QFETCH( QString, dbName );