diff options
author | Matt Newell <newellm@blur.com> | 2012-03-26 10:46:22 -0700 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-30 09:31:03 +0200 |
commit | cff46983a8823fda13cafa2c8774153525f0d4d1 (patch) | |
tree | 00c6625f23cfa64d9173ad1cd3662786cb025cfe /tests/auto/sql | |
parent | 3ec88b355b5c9649d128fcf18cb2abc39ac0e770 (diff) |
Allow named bind values to be used multiple times per query
Prepared queries should be able to use a name parameter more than
once. Currently this will result in undefined behavior and crashes.
This patch fixes the bug and implements the needed test case.
Task-number: QTBUG-6420
Change-Id: I07d6537e432a9b2781e9ef3d9f597bceb054527e
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Honglei Zhang <honglei.zhang@nokia.com>
Diffstat (limited to 'tests/auto/sql')
-rw-r--r-- | tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 584fcb045a..dab34a89ed 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -1683,11 +1683,11 @@ void tst_QSqlQuery::prepare_bind_exec() QVERIFY_SQL( q, exec("set client_min_messages='warning'")); if ( tst_Databases::isSqlServer( db ) || db.driverName().startsWith( "QTDS" ) ) - createQuery = "create table " + qtest_prepare + " (id int primary key, name nvarchar(200) null)"; + createQuery = "create table " + qtest_prepare + " (id int primary key, name nvarchar(200) null, name2 nvarchar(200) null)"; else if ( tst_Databases::isMySQL(db) && useUnicode ) - createQuery = "create table " + qtest_prepare + " (id int not null primary key, name varchar(200) character set utf8)"; + createQuery = "create table " + qtest_prepare + " (id int not null primary key, name varchar(200) character set utf8, name2 varchar(200) character set utf8)"; else - createQuery = "create table " + qtest_prepare + " (id int not null primary key, name varchar(200))"; + createQuery = "create table " + qtest_prepare + " (id int not null primary key, name varchar(200), name2 varchar(200))"; QVERIFY_SQL( q, exec( createQuery ) ); @@ -1756,7 +1756,7 @@ void tst_QSqlQuery::prepare_bind_exec() QCOMPARE( q.value( 0 ).toInt(), i ); QCOMPARE( q.value( 1 ).toString().trimmed(), values[ i ] ); QSqlRecord rInf = q.record(); - QCOMPARE(( int )rInf.count(), 2 ); + QCOMPARE(( int )rInf.count(), 3 ); QCOMPARE( rInf.field( 0 ).name().toUpper(), QString( "ID" ) ); QCOMPARE( rInf.field( 1 ).name().toUpper(), QString( "NAME" ) ); QVERIFY( !q.next() ); @@ -1839,6 +1839,20 @@ void tst_QSqlQuery::prepare_bind_exec() QVERIFY( !q.isActive() ); + QVERIFY( q.prepare( "insert into " + qtest_prepare + " (id, name, name2) values (:id, :name, :name)" ) ); + for ( i = 101; i < 103; ++i ) { + q.bindValue( ":id", i ); + q.bindValue( ":name", "name" ); + QVERIFY( q.exec() ); + } + + // Test for QTBUG-6420 + QVERIFY( q.exec( "select * from " + qtest_prepare + " where id > 100 order by id" ) ); + QVERIFY( q.next() ); + QCOMPARE( q.value(0).toInt(), 101 ); + QCOMPARE( q.value(1).toString(), QString("name") ); + QCOMPARE( q.value(2).toString(), QString("name") ); + } // end of SQLite scope } |