diff options
author | Marko Kangas <marko.kangas@digia.com> | 2013-02-08 12:10:26 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-13 17:27:36 +0100 |
commit | 18be0749eb58316036d6eaff9dc5fecc1379f31a (patch) | |
tree | 81e7748dfe6b10fe099c0cf711d0f270cf959f07 | |
parent | 7ec521a373b03782b4ef364cb92427283187c78e (diff) |
Fix for Sql query aliases with dots
Task-number: QTBUG-14904
Change-Id: I98a02d4bbf28522cd5c2f65ea606b6b26977e8e6
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 3 | ||||
-rw-r--r-- | tests/auto/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 ); |