sqlite: Allow for duplicated placeholders with just one placeholder

This accounts for a case of a placeholder being duplicated in the
prepare query, but where only one placeholder was used. This amends
e4e87a2ece1e0c9901514fea094f31863b64b570

Task-number: QTBUG-68299
Change-Id: Ia92ee912facd51a13e7222886debb219b24442b0
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Andy Shaw 2018-05-15 22:15:04 +02:00
parent 9c707f140e
commit b0f3cc1594
2 changed files with 12 additions and 2 deletions

View File

@ -496,10 +496,10 @@ bool QSQLiteResult::exec()
#if (SQLITE_VERSION_NUMBER >= 3003011)
// In the case of the reuse of a named placeholder
// We need to check explicitly that paramCount is greater than 1, as sqlite
// We need to check explicitly that paramCount is greater than or equal to 1, as sqlite
// can end up in a case where for virtual tables it returns 0 even though it
// has parameters
if (paramCount > 1 && paramCount < values.count()) {
if (paramCount >= 1 && paramCount < values.count()) {
const auto countIndexes = [](int counter, const QVector<int> &indexList) {
return counter + indexList.length();
};

View File

@ -2347,6 +2347,16 @@ void tst_QSqlQuery::prepare_bind_exec()
QCOMPARE(q.value(0).toInt(), 107);
QCOMPARE(q.value(1).toString(), QString("name"));
QCOMPARE(q.value(2).toString(), QString("107"));
// Test just duplicated placeholders
QVERIFY(q.prepare("insert into " + qtest_prepare + " (id, name, name2) values (110, :name, :name)"));
q.bindValue(":name", "name");
QVERIFY_SQL(q, exec());
QVERIFY(q.exec("select * from " + qtest_prepare + " where id > 109 order by id"));
QVERIFY(q.next());
QCOMPARE(q.value(0).toInt(), 110);
QCOMPARE(q.value(1).toString(), QString("name"));
QCOMPARE(q.value(2).toString(), QString("name"));
} // end of SQLite scope
}