summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sql/drivers/sqlite/qsql_sqlite.cpp3
-rw-r--r--tests/auto/qsqlquery/tst_qsqlquery.cpp39
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 366bb50..eaa51dd 100644
--- a/src/sql/drivers/sqlite/qsql_sqlite.cpp
+++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp
@@ -200,8 +200,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/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp
index bcbeb51..5ebbc3b 100644
--- a/tests/auto/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp
@@ -219,6 +219,9 @@ private slots:
void QTBUG_21884();
void QTBUG_16967_data() { generic_data("QSQLITE"); }
void QTBUG_16967(); //clean close
+ void QTBUG_14904_data() { generic_data("QSQLITE"); }
+ void QTBUG_14904();
+
void QTBUG_2192_data() { generic_data(); }
void QTBUG_2192();
@@ -3243,6 +3246,42 @@ void tst_QSqlQuery::QTBUG_16967()
}
}
+/**
+ * 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 int)");
+ QVERIFY_SQL(q, exec());
+ q.prepare("insert into " + tableName + "(val1) values(?);");
+ q.addBindValue(1);
+ 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::Int);
+ QCOMPARE(q.value(0).toInt(), 1);
+
+ 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::Int);
+ QCOMPARE(q.value(0).toInt(), 1);
+}
+
void tst_QSqlQuery::QTBUG_2192()
{
QFETCH( QString, dbName );