From f01caaf64a6798e805ce5df9f735a5b86bfe8eb8 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Fri, 8 Feb 2013 23:57:41 +0100 Subject: QSqlQuery tests: fix mysql problems Change-Id: I82f4e6c8801c7a936b80ad72c229f915e6d2a4de Reviewed-by: Israel Lins Albuquerque Reviewed-by: Mark Brand --- tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp') diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 4e821dacc5..764b29dc85 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -540,7 +540,7 @@ void tst_QSqlQuery::mysqlOutValues() q.exec( "drop function " + hello ); - QVERIFY_SQL( q, exec( "create function " + hello + " (s char(20)) returns varchar(50) return concat('Hello ', s)" ) ); + QVERIFY_SQL(q, exec("create function " + hello + " (s char(20)) returns varchar(50) READS SQL DATA return concat('Hello ', s)")); QVERIFY_SQL( q, exec( "select " + hello + "('world')" ) ); QVERIFY_SQL( q, next() ); @@ -3580,7 +3580,7 @@ void tst_QSqlQuery::aggregateFunctionTypes() CHECK_DATABASE(db); QVariant::Type intType = QVariant::Int; // QPSQL uses LongLong for manipulation of integers - if (db.driverName().startsWith("QPSQL")) + if (db.driverName().startsWith("QPSQL") || db.driverName().startsWith("QMYSQL")) intType = QVariant::LongLong; { const QString tableName(qTableName("numericFunctionsWithIntValues", __FILE__)); @@ -3594,6 +3594,8 @@ void tst_QSqlQuery::aggregateFunctionTypes() QVERIFY(q.next()); if (db.driverName().startsWith("QSQLITE")) QCOMPARE(q.record().field(0).type(), QVariant::Invalid); + else if (db.driverName().startsWith("QMYSQL")) + QCOMPARE(q.record().field(0).type(), QVariant::Double); else QCOMPARE(q.record().field(0).type(), intType); @@ -3603,11 +3605,15 @@ void tst_QSqlQuery::aggregateFunctionTypes() QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName)); QVERIFY(q.next()); QCOMPARE(q.value(0).toInt(), 3); - QCOMPARE(q.record().field(0).type(), intType); + if (db.driverName().startsWith("QMYSQL")) + QCOMPARE(q.record().field(0).type(), QVariant::Double); + else + QCOMPARE(q.record().field(0).type(), intType); QVERIFY_SQL(q, exec("SELECT AVG(id) FROM " + tableName)); QVERIFY(q.next()); - if (db.driverName().startsWith("QSQLITE") || db.driverName().startsWith("QPSQL")) { + if (db.driverName().startsWith("QSQLITE") || db.driverName().startsWith("QPSQL") + || (db.driverName().startsWith("QMYSQL"))) { QCOMPARE(q.value(0).toDouble(), 1.5); QCOMPARE(q.record().field(0).type(), QVariant::Double); } else { @@ -3682,7 +3688,10 @@ void tst_QSqlQuery::aggregateFunctionTypes() QVERIFY_SQL(q, exec("SELECT ROUND(id, 0) FROM " + tableName + " WHERE id=2.5")); QVERIFY(q.next()); - QCOMPARE(q.value(0).toDouble(), 3.0); + if (db.driverName().startsWith("QMYSQL")) + QCOMPARE(q.value(0).toDouble(), 2.0); + else + QCOMPARE(q.value(0).toDouble(), 3.0); QCOMPARE(q.record().field(0).type(), QVariant::Double); } } -- cgit v1.2.3 From 46b7c91c81de2d830e7a7c993ea3e94e5d182124 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Mon, 11 Feb 2013 21:14:00 +0100 Subject: QSqlQuery tests: fix bool test for postgresql Change-Id: I60634f89841cbc81058588e435c6482c6c0efed6 Reviewed-by: Mark Brand --- tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp') diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 764b29dc85..8972524a0f 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -580,9 +580,10 @@ void tst_QSqlQuery::mysqlOutValues() void tst_QSqlQuery::bindBool() { // QTBUG-27763: bool value got converted to int 127 by mysql driver because sizeof(bool) < sizeof(int). - // The problem was the way the bool value from the application was handled. It doesn't matter - // whether the table column type is BOOL or INT. Use INT here because all DBMSs have it and all - // should pass this test. + // The problem was the way the bool value from the application was handled. For our purposes here, it + // doesn't matter whether the column type is BOOLEAN or INT. All DBMSs have INT, and this usually + // works for this test. Postresql is an exception because its INT type does not accept BOOLEAN + // values and its BOOLEAN columns do not accept INT values. QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); @@ -590,7 +591,8 @@ void tst_QSqlQuery::bindBool() const QString tableName(qTableName( "bindBool", __FILE__ )); q.exec("DROP TABLE " + tableName); - QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id INT, flag INT NOT NULL, PRIMARY KEY(id))")); + QString colType = db.driverName().startsWith("QPSQL") ? QLatin1String("BOOLEAN") : QLatin1String("INT"); + QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id INT, flag " + colType + " NOT NULL, PRIMARY KEY(id))")); for (int i = 0; i < 2; ++i) { bool flag = i; -- cgit v1.2.3 From 60c1f9f2744f7a627b60d0eb5fbdf484a327a234 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Fri, 8 Feb 2013 23:56:11 +0100 Subject: QSqlQuery tests: fix create table failures Change-Id: Id20517cc68d03ac008650374fadd96cd6626d3fe Reviewed-by: Mark Brand --- tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp') diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 8972524a0f..1d2a60506f 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -420,9 +420,11 @@ void tst_QSqlQuery::char1Select() { QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "char1Select", __FILE__ ) + " (id char(1))" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "char1Select", __FILE__ ) + " values ('a')" ) ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "char1Select", __FILE__ ) ) ); + const QString tbl = qTableName("char1Select", __FILE__); + q.exec( "drop table " + tbl); + QVERIFY_SQL(q, exec("create table " + tbl + " (id char(1))")); + QVERIFY_SQL(q, exec("insert into " + tbl + " values ('a')")); + QVERIFY_SQL(q, exec("select * from " + tbl)); QVERIFY( q.next() ); if ( db.driverName().startsWith( "QIBASE" ) ) @@ -1489,6 +1491,7 @@ void tst_QSqlQuery::precision() // need a new scope for SQLITE QSqlQuery q( db ); + q.exec("drop table " + qtest_precision); if ( tst_Databases::isMSAccess( db ) ) QVERIFY_SQL( q, exec( "create table " + qtest_precision + " (col1 number)" ) ); else @@ -1753,6 +1756,7 @@ void tst_QSqlQuery::prepare_bind_exec() else createQuery = "create table " + qtest_prepare + " (id int not null primary key, name varchar(200), name2 varchar(200))"; + q.exec("drop table " + qtest_prepare); QVERIFY_SQL( q, exec( createQuery ) ); QVERIFY( q.prepare( "insert into " + qtest_prepare + " (id, name) values (:id, :name)" ) ); @@ -2286,8 +2290,10 @@ void tst_QSqlQuery::execErrorRecovery() QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_exerr", __FILE__ ) + " (id int not null primary key)" ) ); - QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_exerr", __FILE__ ) + " values (?)" ) ); + const QString tbl = qTableName("qtest_exerr", __FILE__); + q.exec("drop table " + tbl); + QVERIFY_SQL(q, exec("create table " + tbl + " (id int not null primary key)")); + QVERIFY_SQL(q, prepare("insert into " + tbl + " values (?)" )); q.addBindValue( 1 ); QVERIFY_SQL( q, exec() ); @@ -2790,8 +2796,10 @@ void tst_QSqlQuery::emptyTableNavigate() { QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_empty", __FILE__ ) + " (id char(10))" ) ); - QVERIFY_SQL( q, prepare( "select * from " + qTableName( "qtest_empty", __FILE__ ) ) ); + const QString tbl = qTableName("qtest_empty", __FILE__); + q.exec("drop table " + tbl); + QVERIFY_SQL(q, exec("create table " + tbl + " (id char(10))")); + QVERIFY_SQL(q, prepare("select * from " + qTableName("qtest_empty", __FILE__ ))); QVERIFY_SQL( q, exec() ); QVERIFY( !q.next() ); QCOMPARE( q.lastError().isValid(), false ); @@ -2806,6 +2814,7 @@ void tst_QSqlQuery::task_217003() QSqlQuery q( db ); const QString Planet(qTableName( "Planet", __FILE__)); + q.exec("drop table " + Planet); QVERIFY_SQL( q, exec( "create table " + Planet + " (Name varchar(20))" ) ); QVERIFY_SQL( q, exec( "insert into " + Planet + " VALUES ('Mercury')" ) ); QVERIFY_SQL( q, exec( "insert into " + Planet + " VALUES ('Venus')" ) ); -- cgit v1.2.3