diff options
author | Andy Shaw <andy.shaw@qt.io> | 2018-01-02 09:33:48 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2018-01-08 10:13:10 +0000 |
commit | 3e58f2b090661aab7302132cb2da661c8e227bc2 (patch) | |
tree | 9dcdf0353bfed874eeb0a9f9a0c1f120b3375f4a /tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | |
parent | 24fba6744cea1163ceee06d69d31b4eb619cd386 (diff) |
sqlite: Bind duplicated named placeholders correctly
sqlite will reuse the index for bound parameters when the named
placeholder is duplicated so we only need to call bind one time for each
placeholder. Therefore we need to have just one instance of each value
when doing the bind.
Task-number: QTBUG-65150
Change-Id: I75c4bcc4563e43c180a59a7a4cbb770dbe994642
Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
Diffstat (limited to 'tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp')
-rw-r--r-- | tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 3ea13896d8..1a0340f153 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -2017,6 +2017,31 @@ void tst_QSqlQuery::prepare_bind_exec() QCOMPARE( q.value(1).toString(), QString("name") ); QCOMPARE( q.value(2).toString(), QString("name") ); + // Test that duplicated named placeholders before the next unique one works correctly - QTBUG-65150 + QVERIFY(q.prepare("insert into " + qtest_prepare + " (id, name, name2) values (:id, :id, :name)")); + for (i = 104; i < 106; ++i) { + q.bindValue(":id", i); + q.bindValue(":name", "name"); + QVERIFY(q.exec()); + } + QVERIFY(q.exec("select * from " + qtest_prepare + " where id > 103 order by id")); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toInt(), 104); + QCOMPARE(q.value(1).toString(), QString("104")); + QCOMPARE(q.value(2).toString(), QString("name")); + + // Test that duplicated named placeholders in any order + QVERIFY(q.prepare("insert into " + qtest_prepare + " (id, name, name2) values (:id, :name, :id)")); + for (i = 107; i < 109; ++i) { + q.bindValue(":id", i); + q.bindValue(":name", "name"); + QVERIFY(q.exec()); + } + QVERIFY(q.exec("select * from " + qtest_prepare + " where id > 106 order by id")); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toInt(), 107); + QCOMPARE(q.value(1).toString(), QString("name")); + QCOMPARE(q.value(2).toString(), QString("107")); } // end of SQLite scope } |