Fix for Sql query aliases with dots
Task-number: QTBUG-14904 Change-Id: I98a02d4bbf28522cd5c2f65ea606b6b26977e8e6 Reviewed-by: Mark Brand <mabrand@mabrand.nl>
This commit is contained in:
parent
7ec521a373
commit
18be0749eb
@ -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);
|
||||
}
|
||||
|
@ -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 );
|
||||
|
Loading…
Reference in New Issue
Block a user