From 1ae64d1dcf2e9613d2580075a7b716910a6bf972 Mon Sep 17 00:00:00 2001 From: Bill King Date: Wed, 10 Mar 2010 13:41:29 +1000 Subject: Parallelize DB autotests, also some factorization Add local machine parallelization of auto-tests, not just host to host. Reviewed-by: Justin McPherson --- tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp | 97 ++-- .../q3sqlselectcursor/tst_q3sqlselectcursor.cpp | 20 +- tests/auto/qsqldatabase/tst_databases.h | 26 +- tests/auto/qsqldatabase/tst_qsqldatabase.cpp | 301 ++++++------ tests/auto/qsqldriver/tst_qsqldriver.cpp | 19 +- tests/auto/qsqlquery/tst_qsqlquery.cpp | 517 +++++++++++---------- tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp | 79 ++-- .../tst_qsqlrelationaltablemodel.cpp | 221 ++++----- tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp | 117 ++--- tests/auto/qsqlthread/tst_qsqlthread.cpp | 39 +- 10 files changed, 738 insertions(+), 698 deletions(-) diff --git a/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp b/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp index 874eb7b..f837564 100644 --- a/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp +++ b/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp @@ -48,6 +48,7 @@ #include "../qsqldatabase/tst_databases.h" +const QString qtest(qTableName( "qtest", __FILE__ )); //TESTED_FILES= @@ -142,26 +143,26 @@ void tst_Q3SqlCursor::createTestTables( QSqlDatabase db ) // please never ever change this table; otherwise fix all tests ;) if ( tst_Databases::isMSAccess( db ) ) { - QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest" ) + " ( id int not null, t_varchar varchar(40) not null," + QVERIFY_SQL(q, exec( "create table " + qtest + " ( id int not null, t_varchar varchar(40) not null," "t_char char(40), t_numeric number, primary key (id, t_varchar) )" )); } else { - QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest" ) + " ( id int not null, t_varchar varchar(40) not null," + QVERIFY_SQL(q, exec( "create table " + qtest + " ( id int not null, t_varchar varchar(40) not null," "t_char char(40), t_numeric numeric(6, 3), primary key (id, t_varchar) )" )); } if ( tst_Databases::isSqlServer( db ) ) { //workaround for SQL SERVER since he can store unicode only in nvarchar fields - QVERIFY_SQL(q, exec("create table " + qTableName("qtest_unicode") + " (id int not null, " + QVERIFY_SQL(q, exec("create table " + qTableName("qtest_unicode", __FILE__) + " (id int not null, " "t_varchar nvarchar(80) not null, t_char nchar(80) )" )); } else { - QVERIFY_SQL(q, exec("create table " + qTableName("qtest_unicode") + " (id int not null, " + QVERIFY_SQL(q, exec("create table " + qTableName("qtest_unicode", __FILE__) + " (id int not null, " "t_varchar varchar(100) not null," "t_char char(100))" )); } if (tst_Databases::isMSAccess(db)) { - QVERIFY_SQL(q, exec("create table " + qTableName("qtest_precision") + " (col1 number)")); + QVERIFY_SQL(q, exec("create table " + qTableName("qtest_precision", __FILE__) + " (col1 number)")); } else { - QVERIFY_SQL(q, exec("create table " + qTableName("qtest_precision") + " (col1 numeric(15, 14))")); + QVERIFY_SQL(q, exec("create table " + qTableName("qtest_precision", __FILE__) + " (col1 numeric(15, 14))")); } } @@ -170,12 +171,12 @@ void tst_Q3SqlCursor::dropTestTables( QSqlDatabase db ) if ( !db.isValid() ) return; QStringList tableNames; - tableNames << qTableName( "qtest" ) - << qTableName( "qtest_unicode" ) - << qTableName( "qtest_precision" ) - << qTableName( "qtest_ovchar" ) - << qTableName( "qtest_onvchar" ) - << qTableName( "qtestPK" ); + tableNames << qtest + << qTableName( "qtest_unicode", __FILE__ ) + << qTableName( "qtest_precision", __FILE__ ) + << qTableName( "qtest_ovchar", __FILE__ ) + << qTableName( "qtest_onvchar", __FILE__ ) + << qTableName( "qtestPK", __FILE__ ); tst_Databases::safeDropTables( db, tableNames ); } @@ -185,8 +186,8 @@ void tst_Q3SqlCursor::populateTestTables( QSqlDatabase db ) return; QSqlQuery q( db ); - q.exec( "delete from " + qTableName( "qtest" ) ); //not fatal - QVERIFY_SQL(q, prepare("insert into " + qTableName( "qtest" ) + " (id, t_varchar, t_char, t_numeric) values (?, ?, ?, ?)")); + q.exec( "delete from " + qtest ); //not fatal + QVERIFY_SQL(q, prepare("insert into " + qtest + " (id, t_varchar, t_char, t_numeric) values (?, ?, ?, ?)")); q.addBindValue(QVariantList() << 0 << 1 << 2 << 3); q.addBindValue(QVariantList() << "VarChar0" << "VarChar1" << "VarChar2" << "VarChar3"); q.addBindValue(QVariantList() << "Char0" << "Char1" << "Char2" << "Char3"); @@ -243,7 +244,7 @@ void tst_Q3SqlCursor::copyConstructor() Q3SqlCursor cur2; { - Q3SqlCursor cur( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur( qtest, true, db ); QVERIFY_SQL(cur, select( cur.index( QString("id") ) )); cur2 = Q3SqlCursor( cur ); // let "cur" run out of scope... @@ -266,7 +267,7 @@ void tst_Q3SqlCursor::value() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - Q3SqlCursor cur( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur( qtest, true, db ); QVERIFY_SQL(cur, select( cur.index( QString("id") ) )); int i = 0; while ( cur.next() ) { @@ -281,7 +282,7 @@ void tst_Q3SqlCursor::primaryIndex() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - Q3SqlCursor cur( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur( qtest, true, db ); QSqlIndex index = cur.primaryIndex(); if ( tst_Databases::isMSAccess( db ) ) { QCOMPARE( index.fieldName(1).upper(), QString( "ID" ) ); @@ -300,7 +301,7 @@ void tst_Q3SqlCursor::insert() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - Q3SqlCursor cur( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur( qtest, true, db ); QSqlRecord* irec = cur.primeInsert(); QVERIFY( irec != 0 ); @@ -338,7 +339,7 @@ void tst_Q3SqlCursor::insertSpecial() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - Q3SqlCursor cur( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur( qtest, true, db ); QSqlRecord* irec = cur.primeInsert(); QVERIFY( irec != 0 ); @@ -386,9 +387,9 @@ void tst_Q3SqlCursor::batchInsert() CHECK_DATABASE( db ); QSqlQuery q( db ); - q.exec( "delete from " + qTableName( "qtest" ) ); + q.exec( "delete from " + qtest ); - Q3SqlCursor cur( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur( qtest, true, db ); int i = 0; for ( ; i < 100; ++i ) { @@ -420,7 +421,7 @@ void tst_Q3SqlCursor::batchInsert() } i = 0; - QVERIFY_SQL(q, exec( "select * from " + qTableName( "qtest" ) + " order by id" )); + QVERIFY_SQL(q, exec( "select * from " + qtest + " order by id" )); while ( q.next() ) { QCOMPARE( q.value( 0 ).toInt(), i ); i++; @@ -452,11 +453,11 @@ void tst_Q3SqlCursor::insertORA() /****** CHARSET TEST ******/ QSqlQuery q( db ); - QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest_ovchar" ) + " ( id int primary key, t_char varchar(40) )" )); + QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest_ovchar", __FILE__ ) + " ( id int primary key, t_char varchar(40) )" )); static const QString val1( "blah1" ); - Q3SqlCursor cur ( qTableName( "qtest_ovchar" ), true, db ); + Q3SqlCursor cur ( qTableName( "qtest_ovchar", __FILE__ ), true, db ); QSqlRecord* irec = cur.primeInsert(); irec->setValue( "id", 1 ); irec->setValue( "t_char", val1 ); @@ -486,9 +487,9 @@ void tst_Q3SqlCursor::insertORA() /****** NCHARSET TEST ********/ - QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest_onvchar" ) + " ( id int primary key, t_nchar nvarchar2(40) )" )); + QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest_onvchar", __FILE__ ) + " ( id int primary key, t_nchar nvarchar2(40) )" )); - Q3SqlCursor cur2 ( qTableName( "qtest_onvchar" ), true, db ); + Q3SqlCursor cur2 ( qTableName( "qtest_onvchar", __FILE__ ), true, db ); irec = cur2.primeInsert(); irec->setValue( "id", 1 ); irec->setValue( "t_nchar", val1 ); @@ -529,7 +530,7 @@ void tst_Q3SqlCursor::unicode() if(db.driverName().startsWith("QIBASE") && (db.databaseName() == "silence.nokia.troll.no:c:\\ibase\\testdb_ascii" || db.databaseName() == "/opt/interbase/qttest.gdb")) QSKIP("Can't transliterate extended unicode to ascii", SkipSingle); - Q3SqlCursor cur( qTableName( "qtest_unicode" ), true, db ); + Q3SqlCursor cur( qTableName( "qtest_unicode", __FILE__ ), true, db ); QSqlRecord* irec = cur.primeInsert(); irec->setValue( 0, 500 ); irec->setValue( 1, utf8str ); @@ -566,7 +567,7 @@ void tst_Q3SqlCursor::precision() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - Q3SqlCursor cur( qTableName( "qtest_precision" ), true, db ); + Q3SqlCursor cur( qTableName( "qtest_precision", __FILE__ ), true, db ); cur.setTrimmed( "col1", true ); QSqlRecord* irec = cur.primeInsert(); irec->setValue( 0, precStr ); @@ -589,7 +590,7 @@ void tst_Q3SqlCursor::setFilter() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - Q3SqlCursor cur( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur( qtest, true, db ); cur.setFilter( "id = 2" ); QVERIFY_SQL(cur, select()); @@ -619,23 +620,23 @@ void tst_Q3SqlCursor::select() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - Q3SqlCursor cur( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur( qtest, true, db ); QVERIFY_SQL(cur, select()); QVERIFY( cur.next() ); QVERIFY( cur.next() ); - Q3SqlCursor cur2( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur2( qtest, true, db ); QVERIFY_SQL(cur2, select( "id = 1" )); QVERIFY( cur2.next() ); QCOMPARE( cur2.value( 0 ).toInt(), 1 ); - Q3SqlCursor cur3( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur3( qtest, true, db ); QVERIFY_SQL(cur3, select( cur3.primaryIndex( false ) )); QVERIFY( cur3.next() ); QVERIFY( cur3.next() ); QCOMPARE( cur3.value( 0 ).toInt(), 1 ); - Q3SqlCursor cur4( qTableName( "qtest" ), true, db ); + Q3SqlCursor cur4( qtest, true, db ); QSqlIndex idx = cur4.primaryIndex( false ); QCOMPARE( (int)idx.count(), 2 ); if ( tst_Databases::isMSAccess( db ) ) { @@ -667,17 +668,17 @@ void tst_Q3SqlCursor::setName() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - Q3SqlCursor c2( qTableName( "qtest" ), true, db ); - QCOMPARE( c2.name(), qTableName( "qtest" ) ); + Q3SqlCursor c2( qtest, true, db ); + QCOMPARE( c2.name(), qtest ); QCOMPARE( c2.fieldName( 0 ).lower(), QString( "id" ) ); Q3SqlCursor c( QString(), true, db ); - c.setName( qTableName( "qtest" ) ); - QCOMPARE( c.name(), qTableName( "qtest" ) ); + c.setName( qtest ); + QCOMPARE( c.name(), qtest ); QCOMPARE( c.fieldName( 0 ).lower(), QString( "id" ) ); - c.setName( qTableName( "qtest_precision" ) ); - QCOMPARE( c.name(), qTableName( "qtest_precision" ) ); + c.setName( qTableName( "qtest_precision", __FILE__ ) ); + QCOMPARE( c.name(), qTableName( "qtest_precision", __FILE__ ) ); QCOMPARE( c.fieldName( 0 ).lower(), QString( "col1" ) ); } @@ -689,9 +690,9 @@ void tst_Q3SqlCursor::updateNoPK() CHECK_DATABASE( db ); QSqlQuery q(db); - QVERIFY_SQL(q, exec("create table " + qTableName( "qtestPK" ) + " (id int, name varchar(20), num numeric)")); + QVERIFY_SQL(q, exec("create table " + qTableName( "qtestPK", __FILE__ ) + " (id int, name varchar(20), num numeric)")); - Q3SqlCursor cur(qTableName("qtestPK"), true, db); + Q3SqlCursor cur(qTableName("qtestPK", __FILE__), true, db); QSqlRecord* rec = cur.primeInsert(); Q_ASSERT(rec); rec->setNull(0); @@ -705,14 +706,14 @@ void tst_Q3SqlCursor::updateNoPK() db.driverName().startsWith("QMYSQL") || db.driverName().startsWith("QODBC") || db.driverName().startsWith("QOCI")) { - QString query = QString::fromLatin1("insert into " + qTableName("qtestPK") + + QString query = QString::fromLatin1("insert into " + qTableName("qtestPK", __FILE__) + " (" + db.driver()->escapeIdentifier("id", QSqlDriver::FieldName) + ',' + db.driver()->escapeIdentifier("name", QSqlDriver::FieldName) + ',' + db.driver()->escapeIdentifier("num", QSqlDriver::FieldName) + ')' + " values (NULL,NULL,NULL)"); QCOMPARE(cur.lastQuery(), query); } else { - QCOMPARE(cur.lastQuery(), QString::fromLatin1("insert into " + qTableName("qtestPK") + + QCOMPARE(cur.lastQuery(), QString::fromLatin1("insert into " + qTableName("qtestPK", __FILE__) + " (\"id\",\"name\",\"num\") values (NULL,NULL,NULL)")); } } @@ -724,12 +725,12 @@ void tst_Q3SqlCursor::updateNoPK() rec->setNull(2); // Sqlite returns 2, don't ask why. QVERIFY(cur.update() != 0); - QString expect = "update " + qTableName("qtestPK") + + QString expect = "update " + qTableName("qtestPK", __FILE__) + " set "+db.driver()->escapeIdentifier("id", QSqlDriver::FieldName)+" = 1 , " +db.driver()->escapeIdentifier("name", QSqlDriver::FieldName)+" = NULL , " - +db.driver()->escapeIdentifier("num", QSqlDriver::FieldName)+" = NULL where " + qTableName("qtestPK") + ".id" - " IS NULL and " + qTableName("qtestPK") + ".name IS NULL and " + - qTableName("qtestPK") + ".num IS NULL"; + +db.driver()->escapeIdentifier("num", QSqlDriver::FieldName)+" = NULL where " + qTableName("qtestPK", __FILE__) + ".id" + " IS NULL and " + qTableName("qtestPK", __FILE__) + ".name IS NULL and " + + qTableName("qtestPK", __FILE__) + ".num IS NULL"; if (!db.driver()->hasFeature(QSqlDriver::PreparedQueries)) { if (!db.driverName().startsWith("QSQLITE")) { QCOMPARE(cur.lastQuery(), expect); @@ -760,7 +761,7 @@ void tst_Q3SqlCursor::insertFieldNameContainsWS() { return; } - QString tableName = qTableName("qtestws"); + QString tableName = qTableName("qtestws", __FILE__); QSqlQuery q(db); tst_Databases::safeDropTable(db, tableName); diff --git a/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp b/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp index c19f9fd..b69ae79 100644 --- a/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp +++ b/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp @@ -111,16 +111,16 @@ void tst_Q3SqlSelectCursor::createTestTables( QSqlDatabase db ) QVERIFY_SQL( q, exec("set client_min_messages='warning'")); // please never ever change this table; otherwise fix all tests ;) if (tst_Databases::isMSAccess(db)) - QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest" ) + " ( id int not null, t_varchar varchar(40) not null," + QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest", __FILE__ ) + " ( id int not null, t_varchar varchar(40) not null," "t_char char(40), t_numeric number, primary key (id, t_varchar) )" )); else - QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest" ) + " ( id int not null, t_varchar varchar(40) not null," + QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest", __FILE__ ) + " ( id int not null, t_varchar varchar(40) not null," "t_char char(40), t_numeric numeric(6, 3), primary key (id, t_varchar) )" )); } void tst_Q3SqlSelectCursor::dropTestTables( QSqlDatabase db ) { - tst_Databases::safeDropTable( db, qTableName( "qtest" ) ); + tst_Databases::safeDropTable( db, qTableName( "qtest", __FILE__ ) ); } void tst_Q3SqlSelectCursor::populateTestTables( QSqlDatabase db ) @@ -129,11 +129,11 @@ void tst_Q3SqlSelectCursor::populateTestTables( QSqlDatabase db ) return; QSqlQuery q( db ); - q.exec( "delete from " + qTableName( "qtest" ) ); //non-fatal - QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest" ) + " (id, t_varchar, t_char, t_numeric) values ( 0, 'VarChar0', 'Char0', 1.1 )" )); - QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest" ) + " (id, t_varchar, t_char, t_numeric) values ( 1, 'VarChar1', 'Char1', 2.2 )" )); - QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest" ) + " (id, t_varchar, t_char, t_numeric) values ( 2, 'VarChar2', 'Char2', 3.3 )" )); - QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest" ) + " (id, t_varchar, t_char, t_numeric) values ( 3, 'VarChar3', 'Char3', 4.4 )" )); + q.exec( "delete from " + qTableName( "qtest", __FILE__ ) ); //non-fatal + QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest", __FILE__ ) + " (id, t_varchar, t_char, t_numeric) values ( 0, 'VarChar0', 'Char0', 1.1 )" )); + QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest", __FILE__ ) + " (id, t_varchar, t_char, t_numeric) values ( 1, 'VarChar1', 'Char1', 2.2 )" )); + QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest", __FILE__ ) + " (id, t_varchar, t_char, t_numeric) values ( 2, 'VarChar2', 'Char2', 3.3 )" )); + QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest", __FILE__ ) + " (id, t_varchar, t_char, t_numeric) values ( 3, 'VarChar3', 'Char3', 4.4 )" )); } void tst_Q3SqlSelectCursor::initTestCase() @@ -184,7 +184,7 @@ void tst_Q3SqlSelectCursor::value() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - Q3SqlSelectCursor cur( "select * from " + qTableName( "qtest" ) + " order by id", db ); + Q3SqlSelectCursor cur( "select * from " + qTableName( "qtest", __FILE__ ) + " order by id", db ); QVERIFY( cur.select() ); QVERIFY_SQL(cur, isActive()); int i = 0; @@ -203,7 +203,7 @@ void tst_Q3SqlSelectCursor::_exec() Q3SqlSelectCursor cur( QString(), db ); QVERIFY_SQL(cur, isActive() == false); - cur.exec( "select * from " + qTableName( "qtest" ) ); //nothing should happen + cur.exec( "select * from " + qTableName( "qtest", __FILE__ ) ); //nothing should happen QVERIFY_SQL(cur, isActive()); int i = 0; while ( cur.next() ) { diff --git a/tests/auto/qsqldatabase/tst_databases.h b/tests/auto/qsqldatabase/tst_databases.h index 4e99f18..5837719 100644 --- a/tests/auto/qsqldatabase/tst_databases.h +++ b/tests/auto/qsqldatabase/tst_databases.h @@ -95,12 +95,14 @@ static QString qGetHostName() // to prevent nameclashes on our database server, each machine // will use its own set of table names. Call this function to get // "tablename_hostname" -inline static QString qTableName( const QString& prefix, QSqlDriver* driver = 0 ) +inline static QString qTableName( const QString& prefix, const char *sourceFileName ) { - if ( !driver ) - return prefix + "_" + qGetHostName().replace( "-", "_" ); - else - return driver->escapeIdentifier( prefix + "_" + qGetHostName(), QSqlDriver::TableName ); + return QLatin1String("dbtst")+QString::number(qHash(QLatin1String(sourceFileName) + "_" + qGetHostName().replace( "-", "_" )), 16)+"_"+prefix; +} + +inline static QString qTableName( const QString& prefix, QSqlDriver* driver ) +{ + return driver->escapeIdentifier( prefix + "_" + qGetHostName(), QSqlDriver::TableName ); } inline static bool testWhiteSpaceNames( const QString &name ) @@ -250,8 +252,8 @@ public: // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=iceblink.nokia.troll.no\\ICEBLINK", "troll", "trond", "" ); // addDb( "QODBC3", "DRIVER={SQL Native Client};SERVER=silence.nokia.troll.no\\SQLEXPRESS", "troll", "trond", "" ); -// addDb( "QODBC", "DRIVER={MySQL ODBC 5.1 Driver};SERVER=mysql5-nokia.trolltech.com.au;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); -// addDb( "QODBC", "DRIVER={MySQL ODBC 5.1 Driver};SERVER=mysql4-nokia.trolltech.com.au;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); +// addDb( "QODBC", "DRIVER={MySQL ODBC 5.1 Driver};SERVER=bq-mysql50.apac.nokia.com;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); +// addDb( "QODBC", "DRIVER={MySQL ODBC 5.1 Driver};SERVER=bq-mysql51.apac.nokia.com;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=horsehead.nokia.troll.no;DATABASE=testdb;PORT=4101;UID=troll;PWD=trondk", "troll", "trondk", "" ); // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=silence.nokia.troll.no;DATABASE=testdb;PORT=2392;UID=troll;PWD=trond", "troll", "trond", "" ); // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=bq-winserv2003-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433;UID=testuser;PWD=Ee4Gabf6_;TDS_Version=8.0", "", "", "" ); @@ -261,7 +263,7 @@ public: // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=bq-winserv2003-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433", "testuser", "Ee4Gabf6_", "" ); // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=bq-winserv2008-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433", "testuser", "Ee4Gabf6_", "" ); // addDb( "QODBC", "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dbs\\access\\testdb.mdb", "", "", "" ); -// addDb( "QODBC", "DRIVER={Postgresql};SERVER=postgres81-nokia.trolltech.com.au;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); +// addDb( "QODBC", "DRIVER={Postgresql};SERVER=bq-pgsql84.apac.nokia.com;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); } void open() @@ -338,7 +340,7 @@ public: foreach(const QString &table2, dbtables.filter(table, Qt::CaseInsensitive)) { if(table2.compare(table.section('.', -1, -1), Qt::CaseInsensitive) == 0) { table=db.driver()->escapeIdentifier(table2, QSqlDriver::TableName); - if(db.driverName().startsWith( "QPSQL" )) + if(isPostgreSQL(db)) wasDropped = q.exec( "drop table " + table + " cascade"); else wasDropped = q.exec( "drop table " + table); @@ -483,16 +485,16 @@ public: static bool isPostgreSQL( QSqlDatabase db ) { - return db.driverName().startsWith("QPSQL") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("PostgreSQL") ); + return db.driverName().startsWith("QPSQL") || (db.driverName().startsWith("QODBC") && ( db.databaseName().contains("PostgreSQL", Qt::CaseInsensitive) || db.databaseName().contains("pgsql", Qt::CaseInsensitive) ) ); } static bool isMySQL( QSqlDatabase db ) { - return db.driverName().startsWith("QMYSQL") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("MySQL") ); + return db.driverName().startsWith("QMYSQL") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("MySQL", Qt::CaseInsensitive) ); } static bool isDB2( QSqlDatabase db ) { - return db.driverName().startsWith("QDB2") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("db2") ); + return db.driverName().startsWith("QDB2") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("db2", Qt::CaseInsensitive) ); } // -1 on fail, else Oracle version diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp index fe084fa..b2b592b 100644 --- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp @@ -259,10 +259,10 @@ struct FieldDef { // excluding the primary key field static int createFieldTable(const FieldDef fieldDefs[], QSqlDatabase db) { - tst_Databases::safeDropTable(db, qTableName("qtestfields")); + tst_Databases::safeDropTable(db, qTableName("qtestfields", __FILE__)); QSqlQuery q(db); // construct a create table statement consisting of all fieldtypes - QString qs = "create table " + qTableName("qtestfields"); + QString qs = "create table " + qTableName("qtestfields", __FILE__); QString autoName = tst_Databases::autoFieldName(db); if (tst_Databases::isMSAccess(db)) qs.append(" (id int not null"); @@ -316,18 +316,18 @@ void tst_QSqlDatabase::createTestTables(QSqlDatabase db) // please never ever change this table; otherwise fix all tests ;) if (tst_Databases::isMSAccess(db)) { - QVERIFY_SQL(q, exec("create table " + qTableName("qtest") + + QVERIFY_SQL(q, exec("create table " + qTableName("qtest", __FILE__) + " (id int not null, t_varchar varchar(40) not null, t_char char(40), " "t_numeric number, primary key (id, t_varchar))")); } else { - QVERIFY_SQL(q, exec("create table " + qTableName("qtest") + + QVERIFY_SQL(q, exec("create table " + qTableName("qtest", __FILE__) + " (id integer not null, t_varchar varchar(40) not null, " "t_char char(40), t_numeric numeric(6, 3), primary key (id, t_varchar))")); } if (testWhiteSpaceNames(db.driverName())) { QString qry = "create table " - + db.driver()->escapeIdentifier(qTableName("qtest") + " test", QSqlDriver::TableName) + + db.driver()->escapeIdentifier(qTableName("qtest", __FILE__) + " test", QSqlDriver::TableName) + '(' + db.driver()->escapeIdentifier(QLatin1String("test test"), QSqlDriver::FieldName) + " int not null primary key)"; @@ -346,45 +346,45 @@ void tst_QSqlDatabase::dropTestTables(QSqlDatabase db) } // drop the view first, otherwise we'll get dependency problems - tst_Databases::safeDropViews(db, QStringList() << qTableName("qtest_view") << qTableName("qtest_view2")); + tst_Databases::safeDropViews(db, QStringList() << qTableName("qtest_view", __FILE__) << qTableName("qtest_view2", __FILE__)); QStringList tableNames; - tableNames << qTableName("qtest") - << qTableName("qtestfields") - << qTableName("qtestalter") - << qTableName("qtest_temp") - << qTableName("qtest_bigint") - << qTableName("qtest_xmltype") - << qTableName("latin1table") - << qTableName("qtest_sqlguid") - << qTableName("batable") - << qTableName("qtest_prec") - << qTableName("uint") - << qTableName("strings") - << qTableName("numericfields") - << qTableName("qtest_ibaseblobs") - << qTableName("qtestBindBool") - << qTableName("testqGetString") - << qTableName("qtest_sqlguid") - << qTableName("uint_table") - << qTableName("uint_test") - << qTableName("bug_249059"); + tableNames << qTableName("qtest", __FILE__) + << qTableName("qtestfields", __FILE__) + << qTableName("qtestalter", __FILE__) + << qTableName("qtest_temp", __FILE__) + << qTableName("qtest_bigint", __FILE__) + << qTableName("qtest_xmltype", __FILE__) + << qTableName("latin1table", __FILE__) + << qTableName("qtest_sqlguid", __FILE__) + << qTableName("batable", __FILE__) + << qTableName("qtest_prec", __FILE__) + << qTableName("uint", __FILE__) + << qTableName("strings", __FILE__) + << qTableName("numericfields", __FILE__) + << qTableName("qtest_ibaseblobs", __FILE__) + << qTableName("qtestBindBool", __FILE__) + << qTableName("testqGetString", __FILE__) + << qTableName("qtest_sqlguid", __FILE__) + << qTableName("uint_table", __FILE__) + << qTableName("uint_test", __FILE__) + << qTableName("bug_249059", __FILE__); QSqlQuery q(0, db); if (db.driverName().startsWith("QPSQL")) { - q.exec("drop schema " + qTableName("qtestschema") + " cascade"); - q.exec("drop schema " + qTableName("qtestScHeMa") + " cascade"); + q.exec("drop schema " + qTableName("qtestschema", __FILE__) + " cascade"); + q.exec("drop schema " + qTableName("qtestScHeMa", __FILE__) + " cascade"); } if (testWhiteSpaceNames(db.driverName())) - tableNames << db.driver()->escapeIdentifier(qTableName("qtest") + " test", QSqlDriver::TableName); + tableNames << db.driver()->escapeIdentifier(qTableName("qtest", __FILE__) + " test", QSqlDriver::TableName); tst_Databases::safeDropTables(db, tableNames); if (db.driverName().startsWith("QOCI")) { - q.exec("drop user "+qTableName("CREATOR")+" cascade"); - q.exec("drop user "+qTableName("APPUSER")+" cascade"); - q.exec("DROP TABLE system."+qTableName("mypassword")); + q.exec("drop user "+qTableName("CREATOR", __FILE__)+" cascade"); + q.exec("drop user "+qTableName("APPUSER", __FILE__)+" cascade"); + q.exec("DROP TABLE system."+qTableName("mypassword", __FILE__)); } } @@ -394,13 +394,14 @@ void tst_QSqlDatabase::populateTestTables(QSqlDatabase db) if (!db.isValid()) return; QSqlQuery q(db); + const QString qtest(qTableName("qtest", __FILE__)); - q.exec("delete from " + qTableName("qtest")); //non-fatal - QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (0, 'VarChar0', 'Char0', 1.1)")); - QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (1, 'VarChar1', 'Char1', 2.2)")); - QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (2, 'VarChar2', 'Char2', 3.3)")); - QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (3, 'VarChar3', 'Char3', 4.4)")); - QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (4, 'VarChar4', NULL, NULL)")); + q.exec("delete from " + qtest); //non-fatal + QVERIFY_SQL(q, exec("insert into " + qtest + " (id, t_varchar, t_char, t_numeric) values (0, 'VarChar0', 'Char0', 1.1)")); + QVERIFY_SQL(q, exec("insert into " + qtest + " (id, t_varchar, t_char, t_numeric) values (1, 'VarChar1', 'Char1', 2.2)")); + QVERIFY_SQL(q, exec("insert into " + qtest + " (id, t_varchar, t_char, t_numeric) values (2, 'VarChar2', 'Char2', 3.3)")); + QVERIFY_SQL(q, exec("insert into " + qtest + " (id, t_varchar, t_char, t_numeric) values (3, 'VarChar3', 'Char3', 4.4)")); + QVERIFY_SQL(q, exec("insert into " + qtest + " (id, t_varchar, t_char, t_numeric) values (4, 'VarChar4', NULL, NULL)")); } void tst_QSqlDatabase::initTestCase() @@ -496,7 +497,7 @@ void tst_QSqlDatabase::recordNonSelect() Q3SqlRecordInfo rInf = db.recordInfo(q); QVERIFY(rInf.isEmpty()); - QVERIFY_SQL(q, exec("create table " + qTableName("qtest_temp") + " (id int)")); + QVERIFY_SQL(q, exec("create table " + qTableName("qtest_temp", __FILE__) + " (id int)")); // query without result set should return empty record rec = db.record(q); @@ -512,6 +513,8 @@ void tst_QSqlDatabase::tables() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); + const QString qtest(qTableName("qtest", __FILE__)), qtest_view(qTableName("qtest_view", __FILE__)), temp_tab(qTableName("test_tab", __FILE__)); + bool views = true; bool tempTables = false; @@ -520,50 +523,50 @@ void tst_QSqlDatabase::tables() QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); - if (!q.exec("CREATE VIEW " + qTableName("qtest_view") + " as select * from " + qTableName("qtest"))) { + if (!q.exec("CREATE VIEW " + qtest_view + " as select * from " + qtest)) { qDebug(QString("DBMS '%1' cannot handle VIEWs: %2").arg( tst_Databases::dbToString(db)).arg(QString(tst_Databases::printError(q.lastError()))).toLatin1()); views = false; } if (db.driverName().startsWith("QSQLITE3")) { - QVERIFY_SQL(q, exec("CREATE TEMPORARY TABLE " + qTableName("temp_tab") + " (id int)")); + QVERIFY_SQL(q, exec("CREATE TEMPORARY TABLE " + temp_tab + " (id int)")); tempTables = true; } QStringList tables = db.tables(QSql::Tables); - QVERIFY(tables.contains(qTableName("qtest"), Qt::CaseInsensitive)); + QVERIFY(tables.contains(qtest, Qt::CaseInsensitive)); QVERIFY(!tables.contains("sql_features", Qt::CaseInsensitive)); //check for postgres 7.4 internal tables if (views) { - QVERIFY(!tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive)); + QVERIFY(!tables.contains(qtest_view, Qt::CaseInsensitive)); } if (tempTables) - QVERIFY(tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive)); + QVERIFY(tables.contains(temp_tab, Qt::CaseInsensitive)); tables = db.tables(QSql::Views); if (views) { - if(!tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive)) - qDebug() << "failed to find" << qTableName("qtest_view") << "in" << tables; - QVERIFY(tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive)); + if(!tables.contains(qtest_view, Qt::CaseInsensitive)) + qDebug() << "failed to find" << qtest_view << "in" << tables; + QVERIFY(tables.contains(qtest_view, Qt::CaseInsensitive)); } if (tempTables) - QVERIFY(!tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive)); - QVERIFY(!tables.contains(qTableName("qtest"), Qt::CaseInsensitive)); + QVERIFY(!tables.contains(temp_tab, Qt::CaseInsensitive)); + QVERIFY(!tables.contains(qtest, Qt::CaseInsensitive)); tables = db.tables(QSql::SystemTables); - QVERIFY(!tables.contains(qTableName("qtest"), Qt::CaseInsensitive)); - QVERIFY(!tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive)); - QVERIFY(!tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive)); + QVERIFY(!tables.contains(qtest, Qt::CaseInsensitive)); + QVERIFY(!tables.contains(qtest_view, Qt::CaseInsensitive)); + QVERIFY(!tables.contains(temp_tab, Qt::CaseInsensitive)); tables = db.tables(QSql::AllTables); if (views) - QVERIFY(tables.contains(qTableName("qtest_view"), Qt::CaseInsensitive)); + QVERIFY(tables.contains(qtest_view, Qt::CaseInsensitive)); if (tempTables) - QVERIFY(tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive)); - QVERIFY(tables.contains(qTableName("qtest"), Qt::CaseInsensitive)); + QVERIFY(tables.contains(temp_tab, Qt::CaseInsensitive)); + QVERIFY(tables.contains(qtest, Qt::CaseInsensitive)); if (db.driverName().startsWith("QPSQL")) { - QVERIFY(tables.contains(qTableName("qtest") + " test")); + QVERIFY(tables.contains(qtest + " test")); } } @@ -574,7 +577,7 @@ void tst_QSqlDatabase::whitespaceInIdentifiers() CHECK_DATABASE(db); if (testWhiteSpaceNames(db.driverName())) { - QString tableName = qTableName("qtest") + " test"; + const QString tableName(qTableName("qtest", __FILE__) + " test"); QVERIFY(db.tables().contains(tableName, Qt::CaseInsensitive)); QSqlRecord rec = db.record(db.driver()->escapeIdentifier(tableName, QSqlDriver::TableName)); @@ -602,14 +605,15 @@ void tst_QSqlDatabase::alterTable() QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); + const QString qtestalter(qTableName("qtestalter", __FILE__)); QSqlQuery q(db); - QVERIFY_SQL(q, exec("create table " + qTableName("qtestalter") + " (F1 char(20), F2 char(20), F3 char(20))")); - QSqlRecord rec = db.record(qTableName("qtestalter")); + QVERIFY_SQL(q, exec("create table " + qtestalter + " (F1 char(20), F2 char(20), F3 char(20))")); + QSqlRecord rec = db.record(qtestalter); QCOMPARE((int)rec.count(), 3); #ifdef QT3_SUPPORT - Q3SqlRecordInfo rinf = db.recordInfo(qTableName("qtestalter")); + Q3SqlRecordInfo rinf = db.recordInfo(qtestalter); QCOMPARE((int)rinf.count(), 3); #endif @@ -622,13 +626,13 @@ void tst_QSqlDatabase::alterTable() #endif } - if (!q.exec("alter table " + qTableName("qtestalter") + " drop column F2")) { + if (!q.exec("alter table " + qtestalter + " drop column F2")) { QSKIP("DBMS doesn't support dropping columns in ALTER TABLE statement", SkipSingle); } - rec = db.record(qTableName("qtestalter")); + rec = db.record(qtestalter); #ifdef QT3_SUPPORT - rinf = db.recordInfo(qTableName("qtestalter")); + rinf = db.recordInfo(qtestalter); #endif QCOMPARE((int)rec.count(), 2); @@ -643,7 +647,7 @@ void tst_QSqlDatabase::alterTable() QCOMPARE(rinf[ 1 ].name().upper(), QString("F3")); #endif - q.exec("select * from " + qTableName("qtestalter")); + q.exec("select * from " + qtestalter); #ifdef QT3_SUPPORT rec = db.record(q); @@ -730,17 +734,17 @@ void tst_QSqlDatabase::commonFieldTest(const FieldDef fieldDefs[], QSqlDatabase // check whether recordInfo returns the right types #ifdef QT3_SUPPORT - Q3SqlRecordInfo inf = db.recordInfo(qTableName("qtestfields")); + Q3SqlRecordInfo inf = db.recordInfo(qTableName("qtestfields", __FILE__)); QCOMPARE((int)inf.count(), fieldCount+1); testRecordInfo(fieldDefs, inf); #endif - QSqlRecord rec = db.record(qTableName("qtestfields")); + QSqlRecord rec = db.record(qTableName("qtestfields", __FILE__)); QCOMPARE((int)rec.count(), fieldCount+1); testRecord(fieldDefs, rec, db); QSqlQuery q(db); - QVERIFY_SQL(q, exec("select * from " + qTableName("qtestfields"))); + QVERIFY_SQL(q, exec("select * from " + qTableName("qtestfields", __FILE__))); #ifdef QT3_SUPPORT inf = db.recordInfo(q); @@ -760,7 +764,7 @@ void tst_QSqlDatabase::checkValues(const FieldDef fieldDefs[], QSqlDatabase db) #ifdef QT3_SUPPORT CHECK_DATABASE(db); - Q3SqlCursor cur(qTableName("qtestfields"), true, db); + Q3SqlCursor cur(qTableName("qtestfields", __FILE__), true, db); QVERIFY_SQL(cur, select()); QSqlRecord* rec = cur.primeInsert(); Q_ASSERT(rec); @@ -821,7 +825,7 @@ void tst_QSqlDatabase::checkNullValues(const FieldDef fieldDefs[], QSqlDatabase #ifdef QT3_SUPPORT CHECK_DATABASE(db); - Q3SqlCursor cur(qTableName("qtestfields"), true, db); + Q3SqlCursor cur(qTableName("qtestfields", __FILE__), true, db); QVERIFY_SQL(cur, select()); QSqlRecord* rec = cur.primeInsert(); Q_ASSERT(rec); @@ -955,12 +959,12 @@ void tst_QSqlDatabase::recordOCI() checkValues(fieldDefs, db); // some additional tests - QSqlRecord rec = db.record(qTableName("qtestfields")); + QSqlRecord rec = db.record(qTableName("qtestfields", __FILE__)); QCOMPARE(rec.field("T_NUMBER").length(), 10); QCOMPARE(rec.field("T_NUMBER").precision(), 5); QSqlQuery q(db); - QVERIFY_SQL(q, exec("SELECT * FROM " + qTableName("qtestfields"))); + QVERIFY_SQL(q, exec("SELECT * FROM " + qTableName("qtestfields", __FILE__))); rec = q.record(); QCOMPARE(rec.field("T_NUMBER").length(), 10); QCOMPARE(rec.field("T_NUMBER").precision(), 5); @@ -1024,11 +1028,11 @@ void tst_QSqlDatabase::recordPSQL() if(tst_Databases::isPostgreSQL(db)) QVERIFY_SQL( q, exec("set client_min_messages='warning'")); - q.exec("drop sequence " + qTableName("qtestfields") + "_t_bigserial_seq"); - q.exec("drop sequence " + qTableName("qtestfields") + "_t_serial_seq"); + q.exec("drop sequence " + qTableName("qtestfields", __FILE__) + "_t_bigserial_seq"); + q.exec("drop sequence " + qTableName("qtestfields", __FILE__) + "_t_serial_seq"); // older psql cut off the table name - q.exec("drop sequence " + qTableName("qtestfields").left(15) + "_t_bigserial_seq"); - q.exec("drop sequence " + qTableName("qtestfields").left(18) + "_t_serial_seq"); + q.exec("drop sequence " + qTableName("qtestfields", __FILE__).left(15) + "_t_bigserial_seq"); + q.exec("drop sequence " + qTableName("qtestfields", __FILE__).left(18) + "_t_serial_seq"); const int fieldCount = createFieldTable(fieldDefs, db); QVERIFY(fieldCount > 0); @@ -1325,6 +1329,7 @@ void tst_QSqlDatabase::transaction() QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); + const QString qtest(qTableName("qtest", __FILE__)); if (!db.driver()->hasFeature(QSqlDriver::Transactions)) { QSKIP("DBMS not transaction capable", SkipSingle); @@ -1333,8 +1338,8 @@ void tst_QSqlDatabase::transaction() QVERIFY(db.transaction()); QSqlQuery q(db); - QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " values (40, 'VarChar40', 'Char40', 40.40)")); - QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 40")); + QVERIFY_SQL(q, exec("insert into " + qtest + " values (40, 'VarChar40', 'Char40', 40.40)")); + QVERIFY_SQL(q, exec("select * from " + qtest + " where id = 40")); QVERIFY(q.next()); QCOMPARE(q.value(0).toInt(), 40); q.clear(); @@ -1342,15 +1347,15 @@ void tst_QSqlDatabase::transaction() QVERIFY(db.commit()); QVERIFY(db.transaction()); - QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 40")); + QVERIFY_SQL(q, exec("select * from " + qtest + " where id = 40")); QVERIFY(q.next()); QCOMPARE(q.value(0).toInt(), 40); q.clear(); QVERIFY(db.commit()); QVERIFY(db.transaction()); - QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " values (41, 'VarChar41', 'Char41', 41.41)")); - QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 41")); + QVERIFY_SQL(q, exec("insert into " + qtest + " values (41, 'VarChar41', 'Char41', 41.41)")); + QVERIFY_SQL(q, exec("select * from " + qtest + " where id = 41")); QVERIFY(q.next()); QCOMPARE(q.value(0).toInt(), 41); q.clear(); // for SQLite which does not allow any references on rows that shall be rolled back @@ -1363,7 +1368,7 @@ void tst_QSqlDatabase::transaction() } } - QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 41")); + QVERIFY_SQL(q, exec("select * from " + qtest + " where id = 41")); if(db.driverName().startsWith("QODBC") && dbName.contains("MySQL")) QEXPECT_FAIL("", "Some odbc drivers don't actually roll back despite telling us they do, especially the mysql driver", Continue); QVERIFY(!q.next()); @@ -1377,6 +1382,7 @@ void tst_QSqlDatabase::bigIntField() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); QString drvName = db.driverName(); + const QString qtest_bigint(qTableName("qtest_bigint", __FILE__)); QSqlQuery q(db); q.setForwardOnly(true); @@ -1384,19 +1390,19 @@ void tst_QSqlDatabase::bigIntField() q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64); if (drvName.startsWith("QMYSQL")) { - QVERIFY_SQL(q, exec("create table " + qTableName("qtest_bigint") + " (id int, t_s64bit bigint, t_u64bit bigint unsigned)")); + QVERIFY_SQL(q, exec("create table " + qtest_bigint + " (id int, t_s64bit bigint, t_u64bit bigint unsigned)")); } else if (drvName.startsWith("QPSQL") || drvName.startsWith("QDB2") || tst_Databases::isSqlServer(db)) { - QVERIFY_SQL(q, exec("create table " + qTableName("qtest_bigint") + "(id int, t_s64bit bigint, t_u64bit bigint)")); + QVERIFY_SQL(q, exec("create table " + qtest_bigint + "(id int, t_s64bit bigint, t_u64bit bigint)")); } else if (drvName.startsWith("QOCI")) { - QVERIFY_SQL(q, exec("create table " + qTableName("qtest_bigint") + " (id int, t_s64bit int, t_u64bit int)")); + QVERIFY_SQL(q, exec("create table " + qtest_bigint + " (id int, t_s64bit int, t_u64bit int)")); //} else if (drvName.startsWith("QIBASE")) { - // QVERIFY_SQL(q, exec("create table " + qTableName("qtest_bigint") + " (id int, t_s64bit int64, t_u64bit int64)")); + // QVERIFY_SQL(q, exec("create table " + qtest_bigint + " (id int, t_s64bit int64, t_u64bit int64)")); } else { QSKIP("no 64 bit integer support", SkipAll); } - QVERIFY(q.prepare("insert into " + qTableName("qtest_bigint") + " values (?, ?, ?)")); + QVERIFY(q.prepare("insert into " + qtest_bigint + " values (?, ?, ?)")); qlonglong ll = Q_INT64_C(9223372036854775807); qulonglong ull = Q_UINT64_C(18446744073709551615); @@ -1420,7 +1426,7 @@ void tst_QSqlDatabase::bigIntField() q.bindValue(2, (qlonglong) ull); QVERIFY_SQL(q, exec()); } - QVERIFY(q.exec("select * from " + qTableName("qtest_bigint") + " order by id")); + QVERIFY(q.exec("select * from " + qtest_bigint + " order by id")); QVERIFY(q.next()); QCOMPARE(q.value(1).toDouble(), (double)ll); QCOMPARE(q.value(1).toLongLong(), ll); @@ -1447,32 +1453,32 @@ void tst_QSqlDatabase::caseSensivity() || db.driverName().startsWith("QODBC")) cs = true; - QSqlRecord rec = db.record(qTableName("qtest")); + QSqlRecord rec = db.record(qTableName("qtest", __FILE__)); QVERIFY((int)rec.count() > 0); if (!cs) { - rec = db.record(qTableName("QTEST").toUpper()); + rec = db.record(qTableName("QTEST", __FILE__).toUpper()); QVERIFY((int)rec.count() > 0); - rec = db.record(qTableName("qTesT")); + rec = db.record(qTableName("qTesT", __FILE__)); QVERIFY((int)rec.count() > 0); } #ifdef QT3_SUPPORT - Q3SqlRecordInfo rInf = db.recordInfo(qTableName("qtest")); + Q3SqlRecordInfo rInf = db.recordInfo(qTableName("qtest", __FILE__)); QVERIFY((int)rInf.count() > 0); if (!cs) { - rInf = db.recordInfo(qTableName("QTEST").upper()); + rInf = db.recordInfo(qTableName("QTEST", __FILE__).upper()); QVERIFY((int)rInf.count() > 0); - rInf = db.recordInfo(qTableName("qTesT")); + rInf = db.recordInfo(qTableName("qTesT", __FILE__)); QVERIFY((int)rInf.count() > 0); } #endif - rec = db.primaryIndex(qTableName("qtest")); + rec = db.primaryIndex(qTableName("qtest", __FILE__)); QVERIFY((int)rec.count() > 0); if (!cs) { - rec = db.primaryIndex(qTableName("QTEST").toUpper()); + rec = db.primaryIndex(qTableName("QTEST", __FILE__).toUpper()); QVERIFY((int)rec.count() > 0); - rec = db.primaryIndex(qTableName("qTesT")); + rec = db.primaryIndex(qTableName("qTesT", __FILE__)); QVERIFY((int)rec.count() > 0); } } @@ -1488,7 +1494,7 @@ void tst_QSqlDatabase::noEscapedFieldNamesInRecord() fieldname = fieldname.toUpper(); QSqlQuery q(db); - QString query = "SELECT " + db.driver()->escapeIdentifier(fieldname, QSqlDriver::FieldName) + " FROM " + qTableName("qtest"); + QString query = "SELECT " + db.driver()->escapeIdentifier(fieldname, QSqlDriver::FieldName) + " FROM " + qTableName("qtest", __FILE__); QVERIFY_SQL(q, exec(query)); QCOMPARE(q.record().fieldName(0), fieldname); } @@ -1508,9 +1514,9 @@ void tst_QSqlDatabase::psql_schemas() QVERIFY_SQL( q, exec("set client_min_messages='warning'")); } - QVERIFY_SQL(q, exec("CREATE SCHEMA " + qTableName("qtestschema"))); + QVERIFY_SQL(q, exec("CREATE SCHEMA " + qTableName("qtestschema", __FILE__))); - QString table = qTableName("qtestschema") + '.' + qTableName("qtesttable"); + QString table = qTableName("qtestschema", __FILE__) + '.' + qTableName("qtesttable", __FILE__); QVERIFY_SQL(q, exec("CREATE TABLE " + table + " (id int primary key, name varchar(20))")); QVERIFY(db.tables().contains(table)); @@ -1546,10 +1552,10 @@ void tst_QSqlDatabase::psql_escapedIdentifiers() if(tst_Databases::isPostgreSQL(db)) QVERIFY_SQL( q, exec("set client_min_messages='warning'")); - QString schemaName = qTableName("qtestScHeMa"); - QString tableName = qTableName("qtest"); - QString field1Name = QString("fIeLdNaMe"); - QString field2Name = QString("ZuLu"); + const QString schemaName(qTableName("qtestScHeMa", __FILE__)), + tableName(qTableName("qtest", __FILE__)), + field1Name(QLatin1String("fIeLdNaMe")), + field2Name(QLatin1String("ZuLu")); q.exec(QString("DROP SCHEMA \"%1\" CASCADE").arg(schemaName)); QString createSchema = QString("CREATE SCHEMA \"%1\"").arg(schemaName); @@ -1576,7 +1582,6 @@ void tst_QSqlDatabase::psql_escapedIdentifiers() q.exec(QString("DROP SCHEMA \"%1\" CASCADE").arg(schemaName)); } - void tst_QSqlDatabase::psql_escapeBytea() { QFETCH(QString, dbName); @@ -1587,7 +1592,7 @@ void tst_QSqlDatabase::psql_escapeBytea() QByteArray ba(dta, 4); QSqlQuery q(db); - QString tableName = qTableName("batable"); + const QString tableName(qTableName("batable", __FILE__)); QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (ba bytea)").arg(tableName))); QSqlQuery iq(db); @@ -1620,7 +1625,7 @@ void tst_QSqlDatabase::bug_249059() QSKIP("Test requires PostgreSQL >= 7.3", SkipSingle); QSqlQuery q(db); - QString tableName = qTableName("bug_249059"); + const QString tableName(qTableName("bug_249059", __FILE__)); QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (dt timestamp, t time)").arg(tableName))); QSqlQuery iq(db); @@ -1655,7 +1660,7 @@ void tst_QSqlDatabase::precisionPolicy() // DBMS_SPECIFIC(db, "QPSQL"); QSqlQuery q(db); - QString tableName = qTableName("qtest_prec"); + const QString tableName(qTableName("qtest_prec", __FILE__)); if(!db.driver()->hasFeature(QSqlDriver::LowPrecisionNumbers)) QSKIP("Driver or database doesn't support setting precision policy", SkipSingle); @@ -1752,7 +1757,7 @@ void tst_QSqlDatabase::mysqlOdbc_unsignedIntegers() } QSqlQuery q(db); - QString tableName = qTableName("uint"); + const QString tableName(qTableName("uint", __FILE__)); QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (foo integer(10) unsigned, bar integer(10))").arg(tableName))); QVERIFY_SQL(q, exec(QString("INSERT INTO %1 VALUES (-4000000000, -4000000000)").arg(tableName))); QVERIFY_SQL(q, exec(QString("INSERT INTO %1 VALUES (4000000000, 4000000000)").arg(tableName))); @@ -1778,7 +1783,7 @@ void tst_QSqlDatabase::accessOdbc_strings() } QSqlQuery q(db); - QString tableName = qTableName("strings"); + const QString tableName(qTableName("strings", __FILE__)); QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (aStr memo, bStr memo, cStr memo, dStr memo" ", eStr memo, fStr memo, gStr memo, hStr memo)").arg(tableName))); @@ -1816,7 +1821,7 @@ void tst_QSqlDatabase::ibase_numericFields() CHECK_DATABASE(db); QSqlQuery q(db); - QString tableName = qTableName("numericfields"); + const QString tableName(qTableName("numericfields", __FILE__)); QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id int not null, num1 NUMERIC(2,1), " "num2 NUMERIC(5,2), num3 NUMERIC(10,3), " "num4 NUMERIC(18,4))").arg(tableName))); @@ -1888,7 +1893,7 @@ void tst_QSqlDatabase::ibase_fetchBlobs() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - QString tableName = qTableName("qtest_ibaseblobs"); + const QString tableName(qTableName("qtest_ibaseblobs", __FILE__)); QSqlQuery q(db); QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (blob1 BLOB segment size 256)").arg(tableName))); @@ -1921,7 +1926,7 @@ void tst_QSqlDatabase::ibase_procWithoutReturnValues() CHECK_DATABASE(db); QSqlQuery q(db); - QString procName = qTableName("qtest_proc1"); + const QString procName(qTableName("qtest_proc1", __FILE__)); q.exec(QString("drop procedure %1").arg(procName)); QVERIFY_SQL(q, exec("CREATE PROCEDURE " + procName + " (str VARCHAR(10))\nAS BEGIN\nstr='test';\nEND;")); QVERIFY_SQL(q, exec(QString("execute procedure %1('qtest')").arg(procName))); @@ -1939,7 +1944,7 @@ void tst_QSqlDatabase::ibase_procWithReturnValues() return; } - QString procName = qTableName("qtest_proc2"); + const QString procName(qTableName("qtest_proc2", __FILE__)); QSqlQuery q(db); q.exec(QString("drop procedure %1").arg(procName)); @@ -1981,11 +1986,11 @@ void tst_QSqlDatabase::formatValueTrimStrings() QSqlQuery q(db); - QVERIFY_SQL(q, exec(QString("INSERT INTO %1 (id, t_varchar, t_char) values (50, 'Trim Test ', 'Trim Test 2 ')").arg(qTableName("qtest")))); - QVERIFY_SQL(q, exec(QString("INSERT INTO %1 (id, t_varchar, t_char) values (51, 'TrimTest', 'Trim Test 2')").arg(qTableName("qtest")))); - QVERIFY_SQL(q, exec(QString("INSERT INTO %1 (id, t_varchar, t_char) values (52, ' ', ' ')").arg(qTableName("qtest")))); + QVERIFY_SQL(q, exec(QString("INSERT INTO %1 (id, t_varchar, t_char) values (50, 'Trim Test ', 'Trim Test 2 ')").arg(qTableName("qtest", __FILE__)))); + QVERIFY_SQL(q, exec(QString("INSERT INTO %1 (id, t_varchar, t_char) values (51, 'TrimTest', 'Trim Test 2')").arg(qTableName("qtest", __FILE__)))); + QVERIFY_SQL(q, exec(QString("INSERT INTO %1 (id, t_varchar, t_char) values (52, ' ', ' ')").arg(qTableName("qtest", __FILE__)))); - QVERIFY_SQL(q, exec(QString("SELECT t_varchar, t_char FROM %1 WHERE id >= 50 AND id <= 52 ORDER BY id").arg(qTableName("qtest")))); + QVERIFY_SQL(q, exec(QString("SELECT t_varchar, t_char FROM %1 WHERE id >= 50 AND id <= 52 ORDER BY id").arg(qTableName("qtest", __FILE__)))); QVERIFY_SQL(q, next()); @@ -2009,10 +2014,10 @@ void tst_QSqlDatabase::odbc_reopenDatabase() CHECK_DATABASE(db); QSqlQuery q(db); - QVERIFY_SQL(q, exec("SELECT * from " + qTableName("qtest"))); + QVERIFY_SQL(q, exec("SELECT * from " + qTableName("qtest", __FILE__))); QVERIFY_SQL(q, next()); db.open(); - QVERIFY_SQL(q, exec("SELECT * from " + qTableName("qtest"))); + QVERIFY_SQL(q, exec("SELECT * from " + qTableName("qtest", __FILE__))); QVERIFY_SQL(q, next()); db.open(); } @@ -2029,10 +2034,10 @@ void tst_QSqlDatabase::odbc_bindBoolean() } QSqlQuery q(db); - QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("qtestBindBool") + "(id int, boolvalue bit)")); + QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("qtestBindBool", __FILE__) + "(id int, boolvalue bit)")); // Bind and insert - QVERIFY_SQL(q, prepare("INSERT INTO " + qTableName("qtestBindBool") + " VALUES(?, ?)")); + QVERIFY_SQL(q, prepare("INSERT INTO " + qTableName("qtestBindBool", __FILE__) + " VALUES(?, ?)")); q.bindValue(0, 1); q.bindValue(1, true); QVERIFY_SQL(q, exec()); @@ -2041,7 +2046,7 @@ void tst_QSqlDatabase::odbc_bindBoolean() QVERIFY_SQL(q, exec()); // Retrive - QVERIFY_SQL(q, exec("SELECT id, boolvalue FROM " + qTableName("qtestBindBool") + " ORDER BY id")); + QVERIFY_SQL(q, exec("SELECT id, boolvalue FROM " + qTableName("qtestBindBool", __FILE__) + " ORDER BY id")); QVERIFY_SQL(q, next()); QCOMPARE(q.value(0).toInt(), 1); QCOMPARE(q.value(1).toBool(), true); @@ -2055,20 +2060,21 @@ void tst_QSqlDatabase::odbc_testqGetString() QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); + const QString testqGetString(qTableName("testqGetString", __FILE__)); QSqlQuery q(db); if (tst_Databases::isSqlServer(db)) - QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("testqGetString") + "(id int, vcvalue varchar(MAX))")); + QVERIFY_SQL(q, exec("CREATE TABLE " + testqGetString + "(id int, vcvalue varchar(MAX))")); else if(tst_Databases::isMSAccess(db)) - QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("testqGetString") + "(id int, vcvalue memo)")); + QVERIFY_SQL(q, exec("CREATE TABLE " + testqGetString + "(id int, vcvalue memo)")); else - QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("testqGetString") + "(id int, vcvalue varchar(65538))")); + QVERIFY_SQL(q, exec("CREATE TABLE " + testqGetString + "(id int, vcvalue varchar(65538))")); QString largeString; largeString.fill('A', 65536); // Bind and insert - QVERIFY_SQL(q, prepare("INSERT INTO " + qTableName("testqGetString") + " VALUES(?, ?)")); + QVERIFY_SQL(q, prepare("INSERT INTO " + testqGetString + " VALUES(?, ?)")); q.bindValue(0, 1); q.bindValue(1, largeString); QVERIFY_SQL(q, exec()); @@ -2080,7 +2086,7 @@ void tst_QSqlDatabase::odbc_testqGetString() QVERIFY_SQL(q, exec()); // Retrive - QVERIFY_SQL(q, exec("SELECT id, vcvalue FROM " + qTableName("testqGetString") + " ORDER BY id")); + QVERIFY_SQL(q, exec("SELECT id, vcvalue FROM " + testqGetString + " ORDER BY id")); QVERIFY_SQL(q, next()); QCOMPARE(q.value(0).toInt(), 1); QCOMPARE(q.value(1).toString().length(), 65536); @@ -2098,6 +2104,7 @@ void tst_QSqlDatabase::mysql_multiselect() QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); + const QString qtest(qTableName("qtest", __FILE__)); QSqlQuery q(db); QString version=tst_Databases::getMySqlVersion( db ); @@ -2105,11 +2112,11 @@ void tst_QSqlDatabase::mysql_multiselect() if (ver < 4.1) QSKIP("Test requires MySQL >= 4.1", SkipSingle); - QVERIFY_SQL(q, exec("SELECT * FROM " + qTableName("qtest") + "; SELECT * FROM " + qTableName("qtest"))); + QVERIFY_SQL(q, exec("SELECT * FROM " + qtest + "; SELECT * FROM " + qtest)); QVERIFY_SQL(q, next()); - QVERIFY_SQL(q, exec("SELECT * FROM " + qTableName("qtest") + "; SELECT * FROM " + qTableName("qtest"))); + QVERIFY_SQL(q, exec("SELECT * FROM " + qtest + "; SELECT * FROM " + qtest)); QVERIFY_SQL(q, next()); - QVERIFY_SQL(q, exec("SELECT * FROM " + qTableName("qtest"))); + QVERIFY_SQL(q, exec("SELECT * FROM " + qtest)); } void tst_QSqlDatabase::ibase_useCustomCharset() @@ -2123,7 +2130,7 @@ void tst_QSqlDatabase::ibase_useCustomCharset() db.setConnectOptions("ISC_DPB_LC_CTYPE=Latin1"); db.open(); - QString tableName = qTableName("latin1table"); + const QString tableName(qTableName("latin1table", __FILE__)); QSqlQuery q(db); QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(text VARCHAR(6) CHARACTER SET Latin1)").arg(tableName))); @@ -2161,7 +2168,7 @@ void tst_QSqlDatabase::oci_xmltypeSupport() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - QString tableName = qTableName("qtest_xmltype"); + const QString tableName(qTableName("qtest_xmltype", __FILE__)); QString xml("MY_TABLE"); QSqlQuery q(db); @@ -2189,7 +2196,7 @@ void tst_QSqlDatabase::oci_fieldLength() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - QString tableName = qTableName("qtest"); + const QString tableName(qTableName("qtest", __FILE__)); QSqlQuery q(db); QVERIFY_SQL(q, exec(QString("SELECT t_varchar, t_char FROM %1").arg(tableName))); @@ -2205,7 +2212,7 @@ void tst_QSqlDatabase::oci_synonymstest() CHECK_DATABASE(db); QSqlQuery q(db); - QString creator(qTableName("CREATOR")), appuser(qTableName("APPUSER")), table1(qTableName("TABLE1")); + const QString creator(qTableName("CREATOR", __FILE__)), appuser(qTableName("APPUSER", __FILE__)), table1(qTableName("TABLE1", __FILE__)); // QVERIFY_SQL(q, exec("drop public synonym "+table1)); QVERIFY_SQL(q, exec(QString("create user %1 identified by %2 default tablespace users temporary tablespace temp").arg(creator).arg(creator))); QVERIFY_SQL(q, exec(QString("grant CONNECT to %1").arg(creator))); @@ -2223,8 +2230,8 @@ void tst_QSqlDatabase::oci_synonymstest() db3.close(); QVERIFY_SQL(db3, open(appuser,appuser)); QSqlQuery q3(db3); - QVERIFY_SQL(q3, exec("create synonym "+appuser+'.'+qTableName("synonyms")+" for "+creator+'.'+table1)); - QVERIFY_SQL(db3, tables().filter(qTableName("synonyms"), Qt::CaseInsensitive).count() >= 1); + QVERIFY_SQL(q3, exec("create synonym "+appuser+'.'+qTableName("synonyms", __FILE__)+" for "+creator+'.'+table1)); + QVERIFY_SQL(db3, tables().filter(qTableName("synonyms", __FILE__), Qt::CaseInsensitive).count() >= 1); } @@ -2240,7 +2247,7 @@ void tst_QSqlDatabase::odbc_uniqueidentifier() return; } - QString tableName = qTableName("qtest_sqlguid"); + const QString tableName(qTableName("qtest_sqlguid", __FILE__)); QString guid = QString("AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE"); QString invalidGuid = QString("GAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE"); @@ -2283,7 +2290,7 @@ void tst_QSqlDatabase::odbc_uintfield() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - QString tableName = qTableName("uint_table"); + const QString tableName(qTableName("uint_table", __FILE__)); unsigned int val = 4294967295U; QSqlQuery q(db); @@ -2347,7 +2354,7 @@ void tst_QSqlDatabase::eventNotificationIBase() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - QString procedureName = qTableName("posteventProc"); + const QString procedureName(qTableName("posteventProc", __FILE__)); QSqlDriver *driver=db.driver(); QVERIFY_SQL(*driver, subscribeToNotification(procedureName)); QTest::qWait(300); // Interbase needs some time to call the driver callback. @@ -2381,7 +2388,7 @@ void tst_QSqlDatabase::eventNotificationPSQL() #endif QSqlQuery query(db); - QString procedureName = qTableName("posteventProc"); + QString procedureName = qTableName("posteventProc", __FILE__); QSqlDriver &driver=*(db.driver()); QVERIFY_SQL(driver, subscribeToNotification(procedureName)); @@ -2405,7 +2412,7 @@ void tst_QSqlDatabase::sqlite_bindAndFetchUInt() } QSqlQuery q(db); - QString tableName = qTableName("uint_test"); + const QString tableName(qTableName("uint_test", __FILE__)); QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(uint_field UNSIGNED INTEGER)").arg(tableName))); QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES(?)").arg(tableName))); q.addBindValue(4000000000U); @@ -2425,7 +2432,7 @@ void tst_QSqlDatabase::db2_valueCacheUpdate() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - QString tableName = qTableName("qtest"); + const QString tableName(qTableName("qtest", __FILE__)); QSqlQuery q(db); q.exec(QString("SELECT id, t_varchar, t_char, t_numeric FROM %1").arg(tableName)); q.next(); @@ -2448,7 +2455,7 @@ void tst_QSqlDatabase::sqlStatementUseIsNull_189093() // select a record with NULL value QSqlQuery q(QString::null, db); - QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 4")); + QVERIFY_SQL(q, exec("select * from " + qTableName("qtest", __FILE__) + " where id = 4")); QVERIFY_SQL(q, next()); QSqlDriver *driver = db.driver(); @@ -2471,7 +2478,7 @@ void tst_QSqlDatabase::mysql_savepointtest() QSqlQuery q(db); QVERIFY_SQL(q, exec("begin")); - QVERIFY_SQL(q, exec("insert into "+qTableName("qtest")+" VALUES (54, 'foo', 'foo', 54.54)")); + QVERIFY_SQL(q, exec("insert into "+qTableName("qtest", __FILE__)+" VALUES (54, 'foo', 'foo', 54.54)")); QVERIFY_SQL(q, exec("savepoint foo")); } @@ -2481,7 +2488,7 @@ void tst_QSqlDatabase::oci_tables() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); QSqlQuery q(db); - QString systemTableName("system."+qTableName("mypassword")); + const QString systemTableName("system."+qTableName("mypassword", __FILE__)); QVERIFY_SQL(q, exec("CREATE TABLE "+systemTableName+"(name VARCHAR(20))")); QVERIFY(!db.tables().contains(systemTableName.toUpper())); QVERIFY(db.tables(QSql::SystemTables).contains(systemTableName.toUpper())); @@ -2501,8 +2508,8 @@ void tst_QSqlDatabase::sqlite_enable_cache_mode() db2.setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE"); QVERIFY_SQL(db2, open()); QSqlQuery q(db), q2(db2); - QVERIFY_SQL(q, exec("select * from "+qTableName("qtest"))); - QVERIFY_SQL(q2, exec("select * from "+qTableName("qtest"))); + QVERIFY_SQL(q, exec("select * from "+qTableName("qtest", __FILE__))); + QVERIFY_SQL(q2, exec("select * from "+qTableName("qtest", __FILE__))); } QTEST_MAIN(tst_QSqlDatabase) diff --git a/tests/auto/qsqldriver/tst_qsqldriver.cpp b/tests/auto/qsqldriver/tst_qsqldriver.cpp index 19e4001..f2393ba 100644 --- a/tests/auto/qsqldriver/tst_qsqldriver.cpp +++ b/tests/auto/qsqldriver/tst_qsqldriver.cpp @@ -84,18 +84,19 @@ void tst_QSqlDriver::initTestCase_data() void tst_QSqlDriver::recreateTestTables(QSqlDatabase db) { QSqlQuery q(db); + const QString relTEST1(qTableName("relTEST1", __FILE__)); if(tst_Databases::isPostgreSQL(db)) QVERIFY_SQL( q, exec("set client_min_messages='warning'")); - tst_Databases::safeDropTable( db, qTableName( "relTEST1" ) ); + tst_Databases::safeDropTable( db, relTEST1 ); - QVERIFY_SQL( q, exec("create table " + qTableName("relTEST1") + + QVERIFY_SQL( q, exec("create table " + relTEST1 + " (id int not null primary key, name varchar(20), title_key int, another_title_key int)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(1, 'harry', 1, 2)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(2, 'trond', 2, 1)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(3, 'vohi', 1, 2)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(4, 'boris', 2, 2)")); + QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(1, 'harry', 1, 2)")); + QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(2, 'trond', 2, 1)")); + QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(3, 'vohi', 1, 2)")); + QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(4, 'boris', 2, 2)")); } void tst_QSqlDriver::initTestCase() @@ -108,7 +109,7 @@ void tst_QSqlDriver::cleanupTestCase() { foreach (const QString &dbName, dbs.dbNames) { QSqlDatabase db = QSqlDatabase::database(dbName); - tst_Databases::safeDropTable( db, qTableName( "relTEST1" ) ); + tst_Databases::safeDropTable( db, qTableName( "relTEST1", __FILE__ ) ); } dbs.close(); } @@ -127,7 +128,7 @@ void tst_QSqlDriver::record() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - QString tablename = qTableName("relTEST1"); + QString tablename(qTableName("relTEST1", __FILE__)); QStringList fields; fields << "id" << "name" << "title_key" << "another_title_key"; @@ -180,7 +181,7 @@ void tst_QSqlDriver::primaryIndex() QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - QString tablename = qTableName("relTEST1"); + QString tablename(qTableName("relTEST1", __FILE__)); //check that we can get primary index using unquoted mixed case table name QSqlIndex index = db.driver()->primaryIndex(tablename); QCOMPARE(index.count(), 1); diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 5339132..b9ab73f 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -44,6 +44,8 @@ #include "../qsqldatabase/tst_databases.h" +const QString qtest(qTableName( "qtest", __FILE__ )); + //TESTED_FILES= class tst_QSqlQuery : public QObject @@ -295,56 +297,56 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) { QStringList tablenames; // drop all the table in case a testcase failed - tablenames << qTableName( "qtest" ) - << qTableName( "qtest_null" ) - << qTableName( "qtest_blob" ) - << qTableName( "qtest_bittest" ) - << qTableName( "qtest_nullblob" ) - << qTableName( "qtest_rawtest" ) - << qTableName( "qtest_precision" ) - << qTableName( "qtest_prepare" ) - << qTableName( "qtestj1" ) - << qTableName( "qtestj2" ) - << qTableName( "char1Select" ) - << qTableName( "char1SelectUnicode" ) - << qTableName( "qxmltest" ) - << qTableName( "qtest_exerr" ) - << qTableName( "qtest_empty" ) - << qTableName( "clobby" ) - << qTableName( "bindtest" ) - << qTableName( "more_results" ) - << qTableName( "blobstest" ) - << qTableName( "oraRowId" ) - << qTableName( "qtest_batch" ) - << qTableName("bug6421").toUpper() - << qTableName("bug5765") - << qTableName("bug6852") - << qTableName( "qtest_lockedtable" ) - << qTableName( "Planet" ) - << qTableName( "task_250026" ) - << qTableName( "task_234422" ) - << qTableName("test141895"); + tablenames << qtest + << qTableName( "qtest_null", __FILE__ ) + << qTableName( "qtest_blob", __FILE__ ) + << qTableName( "qtest_bittest", __FILE__ ) + << qTableName( "qtest_nullblob", __FILE__ ) + << qTableName( "qtest_rawtest", __FILE__ ) + << qTableName( "qtest_precision", __FILE__ ) + << qTableName( "qtest_prepare", __FILE__ ) + << qTableName( "qtestj1", __FILE__ ) + << qTableName( "qtestj2", __FILE__ ) + << qTableName( "char1Select", __FILE__ ) + << qTableName( "char1SU", __FILE__ ) + << qTableName( "qxmltest", __FILE__ ) + << qTableName( "qtest_exerr", __FILE__ ) + << qTableName( "qtest_empty", __FILE__ ) + << qTableName( "clobby", __FILE__ ) + << qTableName( "bindtest", __FILE__ ) + << qTableName( "more_results", __FILE__ ) + << qTableName( "blobstest", __FILE__ ) + << qTableName( "oraRowId", __FILE__ ) + << qTableName( "qtest_batch", __FILE__ ) + << qTableName("bug6421", __FILE__).toUpper() + << qTableName("bug5765", __FILE__) + << qTableName("bug6852", __FILE__) + << qTableName( "qtest_lockedtable", __FILE__ ) + << qTableName( "Planet", __FILE__ ) + << qTableName( "task_250026", __FILE__ ) + << qTableName( "task_234422", __FILE__ ) + << qTableName("test141895", __FILE__); if ( db.driverName().startsWith("QPSQL") ) - tablenames << qTableName("task_233829"); + tablenames << qTableName("task_233829", __FILE__); if ( db.driverName().startsWith("QSQLITE") ) - tablenames << qTableName( "record_sqlite" ); + tablenames << qTableName( "record_sqlite", __FILE__ ); if ( tst_Databases::isSqlServer( db ) || db.driverName().startsWith( "QOCI" ) ) - tablenames << qTableName( "qtest_longstr" ); + tablenames << qTableName( "qtest_longstr", __FILE__ ); if (tst_Databases::isSqlServer( db )) - db.exec("DROP PROCEDURE " + qTableName("test141895_proc")); + db.exec("DROP PROCEDURE " + qTableName("test141895_proc", __FILE__)); if (tst_Databases::isMySQL( db )) - db.exec("DROP PROCEDURE IF EXISTS "+qTableName("bug6852_proc")); + db.exec("DROP PROCEDURE IF EXISTS "+qTableName("bug6852_proc", __FILE__)); tst_Databases::safeDropTables( db, tablenames ); if ( db.driverName().startsWith( "QOCI" ) ) { QSqlQuery q( db ); - q.exec( "DROP PACKAGE " + qTableName("pkg") ); + q.exec( "DROP PACKAGE " + qTableName("pkg", __FILE__) ); } } @@ -360,31 +362,32 @@ void tst_QSqlQuery::createTestTables( QSqlDatabase db ) QVERIFY_SQL( q, exec("set client_min_messages='warning'")); if(tst_Databases::isPostgreSQL(db)) - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest" ) + " (id serial NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id)) WITH OIDS" ) ); + QVERIFY_SQL( q, exec( "create table " + qtest + " (id serial NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id)) WITH OIDS" ) ); else - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest" ) + " (id int "+tst_Databases::autoFieldName(db) +" NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id))" ) ); + QVERIFY_SQL( q, exec( "create table " + qtest + " (id int "+tst_Databases::autoFieldName(db) +" NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id))" ) ); if ( tst_Databases::isSqlServer( db ) || db.driverName().startsWith( "QTDS" ) ) - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_null" ) + " (id int null, t_varchar varchar(20) null)" ) ); + QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_null", __FILE__ ) + " (id int null, t_varchar varchar(20) null)" ) ); else - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_null" ) + " (id int, t_varchar varchar(20))" ) ); + QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_null", __FILE__ ) + " (id int, t_varchar varchar(20))" ) ); } void tst_QSqlQuery::populateTestTables( QSqlDatabase db ) { QSqlQuery q( db ); - q.exec( "delete from " + qTableName( "qtest" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (1, 'VarChar1', 'Char1')" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (2, 'VarChar2', 'Char2')" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (3, 'VarChar3', 'Char3')" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (4, 'VarChar4', 'Char4')" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (5, 'VarChar5', 'Char5')" ) ); + const QString qtest_null(qTableName( "qtest_null", __FILE__ )); + q.exec( "delete from " + qtest ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (1, 'VarChar1', 'Char1')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (2, 'VarChar2', 'Char2')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (3, 'VarChar3', 'Char3')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (4, 'VarChar4', 'Char4')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (5, 'VarChar5', 'Char5')" ) ); - q.exec( "delete from " + qTableName( "qtest_null" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_null" ) + " values (0, NULL)" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_null" ) + " values (1, 'n')" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_null" ) + " values (2, 'i')" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_null" ) + " values (3, NULL)" ) ); + q.exec( "delete from " + qtest_null ); + QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (0, NULL)" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (1, 'n')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (2, 'i')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (3, NULL)" ) ); } // There were problems with char fields of size 1 @@ -396,9 +399,9 @@ void tst_QSqlQuery::char1Select() { QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "char1Select" ) + " (id char(1))" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "char1Select" ) + " values ('a')" ) ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "char1Select" ) ) ); + 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__ ) ) ); QVERIFY( q.next() ); if ( db.driverName().startsWith( "QIBASE" ) ) @@ -427,31 +430,32 @@ void tst_QSqlQuery::char1SelectUnicode() QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); QString createQuery; + const QString char1SelectUnicode(qTableName( "char1SU", __FILE__ )); if ( tst_Databases::isSqlServer( db ) ) - createQuery = "create table " + qTableName( "char1SelectUnicode" ) + "(id nchar(1))"; + createQuery = "create table " + char1SelectUnicode + "(id nchar(1))"; else if ( db.driverName().startsWith( "QDB2" ) || db.driverName().startsWith( "QOCI" ) || db.driverName().startsWith( "QPSQL" ) ) - createQuery = "create table " + qTableName( "char1SelectUnicode" ) + " (id char(3))"; + createQuery = "create table " + char1SelectUnicode + " (id char(3))"; else if ( db.driverName().startsWith( "QIBASE" ) ) - createQuery = "create table " + qTableName( "char1SelectUnicode" ) + + createQuery = "create table " + char1SelectUnicode + " (id char(1) character set unicode_fss)"; else if ( db.driverName().startsWith( "QMYSQL" ) ) - createQuery = "create table " + qTableName( "char1SelectUnicode" ) + " (id char(1)) " + createQuery = "create table " + char1SelectUnicode + " (id char(1)) " "default character set 'utf8'"; else - createQuery = "create table " + qTableName( "char1SelectUnicode" ) + " (id char(1))"; + createQuery = "create table " + char1SelectUnicode + " (id char(1))"; QVERIFY_SQL( q, exec( createQuery ) ); - QVERIFY_SQL( q, prepare( "insert into " + qTableName( "char1SelectUnicode" ) + " values(?)" ) ); + QVERIFY_SQL( q, prepare( "insert into " + char1SelectUnicode + " values(?)" ) ); q.bindValue( 0, uniStr ); QVERIFY_SQL( q, exec() ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "char1SelectUnicode" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + char1SelectUnicode ) ); QVERIFY( q.next() ); @@ -471,24 +475,25 @@ void tst_QSqlQuery::oraRowId() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString oraRowId(qTableName("oraRowId", __FILE__)); QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "select rowid from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select rowid from " + qtest ) ); QVERIFY( q.next() ); QCOMPARE( q.value( 0 ).type(), QVariant::String ); QVERIFY( !q.value( 0 ).toString().isEmpty() ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "oraRowId" ) + " (id char(1))" ) ); + QVERIFY_SQL( q, exec( "create table " + oraRowId + " (id char(1))" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "oraRowId" ) + " values('a')" ) ); + QVERIFY_SQL( q, exec( "insert into " + oraRowId + " values('a')" ) ); QVariant v1 = q.lastInsertId(); QVERIFY( v1.isValid() ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "oraRowId" ) + " values('b')" ) ); + QVERIFY_SQL( q, exec( "insert into " + oraRowId + " values('b')" ) ); QVariant v2 = q.lastInsertId(); QVERIFY( v2.isValid() ); - QVERIFY_SQL( q, prepare( "select * from " + qTableName( "oraRowId" ) + " where rowid = ?" ) ); + QVERIFY_SQL( q, prepare( "select * from " + oraRowId + " where rowid = ?" ) ); q.addBindValue( v1 ); QVERIFY_SQL( q, exec() ); QVERIFY( q.next() ); @@ -505,49 +510,50 @@ void tst_QSqlQuery::mysqlOutValues() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString hello(qTableName( "hello", __FILE__ )), qtestproc(qTableName( "qtestproc", __FILE__ )); QSqlQuery q( db ); if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); - q.exec( "drop function " + qTableName( "hello" ) ); + q.exec( "drop function " + hello ); - QVERIFY_SQL( q, exec( "create function " + qTableName( "hello" ) + " (s char(20)) returns varchar(50) return concat('Hello ', s)" ) ); + QVERIFY_SQL( q, exec( "create function " + hello + " (s char(20)) returns varchar(50) return concat('Hello ', s)" ) ); - QVERIFY_SQL( q, exec( "select " + qTableName( "hello" ) + "('world')" ) ); + QVERIFY_SQL( q, exec( "select " + hello + "('world')" ) ); QVERIFY_SQL( q, next() ); QCOMPARE( q.value( 0 ).toString(), QString( "Hello world" ) ); - QVERIFY_SQL( q, prepare( "select " + qTableName( "hello" ) + "('harald')" ) ); + QVERIFY_SQL( q, prepare( "select " + hello + "('harald')" ) ); QVERIFY_SQL( q, exec() ); QVERIFY_SQL( q, next() ); QCOMPARE( q.value( 0 ).toString(), QString( "Hello harald" ) ); - QVERIFY_SQL( q, exec( "drop function " + qTableName( "hello" ) ) ); + QVERIFY_SQL( q, exec( "drop function " + hello ) ); - q.exec( "drop procedure " + qTableName( "qtestproc" ) ); + q.exec( "drop procedure " + qtestproc ); - QVERIFY_SQL( q, exec( "create procedure " + qTableName( "qtestproc" ) + " () " - "BEGIN select * from " + qTableName( "qtest" ) + " order by id; END" ) ); - QVERIFY_SQL( q, exec( "call " + qTableName( "qtestproc" ) + "()" ) ); + QVERIFY_SQL( q, exec( "create procedure " + qtestproc + " () " + "BEGIN select * from " + qtest + " order by id; END" ) ); + QVERIFY_SQL( q, exec( "call " + qtestproc + "()" ) ); QVERIFY_SQL( q, next() ); QCOMPARE( q.value( 1 ).toString(), QString( "VarChar1" ) ); - QVERIFY_SQL( q, exec( "drop procedure " + qTableName( "qtestproc" ) ) ); + QVERIFY_SQL( q, exec( "drop procedure " + qtestproc ) ); - QVERIFY_SQL( q, exec( "create procedure " + qTableName( "qtestproc" ) + " (OUT param1 INT) " + QVERIFY_SQL( q, exec( "create procedure " + qtestproc + " (OUT param1 INT) " "BEGIN set param1 = 42; END" ) ); - QVERIFY_SQL( q, exec( "call " + qTableName( "qtestproc" ) + " (@out)" ) ); + QVERIFY_SQL( q, exec( "call " + qtestproc + " (@out)" ) ); QVERIFY_SQL( q, exec( "select @out" ) ); QCOMPARE( q.record().fieldName( 0 ), QString( "@out" ) ); QVERIFY_SQL( q, next() ); QCOMPARE( q.value( 0 ).toInt(), 42 ); - QVERIFY_SQL( q, exec( "drop procedure " + qTableName( "qtestproc" ) ) ); + QVERIFY_SQL( q, exec( "drop procedure " + qtestproc ) ); } void tst_QSqlQuery::oraOutValues() @@ -555,6 +561,7 @@ void tst_QSqlQuery::oraOutValues() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString tst_outValues(qTableName("tst_outValues", __FILE__)); if ( !db.driver()->hasFeature( QSqlDriver::PreparedQueries ) ) { QSKIP( "Test requires prepared query support", SkipSingle ); @@ -566,11 +573,11 @@ void tst_QSqlQuery::oraOutValues() q.setForwardOnly( true ); /*** outvalue int ***/ - QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x out int) is\n" + QVERIFY_SQL( q, exec( "create or replace procedure " + tst_outValues + "(x out int) is\n" "begin\n" " x := 42;\n" "end;\n" ) ); - QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); + QVERIFY( q.prepare( "call " + tst_outValues + "(?)" ) ); q.addBindValue( 0, QSql::Out ); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValue( 0 ).toInt(), 42 ); @@ -582,11 +589,11 @@ void tst_QSqlQuery::oraOutValues() QVERIFY( !q.boundValue( 0 ).isNull() ); /*** outvalue varchar ***/ - QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x out varchar) is\n" + QVERIFY_SQL( q, exec( "create or replace procedure " + tst_outValues + "(x out varchar) is\n" "begin\n" " x := 'blah';\n" "end;\n" ) ); - QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); + QVERIFY( q.prepare( "call " + tst_outValues + "(?)" ) ); QString s1( "12345" ); s1.reserve( 512 ); q.addBindValue( s1, QSql::Out ); @@ -594,51 +601,51 @@ void tst_QSqlQuery::oraOutValues() QCOMPARE( q.boundValue( 0 ).toString(), QString( "blah" ) ); /*** in/outvalue numeric ***/ - QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x in out numeric) is\n" + QVERIFY_SQL( q, exec( "create or replace procedure " + tst_outValues + "(x in out numeric) is\n" "begin\n" " x := x + 10;\n" "end;\n" ) ); - QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); + QVERIFY( q.prepare( "call " + tst_outValues + "(?)" ) ); q.addBindValue( 10, QSql::Out ); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValue( 0 ).toInt(), 20 ); /*** in/outvalue varchar ***/ - QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x in out varchar) is\n" + QVERIFY_SQL( q, exec( "create or replace procedure " + tst_outValues + "(x in out varchar) is\n" "begin\n" " x := 'homer';\n" "end;\n" ) ); - QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); + QVERIFY( q.prepare( "call " + tst_outValues + "(?)" ) ); q.addBindValue( QString( "maggy" ), QSql::Out ); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValue( 0 ).toString(), QString( "homer" ) ); /*** in/outvalue varchar ***/ - QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x in out varchar) is\n" + QVERIFY_SQL( q, exec( "create or replace procedure " + tst_outValues + "(x in out varchar) is\n" "begin\n" " x := NULL;\n" "end;\n" ) ); - QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); + QVERIFY( q.prepare( "call " + tst_outValues + "(?)" ) ); q.addBindValue( QString( "maggy" ), QSql::Out ); QVERIFY_SQL( q, exec() ); QVERIFY( q.boundValue( 0 ).isNull() ); /*** in/outvalue int ***/ - QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x in out int) is\n" + QVERIFY_SQL( q, exec( "create or replace procedure " + tst_outValues + "(x in out int) is\n" "begin\n" " x := NULL;\n" "end;\n" ) ); - QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); + QVERIFY( q.prepare( "call " + tst_outValues + "(?)" ) ); q.addBindValue( 42, QSql::Out ); QVERIFY_SQL( q, exec() ); QVERIFY( q.boundValue( 0 ).isNull() ); /*** in/outvalue varchar ***/ - QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x in varchar, y out varchar) is\n" + QVERIFY_SQL( q, exec( "create or replace procedure " + tst_outValues + "(x in varchar, y out varchar) is\n" "begin\n" " y := x||'bubulalakikikokololo';\n" "end;\n" ) ); - QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?, ?)" ) ); + QVERIFY( q.prepare( "call " + tst_outValues + "(?, ?)" ) ); q.addBindValue( QString( "fifi" ), QSql::In ); QString out; out.reserve( 50 ); @@ -652,30 +659,31 @@ void tst_QSqlQuery::oraClob() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString clobby(qTableName("clobby", __FILE__)); QSqlQuery q( db ); // simple short string - QVERIFY_SQL( q, exec( "create table " + qTableName( "clobby" ) + "(id int primary key, cl clob, bl blob)" ) ); - QVERIFY_SQL( q, prepare( "insert into " + qTableName( "clobby" ) + " (id, cl, bl) values(?, ?, ?)" ) ); + QVERIFY_SQL( q, exec( "create table " + clobby + "(id int primary key, cl clob, bl blob)" ) ); + QVERIFY_SQL( q, prepare( "insert into " + clobby + " (id, cl, bl) values(?, ?, ?)" ) ); q.addBindValue( 1 ); q.addBindValue( "bubu" ); q.addBindValue( QByteArray("bubu") ); QVERIFY_SQL( q, exec() ); - QVERIFY_SQL( q, exec( "select bl, cl from " + qTableName( "clobby" ) + " where id = 1" ) ); + QVERIFY_SQL( q, exec( "select bl, cl from " + clobby + " where id = 1" ) ); QVERIFY( q.next() ); QCOMPARE( q.value( 0 ).toString(), QString( "bubu" ) ); QCOMPARE( q.value( 1 ).toString(), QString( "bubu" ) ); // simple short string with binding - QVERIFY_SQL( q, prepare( "insert into " + qTableName( "clobby" ) + " (id, cl, bl) values(?, ?, ?)" ) ); + QVERIFY_SQL( q, prepare( "insert into " + clobby + " (id, cl, bl) values(?, ?, ?)" ) ); q.addBindValue( 2 ); q.addBindValue( "lala", QSql::Binary ); q.addBindValue( QByteArray("lala"), QSql::Binary ); QVERIFY_SQL( q, exec() ); - QVERIFY_SQL( q, exec( "select bl, cl from " + qTableName( "clobby" ) + " where id = 2" ) ); + QVERIFY_SQL( q, exec( "select bl, cl from " + clobby + " where id = 2" ) ); QVERIFY( q.next() ); QCOMPARE( q.value( 0 ).toString(), QString( "lala" ) ); QCOMPARE( q.value( 1 ).toString(), QString( "lala" ) ); @@ -683,13 +691,13 @@ void tst_QSqlQuery::oraClob() // loooong string QString loong; loong.fill( QLatin1Char( 'A' ), 25000 ); - QVERIFY_SQL( q, prepare( "insert into " + qTableName( "clobby" ) + " (id, cl, bl) values(?, ?, ?)" ) ); + QVERIFY_SQL( q, prepare( "insert into " + clobby + " (id, cl, bl) values(?, ?, ?)" ) ); q.addBindValue( 3 ); q.addBindValue( loong, QSql::Binary ); q.addBindValue( loong.toLatin1(), QSql::Binary ); QVERIFY_SQL( q, exec() ); - QVERIFY_SQL( q, exec( "select bl, cl from " + qTableName( "clobby" ) + " where id = 3" ) ); + QVERIFY_SQL( q, exec( "select bl, cl from " + clobby + " where id = 3" ) ); QVERIFY( q.next() ); QCOMPARE( q.value( 0 ).toString().count(), loong.count() ); QVERIFY( q.value( 0 ).toString() == loong ); @@ -704,16 +712,16 @@ void tst_QSqlQuery::storedProceduresIBase() CHECK_DATABASE( db ); QSqlQuery q( db ); - q.exec( "drop procedure " + qTableName( "TESTPROC" ) ); + q.exec( "drop procedure " + qTableName( "TESTPROC", __FILE__ ) ); - QVERIFY_SQL( q, exec( "create procedure " + qTableName( "TESTPROC" ) + + QVERIFY_SQL( q, exec( "create procedure " + qTableName( "TESTPROC", __FILE__ ) + " RETURNS (x integer, y varchar(20)) " "AS BEGIN " " x = 42; " " y = 'Hello Anders'; " "END" ) ); - QVERIFY_SQL( q, prepare( "execute procedure " + qTableName( "TestProc" ) ) ); + QVERIFY_SQL( q, prepare( "execute procedure " + qTableName( "TestProc", __FILE__ ) ) ); QVERIFY_SQL( q, exec() ); // check for a valid result set @@ -730,7 +738,7 @@ void tst_QSqlQuery::storedProceduresIBase() // the second next shall fail QVERIFY( !q.next() ); - q.exec( "drop procedure " + qTableName( "TestProc" ) ); + q.exec( "drop procedure " + qTableName( "TestProc", __FILE__ ) ); } void tst_QSqlQuery::outValuesDB2() @@ -748,8 +756,8 @@ void tst_QSqlQuery::outValuesDB2() q.setForwardOnly( true ); - q.exec( "drop procedure " + qTableName( "tst_outValues" ) ); //non-fatal - QVERIFY_SQL( q, exec( "CREATE PROCEDURE " + qTableName( "tst_outValues" ) + + q.exec( "drop procedure " + qTableName( "tst_outValues", __FILE__ ) ); //non-fatal + QVERIFY_SQL( q, exec( "CREATE PROCEDURE " + qTableName( "tst_outValues", __FILE__ ) + " (OUT x int, OUT x2 double, OUT x3 char(20))\n" "LANGUAGE SQL\n" "P1: BEGIN\n" @@ -758,7 +766,7 @@ void tst_QSqlQuery::outValuesDB2() " SET x3 = 'Homer';\n" "END P1" ) ); - QVERIFY_SQL( q, prepare( "call " + qTableName( "tst_outValues" ) + "(?, ?, ?)" ) ); + QVERIFY_SQL( q, prepare( "call " + qTableName( "tst_outValues", __FILE__ ) + "(?, ?, ?)" ) ); q.addBindValue( 0, QSql::Out ); q.addBindValue( 0.0, QSql::Out ); @@ -776,6 +784,7 @@ void tst_QSqlQuery::outValues() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString tst_outValues(qTableName("tst_outValues", __FILE__)); if ( !db.driver()->hasFeature( QSqlDriver::PreparedQueries ) ) { QSKIP( "Test requires prepared query support", SkipSingle ); @@ -787,26 +796,26 @@ void tst_QSqlQuery::outValues() q.setForwardOnly( true ); if ( db.driverName().startsWith( "QOCI" ) ) { - QVERIFY_SQL( q, exec( "create or replace procedure " + qTableName( "tst_outValues" ) + "(x out int) is\n" + QVERIFY_SQL( q, exec( "create or replace procedure " + tst_outValues + "(x out int) is\n" "begin\n" " x := 42;\n" "end;\n" ) ); - QVERIFY( q.prepare( "call " + qTableName( "tst_outvalues" ) + "(?)" ) ); + QVERIFY( q.prepare( "call " + tst_outValues + "(?)" ) ); } else if ( db.driverName().startsWith( "QDB2" ) ) { - q.exec( "drop procedure " + qTableName( "tst_outValues" ) ); //non-fatal - QVERIFY_SQL( q, exec( "CREATE PROCEDURE " + qTableName( "tst_outValues" ) + " (OUT x int)\n" + q.exec( "drop procedure " + tst_outValues ); //non-fatal + QVERIFY_SQL( q, exec( "CREATE PROCEDURE " + tst_outValues + " (OUT x int)\n" "LANGUAGE SQL\n" "P1: BEGIN\n" " SET x = 42;\n" "END P1" ) ); - QVERIFY( q.prepare( "call " + qTableName( "tst_outValues" ) + "(?)" ) ); + QVERIFY( q.prepare( "call " + tst_outValues + "(?)" ) ); } else if ( tst_Databases::isSqlServer( db ) ) { - q.exec( "drop procedure " + qTableName( "tst_outValues" ) ); //non-fatal - QVERIFY_SQL( q, exec( "create procedure " + qTableName( "tst_outValues" ) + " (@x int out) as\n" + q.exec( "drop procedure " + tst_outValues ); //non-fatal + QVERIFY_SQL( q, exec( "create procedure " + tst_outValues + " (@x int out) as\n" "begin\n" " set @x = 42\n" "end\n" ) ); - QVERIFY( q.prepare( "{call " + qTableName( "tst_outvalues" ) + "(?)}" ) ); + QVERIFY( q.prepare( "{call " + tst_outValues + "(?)}" ) ); } else { QSKIP( "Don't know how to create a stored procedure for this database server, please fix this test", SkipSingle ); return; @@ -843,11 +852,11 @@ void tst_QSqlQuery::blob() q.setForwardOnly( true ); - QString queryString = QString( "create table " + qTableName( "qtest_blob" ) + + QString queryString = QString( "create table " + qTableName( "qtest_blob", __FILE__ ) + " (id int not null primary key, t_blob %1)" ).arg( tst_Databases::blobTypeName( db, BLOBSIZE ) ); QVERIFY_SQL( q, exec( queryString ) ); - QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_blob" ) + " (id, t_blob) values (?, ?)" ) ); + QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_blob", __FILE__ ) + " (id, t_blob) values (?, ?)" ) ); for ( i = 0; i < BLOBCOUNT; ++i ) { q.addBindValue( i ); @@ -855,7 +864,7 @@ void tst_QSqlQuery::blob() QVERIFY_SQL( q, exec() ); } - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest_blob" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest_blob", __FILE__ ) ) ); for ( i = 0; i < BLOBCOUNT; ++i ) { QVERIFY( q.next() ); @@ -878,7 +887,7 @@ void tst_QSqlQuery::value() CHECK_DATABASE( db ); QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "select id, t_varchar, t_char from " + qTableName( "qtest" ) + " order by id" ) ); + QVERIFY_SQL( q, exec( "select id, t_varchar, t_char from " + qtest + " order by id" ) ); int i = 1; while ( q.next() ) { @@ -910,7 +919,7 @@ void tst_QSqlQuery::record() QSqlQuery q( db ); QVERIFY( q.record().isEmpty() ); - QVERIFY_SQL( q, exec( "select id, t_varchar, t_char from " + qTableName( "qtest" ) + " order by id" ) ); + QVERIFY_SQL( q, exec( "select id, t_varchar, t_char from " + qtest + " order by id" ) ); QSqlRecord rec = q.record(); QCOMPARE( q.record().fieldName( 0 ).toLower(), QString( "id" ) ); QCOMPARE( q.record().fieldName( 1 ).toLower(), QString( "t_varchar" ) ); @@ -934,7 +943,7 @@ void tst_QSqlQuery::isValid() QSqlQuery q( db ); QVERIFY( !q.isValid() ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); QVERIFY( q.first() ); QVERIFY( q.isValid() ); } @@ -947,7 +956,7 @@ void tst_QSqlQuery::isActive() QSqlQuery q( db ); QVERIFY( !q.isActive() ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); QVERIFY( q.isActive() ); QVERIFY( q.last() ); @@ -957,15 +966,15 @@ void tst_QSqlQuery::isActive() QVERIFY( q.isActive() ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (41, 'VarChar41', 'Char41')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (41, 'VarChar41', 'Char41')" ) ); QVERIFY( q.isActive() ); - QVERIFY_SQL( q, exec( "update " + qTableName( "qtest" ) + " set id = 42 where id = 41" ) ); + QVERIFY_SQL( q, exec( "update " + qtest + " set id = 42 where id = 41" ) ); QVERIFY( q.isActive() ); - QVERIFY_SQL( q, exec( "delete from " + qTableName( "qtest" ) + " where id = 42" ) ); + QVERIFY_SQL( q, exec( "delete from " + qtest + " where id = 42" ) ); QVERIFY( q.isActive() ); } @@ -979,7 +988,7 @@ void tst_QSqlQuery::numRowsAffected() QSqlQuery q( db ); QCOMPARE( q.numRowsAffected(), -1 ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); int i = 0; while ( q.next() ) @@ -993,21 +1002,21 @@ void tst_QSqlQuery::numRowsAffected() qDebug( "Expected numRowsAffected to be -1, 0 or %d, got %d", i, q.numRowsAffected() ); } - QVERIFY_SQL( q, exec( "update " + qTableName( "qtest" ) + " set id = 100 where id = 1" ) ); + QVERIFY_SQL( q, exec( "update " + qtest + " set id = 100 where id = 1" ) ); QCOMPARE( q.numRowsAffected(), 1 ); QCOMPARE( q.numRowsAffected(), 1 ); // yes, we check twice - QVERIFY_SQL( q, exec( "update " + qTableName( "qtest" ) + " set id = id + 100" ) ); + QVERIFY_SQL( q, exec( "update " + qtest + " set id = id + 100" ) ); QCOMPARE( q.numRowsAffected(), i ); QCOMPARE( q.numRowsAffected(), i ); // yes, we check twice - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (42000, 'homer', 'marge')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (42000, 'homer', 'marge')" ) ); QCOMPARE( q.numRowsAffected(), 1 ); QCOMPARE( q.numRowsAffected(), 1 ); // yes, we check twice QSqlQuery q2( db ); - QVERIFY_SQL( q2, exec( "insert into " + qTableName( "qtest" ) + " values (42001, 'homer', 'marge')" ) ); + QVERIFY_SQL( q2, exec( "insert into " + qtest + " values (42001, 'homer', 'marge')" ) ); if ( !db.driverName().startsWith( "QSQLITE2" ) ) { // SQLite 2.x accumulates changed rows in nested queries. See task 33794 @@ -1025,7 +1034,7 @@ void tst_QSqlQuery::size() QSqlQuery q( db ); QCOMPARE( q.size(), -1 ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); int i = 0; while ( q.next() ) @@ -1039,7 +1048,7 @@ void tst_QSqlQuery::size() QCOMPARE( q.size(), -1 ); // yes, twice } - QSqlQuery q2( "select * from " + qTableName( "qtest" ), db ); + QSqlQuery q2( "select * from " + qtest, db ); if ( db.driver()->hasFeature( QSqlDriver::QuerySize ) ) QCOMPARE( q.size(), i ); @@ -1048,7 +1057,7 @@ void tst_QSqlQuery::size() q2.clear(); - QVERIFY_SQL( q, exec( "update " + qTableName( "qtest" ) + " set id = 100 where id = 1" ) ); + QVERIFY_SQL( q, exec( "update " + qtest + " set id = 100 where id = 1" ) ); QCOMPARE( q.size(), -1 ); QCOMPARE( q.size(), -1 ); // yes, twice } @@ -1060,10 +1069,10 @@ void tst_QSqlQuery::isSelect() CHECK_DATABASE( db ); QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); QVERIFY( q.isSelect() ); - QVERIFY_SQL( q, exec( "update " + qTableName( "qtest" ) + " set id = 1 where id = 1" ) ); + QVERIFY_SQL( q, exec( "update " + qtest + " set id = 1 where id = 1" ) ); QVERIFY( q.isSelect() == false ); } @@ -1075,7 +1084,7 @@ void tst_QSqlQuery::first() QSqlQuery q( db ); QVERIFY( q.at() == QSql::BeforeFirstRow ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); QVERIFY( q.last() ); QVERIFY_SQL( q, first() ); QVERIFY( q.at() == 0 ); @@ -1089,7 +1098,7 @@ void tst_QSqlQuery::next() QSqlQuery q( db ); QVERIFY( q.at() == QSql::BeforeFirstRow ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); QVERIFY( q.first() ); QVERIFY( q.next() ); QVERIFY( q.at() == 1 ); @@ -1103,7 +1112,7 @@ void tst_QSqlQuery::prev() QSqlQuery q( db ); QVERIFY( q.at() == QSql::BeforeFirstRow ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); QVERIFY( q.first() ); QVERIFY( q.next() ); QVERIFY( q.previous() ); @@ -1118,7 +1127,7 @@ void tst_QSqlQuery::last() QSqlQuery q( db ); QCOMPARE( q.at(), int( QSql::BeforeFirstRow ) ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); int i = 0; while ( q.next() ) @@ -1132,7 +1141,7 @@ void tst_QSqlQuery::last() // Access doesn't return the correct position QCOMPARE( q.at(), ( i-1 ) ); - QSqlQuery q2( "select * from " + qTableName( "qtest" ), db ); + QSqlQuery q2( "select * from " + qtest, db ); QVERIFY( q2.last() ); @@ -1148,7 +1157,7 @@ void tst_QSqlQuery::seek() CHECK_DATABASE( db ); QSqlQuery q( db ); QVERIFY( q.at() == QSql::BeforeFirstRow ); - QVERIFY_SQL( q, exec( QString( "select id from %1 order by id" ).arg( qTableName( "qtest" ) ) ) ); + QVERIFY_SQL( q, exec( QString( "select id from %1 order by id" ).arg( qtest ) ) ); // NB! The order of the calls below are important! QVERIFY( q.last() ); @@ -1184,7 +1193,7 @@ void tst_QSqlQuery::seekForwardOnlyQuery() QVERIFY( !q.isForwardOnly() ); QVERIFY( q.at() == QSql::BeforeFirstRow ); - QVERIFY_SQL( q, exec( QString( "select id from %1 order by id" ).arg( qTableName( "qtest" ) ) ) ); + QVERIFY_SQL( q, exec( QString( "select id from %1 order by id" ).arg( qtest ) ) ); QSqlRecord rec; @@ -1223,7 +1232,7 @@ void tst_QSqlQuery::forwardOnly() q.setForwardOnly( true ); QVERIFY( q.isForwardOnly() ); QVERIFY( q.at() == QSql::BeforeFirstRow ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) + " order by id" ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest + " order by id" ) ); QVERIFY( q.at() == QSql::BeforeFirstRow ); QVERIFY( q.first() ); QCOMPARE( q.at(), 0 ); @@ -1248,7 +1257,7 @@ void tst_QSqlQuery::forwardOnly() QCOMPARE( q.at(), 3 ); QCOMPARE( q.value( 0 ).toInt(), 4 ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); int i = 0; while ( q.next() ) @@ -1260,7 +1269,7 @@ void tst_QSqlQuery::forwardOnly() QVERIFY( q2.isForwardOnly() ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) + " order by id" ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest + " order by id" ) ); QVERIFY( q.isForwardOnly() ); @@ -1306,7 +1315,7 @@ void tst_QSqlQuery::query_exec() QSqlQuery q( db ); QVERIFY( !q.isValid() ); QVERIFY( !q.isActive() ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest ) ); QVERIFY( q.isActive() ); QVERIFY( q.next() ); QVERIFY( q.isValid() ); @@ -1319,7 +1328,7 @@ void tst_QSqlQuery::isNull() CHECK_DATABASE( db ); QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "select id, t_varchar from " + qTableName( "qtest_null" ) + " order by id" ) ); + QVERIFY_SQL( q, exec( "select id, t_varchar from " + qTableName( "qtest_null", __FILE__ ) + " order by id" ) ); QVERIFY( q.next() ); QVERIFY( !q.isNull( 0 ) ); QVERIFY( q.isNull( 1 ) ); @@ -1345,13 +1354,13 @@ void tst_QSqlQuery::bitField() QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_bittest" ) + " (bitty bit)" ) ); + QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_bittest", __FILE__ ) + " (bitty bit)" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_bittest" ) + " values (0)" ) ); + QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_bittest", __FILE__ ) + " values (0)" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_bittest" ) + " values (1)" ) ); + QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_bittest", __FILE__ ) + " values (1)" ) ); - QVERIFY_SQL( q, exec( "select bitty from " + qTableName( "qtest_bittest" ) ) ); + QVERIFY_SQL( q, exec( "select bitty from " + qTableName( "qtest_bittest", __FILE__ ) ) ); QVERIFY( q.next() ); @@ -1369,15 +1378,16 @@ void tst_QSqlQuery::nullBlob() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString qtest_nullblob(qTableName("qtest_nullblob", __FILE__)); QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_nullblob" ) + " (id int primary key, bb blob)" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_nullblob" ) + " values (0, EMPTY_BLOB())" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_nullblob" ) + " values (1, NULL)" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_nullblob" ) + " values (2, 'aabbcc00112233445566')" ) ); + QVERIFY_SQL( q, exec( "create table " + qtest_nullblob + " (id int primary key, bb blob)" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_nullblob + " values (0, EMPTY_BLOB())" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_nullblob + " values (1, NULL)" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_nullblob + " values (2, 'aabbcc00112233445566')" ) ); // necessary otherwise oracle will bombard you with internal errors q.setForwardOnly( true ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest_nullblob" ) + " order by id" ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest_nullblob + " order by id" ) ); QVERIFY( q.next() ); QCOMPARE(( int )q.value( 1 ).toByteArray().size(), 0 ); @@ -1398,14 +1408,15 @@ void tst_QSqlQuery::rawField() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString qtest_rawtest(qTableName("qtest_rawtest", __FILE__)); QSqlQuery q( db ); q.setForwardOnly( true ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_rawtest" ) + + QVERIFY_SQL( q, exec( "create table " + qtest_rawtest + " (id int, col raw(20))" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_rawtest" ) + " values (0, NULL)" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_rawtest" ) + " values (1, '00aa1100ddeeff')" ) ); - QVERIFY_SQL( q, exec( "select col from " + qTableName( "qtest_rawtest" ) + " order by id" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_rawtest + " values (0, NULL)" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_rawtest + " values (1, '00aa1100ddeeff')" ) ); + QVERIFY_SQL( q, exec( "select col from " + qtest_rawtest + " order by id" ) ); QVERIFY( q.next() ); QVERIFY( q.isNull( 0 ) ); QCOMPARE(( int )q.value( 0 ).toByteArray().size(), 0 ); @@ -1422,6 +1433,7 @@ void tst_QSqlQuery::precision() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString qtest_precision(qTableName( "qtest_precision", __FILE__ )); static const char* precStr = "1.2345678901234567891"; @@ -1433,13 +1445,13 @@ void tst_QSqlQuery::precision() QSqlQuery q( db ); if ( tst_Databases::isMSAccess( db ) ) - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_precision" ) + " (col1 number)" ) ); + QVERIFY_SQL( q, exec( "create table " + qtest_precision + " (col1 number)" ) ); else - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_precision" ) + " (col1 numeric(21, 20))" ) ); + QVERIFY_SQL( q, exec( "create table " + qtest_precision + " (col1 numeric(21, 20))" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest_precision" ) + " (col1) values (1.2345678901234567891)" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_precision + " (col1) values (1.2345678901234567891)" ) ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest_precision" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest_precision ) ); QVERIFY( q.next() ); QString val = q.value( 0 ).toString(); @@ -1472,7 +1484,7 @@ void tst_QSqlQuery::nullResult() CHECK_DATABASE( db ); QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest" ) + " where id > 50000" ) ); + QVERIFY_SQL( q, exec( "select * from " + qtest + " where id > 50000" ) ); if ( q.driver()->hasFeature( QSqlDriver::QuerySize ) ) QCOMPARE( q.size(), 0 ); @@ -1513,9 +1525,9 @@ void tst_QSqlQuery::transaction() // test a working transaction q.exec( startTransactionStr ); - QVERIFY_SQL( q, exec( "insert into" + qTableName( "qtest" ) + " values (40, 'VarChar40', 'Char40')" ) ); + QVERIFY_SQL( q, exec( "insert into" + qtest + " values (40, 'VarChar40', 'Char40')" ) ); - QVERIFY_SQL( q, exec( "select * from" + qTableName( "qtest" ) + " where id = 40" ) ); + QVERIFY_SQL( q, exec( "select * from" + qtest + " where id = 40" ) ); QVERIFY( q.next() ); @@ -1523,7 +1535,7 @@ void tst_QSqlQuery::transaction() QVERIFY_SQL( q, exec( "commit" ) ); - QVERIFY_SQL( q, exec( "select * from" + qTableName( "qtest" ) + " where id = 40" ) ); + QVERIFY_SQL( q, exec( "select * from" + qtest + " where id = 40" ) ); QVERIFY( q.next() ); @@ -1532,9 +1544,9 @@ void tst_QSqlQuery::transaction() // test a rollback q.exec( startTransactionStr ); - QVERIFY_SQL( q, exec( "insert into" + qTableName( "qtest" ) + " values (41, 'VarChar41', 'Char41')" ) ); + QVERIFY_SQL( q, exec( "insert into" + qtest + " values (41, 'VarChar41', 'Char41')" ) ); - QVERIFY_SQL( q, exec( "select * from" + qTableName( "qtest" ) + " where id = 41" ) ); + QVERIFY_SQL( q, exec( "select * from" + qtest + " where id = 41" ) ); QVERIFY( q.next() ); @@ -1548,18 +1560,18 @@ void tst_QSqlQuery::transaction() QFAIL( "Could not rollback transaction: " + tst_Databases::printError( q.lastError() ) ); } - QVERIFY_SQL( q, exec( "select * from" + qTableName( "qtest" ) + " where id = 41" ) ); + QVERIFY_SQL( q, exec( "select * from" + qtest + " where id = 41" ) ); QVERIFY( q.next() == false ); // test concurrent access q.exec( startTransactionStr ); - QVERIFY_SQL( q, exec( "insert into" + qTableName( "qtest" ) + " values (42, 'VarChar42', 'Char42')" ) ); - QVERIFY_SQL( q, exec( "select * from" + qTableName( "qtest" ) + " where id = 42" ) ); + QVERIFY_SQL( q, exec( "insert into" + qtest + " values (42, 'VarChar42', 'Char42')" ) ); + QVERIFY_SQL( q, exec( "select * from" + qtest + " where id = 42" ) ); QVERIFY( q.next() ); QCOMPARE( q.value( 0 ).toInt(), 42 ); - QVERIFY_SQL( q2, exec( "select * from" + qTableName( "qtest" ) + " where id = 42" ) ); + QVERIFY_SQL( q2, exec( "select * from" + qtest + " where id = 42" ) ); if ( q2.next() ) qDebug( QString( "DBMS '%1' doesn't support query based transactions with concurrent access" ).arg( @@ -1567,7 +1579,7 @@ void tst_QSqlQuery::transaction() QVERIFY_SQL( q, exec( "commit" ) ); - QVERIFY_SQL( q2, exec( "select * from" + qTableName( "qtest" ) + " where id = 42" ) ); + QVERIFY_SQL( q2, exec( "select * from" + qtest + " where id = 42" ) ); QVERIFY( q2.next() ); @@ -1579,6 +1591,7 @@ void tst_QSqlQuery::joins() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString qtestj1(qTableName("qtestj1", __FILE__)), qtestj2(qTableName("qtestj2", __FILE__)); if ( db.driverName().startsWith( "QOCI" ) || db.driverName().startsWith( "QTDS" ) @@ -1592,17 +1605,17 @@ void tst_QSqlQuery::joins() QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtestj1" ) + " (id1 int, id2 int)" ) ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtestj2" ) + " (id int, name varchar(20))" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtestj1" ) + " values (1, 1)" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtestj1" ) + " values (1, 2)" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtestj2" ) + " values(1, 'trenton')" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtestj2" ) + " values(2, 'marius')" ) ); + QVERIFY_SQL( q, exec( "create table " + qtestj1 + " (id1 int, id2 int)" ) ); + QVERIFY_SQL( q, exec( "create table " + qtestj2 + " (id int, name varchar(20))" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtestj1 + " values (1, 1)" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtestj1 + " values (1, 2)" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtestj2 + " values(1, 'trenton')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtestj2 + " values(2, 'marius')" ) ); QVERIFY_SQL( q, exec( "select qtestj1.id1, qtestj1.id2, qtestj2.id, qtestj2.name, qtestj3.id, qtestj3.name " - "from " + qTableName( "qtestj1" ) + " qtestj1 left outer join " + qTableName( "qtestj2" ) + + "from " + qtestj1 + " qtestj1 left outer join " + qtestj2 + " qtestj2 on (qtestj1.id1 = qtestj2.id) " - "left outer join " + qTableName( "qtestj2" ) + " as qtestj3 on (qtestj1.id2 = qtestj3.id)" ) ); + "left outer join " + qtestj2 + " as qtestj3 on (qtestj1.id2 = qtestj3.id)" ) ); QVERIFY( q.next() ); QCOMPARE( q.value( 0 ).toInt(), 1 ); @@ -1628,7 +1641,7 @@ void tst_QSqlQuery::synonyms() CHECK_DATABASE( db ); QSqlQuery q(db); - QVERIFY_SQL( q, exec("select a.id, a.t_char, a.t_varchar from " + qTableName( "qtest" ) + " a where a.id = 1") ); + QVERIFY_SQL( q, exec("select a.id, a.t_char, a.t_varchar from " + qtest + " a where a.id = 1") ); QVERIFY( q.next() ); QCOMPARE( q.value( 0 ).toInt(), 1 ); QCOMPARE( q.value( 1 ).toString().trimmed(), QString( "Char1" ) ); @@ -1647,6 +1660,8 @@ void tst_QSqlQuery::prepare_bind_exec() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString qtest_prepare(qTableName("qtest_prepare", __FILE__)); + if(db.driverName().startsWith("QIBASE") && (db.databaseName() == "silence.nokia.troll.no:c:\\ibase\\testdb_ascii" || db.databaseName() == "/opt/interbase/qttest.gdb")) QSKIP("Can't transliterate extended unicode to ascii", SkipSingle); if(db.driverName().startsWith("QDB2")) @@ -1671,15 +1686,15 @@ 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 " + qTableName( "qtest_prepare" ) + " (id int primary key, name nvarchar(200) null)"; + createQuery = "create table " + qtest_prepare + " (id int primary key, name nvarchar(200) null)"; else if ( tst_Databases::isMySQL(db) && useUnicode ) - createQuery = "create table " + qTableName( "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)"; else - createQuery = "create table " + qTableName( "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))"; QVERIFY_SQL( q, exec( createQuery ) ); - QVERIFY( q.prepare( "insert into " + qTableName( "qtest_prepare" ) + " (id, name) values (:id, :name)" ) ); + QVERIFY( q.prepare( "insert into " + qtest_prepare + " (id, name) values (:id, :name)" ) ); int i; for ( i = 0; i < 6; ++i ) { @@ -1702,7 +1717,7 @@ void tst_QSqlQuery::prepare_bind_exec() QVERIFY_SQL( q, exec() ); } - QVERIFY_SQL( q, exec( "SELECT * FROM " + qTableName( "qtest_prepare" ) + " order by id" ) ); + QVERIFY_SQL( q, exec( "SELECT * FROM " + qtest_prepare + " order by id" ) ); for ( i = 0; i < 6; ++i ) { QVERIFY( q.next() ); @@ -1721,12 +1736,12 @@ void tst_QSqlQuery::prepare_bind_exec() QCOMPARE( q.value( 0 ).toInt(), 8 ); QCOMPARE( q.value( 1 ).toString(), values[5] ); - QVERIFY( q.prepare( "insert into " + qTableName( "qtest_prepare" ) + " (id, name) values (:id, 'Bart')" ) ); + QVERIFY( q.prepare( "insert into " + qtest_prepare + " (id, name) values (:id, 'Bart')" ) ); q.bindValue( ":id", 99 ); QVERIFY_SQL( q, exec() ); q.bindValue( ":id", 100 ); QVERIFY_SQL( q, exec() ); - QVERIFY( q.exec( "select * from " + qTableName( "qtest_prepare" ) + " where id > 98 order by id" ) ); + QVERIFY( q.exec( "select * from " + qtest_prepare + " where id > 98 order by id" ) ); for ( i = 99; i <= 100; ++i ) { QVERIFY( q.next() ); @@ -1735,7 +1750,7 @@ void tst_QSqlQuery::prepare_bind_exec() } /*** SELECT stuff ***/ - QVERIFY( q.prepare( "select * from " + qTableName( "qtest_prepare" ) + " where id = :id" ) ); + QVERIFY( q.prepare( "select * from " + qtest_prepare + " where id = :id" ) ); for ( i = 0; i < 6; ++i ) { q.bindValue( ":id", i ); @@ -1750,9 +1765,9 @@ void tst_QSqlQuery::prepare_bind_exec() QVERIFY( !q.next() ); } - QVERIFY_SQL( q, exec( "DELETE FROM " + qTableName( "qtest_prepare" ) ) ); + QVERIFY_SQL( q, exec( "DELETE FROM " + qtest_prepare ) ); - QVERIFY( q.prepare( "insert into " + qTableName( "qtest_prepare" ) + " (id, name) values (?, ?)" ) ); + QVERIFY( q.prepare( "insert into " + qtest_prepare + " (id, name) values (?, ?)" ) ); q.bindValue( 0, 0 ); q.bindValue( 1, values[ 0 ] ); QVERIFY_SQL( q, exec() ); @@ -1781,7 +1796,7 @@ void tst_QSqlQuery::prepare_bind_exec() QVERIFY_SQL( q, exec() ); } - QVERIFY_SQL( q, exec( "SELECT * FROM " + qTableName( "qtest_prepare" ) + " order by id" ) ); + QVERIFY_SQL( q, exec( "SELECT * FROM " + qtest_prepare + " order by id" ) ); for ( i = 0; i < 6; ++i ) { QVERIFY( q.next() ); @@ -1800,13 +1815,13 @@ void tst_QSqlQuery::prepare_bind_exec() QCOMPARE( q.value( 1 ).toString(), utf8str ); } - QVERIFY( q.prepare( "insert into " + qTableName( "qtest_prepare" ) + " (id, name) values (?, 'Bart')" ) ); + QVERIFY( q.prepare( "insert into " + qtest_prepare + " (id, name) values (?, 'Bart')" ) ); q.bindValue( 0, 99 ); QVERIFY_SQL( q, exec() ); q.addBindValue( 100 ); QVERIFY_SQL( q, exec() ); - QVERIFY( q.exec( "select * from " + qTableName( "qtest_prepare" ) + " where id > 98 order by id" ) ); + QVERIFY( q.exec( "select * from " + qtest_prepare + " where id > 98 order by id" ) ); for ( i = 99; i <= 100; ++i ) { QVERIFY( q.next() ); @@ -1815,7 +1830,7 @@ void tst_QSqlQuery::prepare_bind_exec() } /* insert a duplicate id and make sure the db bails out */ - QVERIFY( q.prepare( "insert into " + qTableName( "qtest_prepare" ) + " (id, name) values (?, ?)" ) ); + QVERIFY( q.prepare( "insert into " + qtest_prepare + " (id, name) values (?, ?)" ) ); q.addBindValue( 99 ); @@ -1837,7 +1852,7 @@ void tst_QSqlQuery::prepared_select() CHECK_DATABASE( db ); QSqlQuery q( db ); - QVERIFY_SQL( q, prepare( "select a.id, a.t_char, a.t_varchar from " + qTableName( "qtest" ) + " a where a.id = ?" ) ); + QVERIFY_SQL( q, prepare( "select a.id, a.t_char, a.t_varchar from " + qtest + " a where a.id = ?" ) ); q.bindValue( 0, 1 ); QVERIFY_SQL( q, exec() ); @@ -1857,7 +1872,7 @@ void tst_QSqlQuery::prepared_select() QVERIFY( q.next() ); QCOMPARE( q.value( 0 ).toInt(), 3 ); - QVERIFY_SQL( q, prepare( "select a.id, a.t_char, a.t_varchar from " + qTableName( "qtest" ) + " a where a.id = ?" ) ); + QVERIFY_SQL( q, prepare( "select a.id, a.t_char, a.t_varchar from " + qtest + " a where a.id = ?" ) ); QCOMPARE( q.at(), ( int )QSql::BeforeFirstRow ); QVERIFY( !q.first() ); } @@ -1873,9 +1888,9 @@ void tst_QSqlQuery::sqlServerLongStrings() QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "CREATE TABLE " + qTableName( "qtest_longstr" ) + " (id int primary key, longstring ntext)" ) ); + QVERIFY_SQL( q, exec( "CREATE TABLE " + qTableName( "qtest_longstr", __FILE__ ) + " (id int primary key, longstring ntext)" ) ); - QVERIFY_SQL( q, prepare( "INSERT INTO " + qTableName( "qtest_longstr" ) + " VALUES (?, ?)" ) ); + QVERIFY_SQL( q, prepare( "INSERT INTO " + qTableName( "qtest_longstr", __FILE__ ) + " VALUES (?, ?)" ) ); q.addBindValue( 0 ); @@ -1893,7 +1908,7 @@ void tst_QSqlQuery::sqlServerLongStrings() QVERIFY_SQL( q, exec() ); - QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest_longstr" ) ) ); + QVERIFY_SQL( q, exec( "select * from " + qTableName( "qtest_longstr", __FILE__ ) ) ); QVERIFY_SQL( q, next() ); @@ -1957,7 +1972,7 @@ void tst_QSqlQuery::batchExec() QSKIP( "Database can't do BatchOperations", SkipSingle ); QSqlQuery q( db ); - QString tableName = qTableName( "qtest_batch" ); + const QString tableName = qTableName( "qtest_batch", __FILE__ ); QVERIFY_SQL( q, exec( "create table " + tableName + " (id int, name varchar(20), dt date, num numeric(8, 4))" ) ); QVERIFY_SQL( q, prepare( "insert into " + tableName + " (id, name, dt, num) values (?, ?, ?, ?)" ) ); @@ -2101,9 +2116,9 @@ void tst_QSqlQuery::record_sqlite() QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table "+qTableName( "record_sqlite" )+"(id integer primary key, name varchar, title int)" ) ); + QVERIFY_SQL( q, exec( "create table "+qTableName( "record_sqlite", __FILE__ )+"(id integer primary key, name varchar, title int)" ) ); - QSqlRecord rec = db.record( qTableName( "record_sqlite" ) ); + QSqlRecord rec = db.record( qTableName( "record_sqlite", __FILE__ ) ); QCOMPARE( rec.count(), 3 ); QCOMPARE( rec.field( 0 ).type(), QVariant::Int ); @@ -2111,7 +2126,7 @@ void tst_QSqlQuery::record_sqlite() QCOMPARE( rec.field( 2 ).type(), QVariant::Int ); /* important - select from an empty table */ - QVERIFY_SQL( q, exec( "select id, name, title from "+qTableName( "record_sqlite" ) ) ); + QVERIFY_SQL( q, exec( "select id, name, title from "+qTableName( "record_sqlite", __FILE__ ) ) ); rec = q.record(); QCOMPARE( rec.count(), 3 ); @@ -2130,13 +2145,13 @@ void tst_QSqlQuery::oraLong() QString aLotOfText( 127000, QLatin1Char( 'H' ) ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_longstr" ) + " (id int primary key, astr long)" ) ); - QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_longstr" ) + " (id, astr) values (?, ?)" ) ); + QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_longstr", __FILE__ ) + " (id int primary key, astr long)" ) ); + QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_longstr", __FILE__ ) + " (id, astr) values (?, ?)" ) ); q.addBindValue( 1 ); q.addBindValue( aLotOfText ); QVERIFY_SQL( q, exec() ); - QVERIFY_SQL( q, exec( "select id,astr from " + qTableName( "qtest_longstr" ) ) ); + QVERIFY_SQL( q, exec( "select id,astr from " + qTableName( "qtest_longstr", __FILE__ ) ) ); QVERIFY( q.next() ); QCOMPARE( q.value( 0 ).toInt(), 1 ); @@ -2151,8 +2166,8 @@ void tst_QSqlQuery::execErrorRecovery() QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_exerr" ) + " (id int not null primary key)" ) ); - QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_exerr" ) + " values (?)" ) ); + 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 (?)" ) ); q.addBindValue( 1 ); QVERIFY_SQL( q, exec() ); @@ -2175,7 +2190,7 @@ void tst_QSqlQuery::lastInsertId() QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "qtest" ) + " values (41, 'VarChar41', 'Char41')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (41, 'VarChar41', 'Char41')" ) ); QVariant v = q.lastInsertId(); @@ -2189,7 +2204,7 @@ void tst_QSqlQuery::lastQuery() CHECK_DATABASE( db ); QSqlQuery q( db ); - QString sql = "select * from " + qTableName( "qtest" ); + QString sql = "select * from " + qtest; QVERIFY_SQL( q, exec( sql ) ); QCOMPARE( q.lastQuery(), sql ); QCOMPARE( q.executedQuery(), sql ); @@ -2208,7 +2223,7 @@ void tst_QSqlQuery::bindWithDoubleColonCastOperator() return; } - QString tablename = qTableName( "bindtest" ); + const QString tablename(qTableName( "bindtest", __FILE__ )); QSqlQuery q( db ); @@ -2282,7 +2297,7 @@ void tst_QSqlQuery::createQueryOnClosedDatabase() QSqlQuery q( db ); db.open(); - QVERIFY_SQL( q, exec( QString( "select * from %1 where id = 1" ).arg( qTableName( "qtest" ) ) ) ); + QVERIFY_SQL( q, exec( QString( "select * from %1 where id = 1" ).arg( qtest ) ) ); QVERIFY_SQL( q, next() ); QCOMPARE( q.value( 0 ).toInt(), 1 ); @@ -2290,7 +2305,7 @@ void tst_QSqlQuery::createQueryOnClosedDatabase() QCOMPARE( q.value( 2 ).toString().trimmed(), QLatin1String( "Char1" ) ); db.close(); - QVERIFY2( !q.exec( QString( "select * from %1 where id = 1" ).arg( qTableName( "qtest" ) ) ), + QVERIFY2( !q.exec( QString( "select * from %1 where id = 1" ).arg( qtest ) ), qPrintable( QString( "This can't happen! The query should not have been executed!" ) ) ); } @@ -2303,7 +2318,7 @@ void tst_QSqlQuery::reExecutePreparedForwardOnlyQuery() QSqlQuery q( db ); q.setForwardOnly( true ); - QVERIFY_SQL( q, prepare( QString( "SELECT id, t_varchar, t_char FROM %1 WHERE id = :id" ).arg( qTableName( "qtest" ) ) ) ); + QVERIFY_SQL( q, prepare( QString( "SELECT id, t_varchar, t_char FROM %1 WHERE id = :id" ).arg( qtest ) ) ); q.bindValue( ":id", 1 ); QVERIFY_SQL( q, exec() ); @@ -2328,7 +2343,7 @@ void tst_QSqlQuery::finish() CHECK_DATABASE( db ); QSqlQuery q( db ); - QVERIFY_SQL( q, prepare( "SELECT id FROM " + qTableName( "qtest" ) + " WHERE id = ?" ) ); + QVERIFY_SQL( q, prepare( "SELECT id FROM " + qtest + " WHERE id = ?" ) ); int id = 4; q.bindValue( 0, id ); @@ -2349,7 +2364,7 @@ void tst_QSqlQuery::finish() q.finish(); QVERIFY( !q.isActive() ); - QVERIFY_SQL( q, exec( "SELECT id FROM " + qTableName( "qtest" ) + " WHERE id = 1" ) ); + QVERIFY_SQL( q, exec( "SELECT id FROM " + qtest + " WHERE id = 1" ) ); QVERIFY( q.isActive() ); QVERIFY_SQL( q, next() ); QCOMPARE( q.value( 0 ).toInt(), 1 ); @@ -2374,7 +2389,7 @@ void tst_QSqlQuery::sqlite_finish() db2.setDatabaseName( db.databaseName() ); QVERIFY_SQL( db2, open() ); - QString tableName = qTableName( "qtest_lockedtable" ); + const QString tableName(qTableName( "qtest_lockedtable", __FILE__ )); QSqlQuery q( db ); tst_Databases::safeDropTable( db, tableName ); @@ -2424,7 +2439,7 @@ void tst_QSqlQuery::nextResult() else if ( db.driverName().startsWith( "QDB2" ) ) driverType = DB2; - QString tableName = qTableName( "more_results" ); + const QString tableName(qTableName( "more_results", __FILE__ )); QVERIFY_SQL( q, exec( "CREATE TABLE " + tableName + " (id integer, text varchar(20), num numeric(6, 3), empty varchar(10));" ) ); @@ -2528,7 +2543,7 @@ void tst_QSqlQuery::nextResult() } // Stored procedure with multiple result sets - QString procName = qTableName( "proc_more_res" ); + const QString procName(qTableName( "proc_more_res", __FILE__ )); q.exec( QString( "DROP PROCEDURE %1;" ).arg( procName ) ); @@ -2606,7 +2621,7 @@ void tst_QSqlQuery::blobsPreparedQuery() if ( !db.driver()->hasFeature( QSqlDriver::BLOB ) || !db.driver()->hasFeature( QSqlDriver::PreparedQueries ) ) QSKIP( "DBMS does not support BLOBs or prepared queries", SkipSingle ); - QString tableName = qTableName( "blobstest" ); + const QString tableName(qTableName( "blobstest", __FILE__ )); QSqlQuery q( db ); q.setForwardOnly( true ); // This is needed to make the test work with DB2. @@ -2661,8 +2676,8 @@ void tst_QSqlQuery::emptyTableNavigate() { QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_empty" ) + " (id char(10))" ) ); - QVERIFY_SQL( q, prepare( "select * from " + qTableName( "qtest_empty" ) ) ); + QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_empty", __FILE__ ) + " (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 ); @@ -2675,19 +2690,20 @@ void tst_QSqlQuery::task_217003() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); QSqlQuery q( db ); + const QString Planet(qTableName( "Planet", __FILE__)); - QVERIFY_SQL( q, exec( "create table " + qTableName( "Planet" ) + " (Name varchar(20))" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "Planet" ) + " VALUES ('Mercury')" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "Planet" ) + " VALUES ('Venus')" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "Planet" ) + " VALUES ('Earth')" ) ); - QVERIFY_SQL( q, exec( "insert into " + qTableName( "Planet" ) + " VALUES ('Mars')" ) ); + 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')" ) ); + QVERIFY_SQL( q, exec( "insert into " + Planet + " VALUES ('Earth')" ) ); + QVERIFY_SQL( q, exec( "insert into " + Planet + " VALUES ('Mars')" ) ); - QVERIFY_SQL( q, exec( "SELECT Name FROM "+qTableName( "Planet" ) ) ); + QVERIFY_SQL( q, exec( "SELECT Name FROM " + Planet ) ); QVERIFY_SQL( q, seek( 3 ) ); QCOMPARE( q.value( 0 ).toString(), QString( "Mars" ) ); QVERIFY_SQL( q, seek( 1 ) ); QCOMPARE( q.value( 0 ).toString(), QString( "Venus" ) ); - QVERIFY_SQL( q, exec( "SELECT Name FROM "+qTableName( "Planet" ) ) ); + QVERIFY_SQL( q, exec( "SELECT Name FROM " + Planet ) ); QVERIFY_SQL( q, seek( 3 ) ); QCOMPARE( q.value( 0 ).toString(), QString( "Mars" ) ); QVERIFY_SQL( q, seek( 0 ) ); @@ -2704,7 +2720,7 @@ void tst_QSqlQuery::task_250026() CHECK_DATABASE( db ); QSqlQuery q( db ); - QString tableName = qTableName( "task_250026" ); + const QString tableName(qTableName( "task_250026", __FILE__ )); if ( !q.exec( "create table " + tableName + " (longfield varchar(1100))" ) ) { qDebug() << "Error" << q.lastError(); @@ -2752,7 +2768,7 @@ void tst_QSqlQuery::task_229811() QSqlQuery q( db ); - QString tableName = qTableName( "task_229811" ); + const QString tableName(qTableName( "task_229811", __FILE__ )); if ( !q.exec( "CREATE TABLE " + tableName + " (Word varchar(20))" ) ) { qDebug() << "Warning" << q.lastError(); @@ -2799,7 +2815,7 @@ void tst_QSqlQuery::task_234422() m_airlines << "Lufthansa" << "SAS" << "United" << "KLM" << "Aeroflot"; m_countries << "DE" << "SE" << "US" << "NL" << "RU"; - QString tableName = qTableName( "task_234422" ); + const QString tableName(qTableName( "task_234422", __FILE__ )); QVERIFY_SQL(query,exec("CREATE TABLE " + tableName + " (id int primary key, " "name varchar(20), homecountry varchar(2))")); @@ -2831,7 +2847,7 @@ void tst_QSqlQuery::task_233829() CHECK_DATABASE( db ); QSqlQuery q( db ); - QString tableName = qTableName("task_233829"); + const QString tableName(qTableName("task_233829", __FILE__)); QVERIFY_SQL(q,exec("CREATE TABLE " + tableName + "(dbl1 double precision,dbl2 double precision) without oids;")); QString queryString("INSERT INTO " + tableName +"(dbl1, dbl2) VALUES(?,?)"); @@ -2851,7 +2867,7 @@ void tst_QSqlQuery::sqlServerReturn0() if (!tst_Databases::isSqlServer( db )) QSKIP("SQL Server specific test", SkipSingle); - QString tableName(qTableName("test141895")), procName(qTableName("test141895_proc")); + const QString tableName(qTableName("test141895", __FILE__)), procName(qTableName("test141895_proc", __FILE__)); QSqlQuery q( db ); q.exec("DROP TABLE " + tableName); q.exec("DROP PROCEDURE " + procName); @@ -2877,7 +2893,7 @@ void tst_QSqlQuery::QTBUG_551() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); QSqlQuery q(db); - QString pkgname=qTableName("pkg"); + const QString pkgname(qTableName("pkg", __FILE__)); QVERIFY_SQL(q, exec("CREATE OR REPLACE PACKAGE "+pkgname+" IS \n\ \n\ TYPE IntType IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;\n\ @@ -2923,17 +2939,18 @@ void tst_QSqlQuery::QTBUG_5251() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + const QString timetest(qTableName("timetest", __FILE__)); if (!db.driverName().startsWith( "QPSQL" )) return; QSqlQuery q(db); - q.exec("DROP TABLE " + qTableName("timetest")); - QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("timetest") + " (t TIME)")); - QVERIFY_SQL(q, exec("INSERT INTO " + qTableName("timetest") + " VALUES ('1:2:3.666')")); + q.exec("DROP TABLE " + timetest); + QVERIFY_SQL(q, exec("CREATE TABLE " + timetest + " (t TIME)")); + QVERIFY_SQL(q, exec("INSERT INTO " + timetest + " VALUES ('1:2:3.666')")); QSqlTableModel timetestModel(0,db); timetestModel.setEditStrategy(QSqlTableModel::OnManualSubmit); - timetestModel.setTable(qTableName("timetest")); + timetestModel.setTable(timetest); QVERIFY_SQL(timetestModel, select()); QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("01:02:03.666")); @@ -2942,7 +2959,7 @@ void tst_QSqlQuery::QTBUG_5251() QVERIFY_SQL(timetestModel, submitAll()); QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500")); - QVERIFY_SQL(q, exec("UPDATE " + qTableName("timetest") + " SET t = '0:11:22.33'")); + QVERIFY_SQL(q, exec("UPDATE " + timetest + " SET t = '0:11:22.33'")); QVERIFY_SQL(timetestModel, select()); QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:11:22.330")); @@ -2955,7 +2972,7 @@ void tst_QSqlQuery::QTBUG_6421() CHECK_DATABASE( db ); QSqlQuery q(db); - QString tableName=qTableName(QLatin1String("bug6421")).toUpper(); + const QString tableName(qTableName("bug6421", __FILE__).toUpper()); QVERIFY_SQL(q, exec("create table "+tableName+"(COL1 char(10), COL2 char(10), COL3 char(10))")); QVERIFY_SQL(q, exec("create index INDEX1 on "+tableName+" (COL1 desc)")); @@ -2980,16 +2997,16 @@ void tst_QSqlQuery::QTBUG_6618() QSKIP("SQL Server specific test", SkipSingle); QSqlQuery q(db); - q.exec( "drop procedure " + qTableName( "tst_raiseError" ) ); //non-fatal + q.exec( "drop procedure " + qTableName( "tst_raiseError", __FILE__ ) ); //non-fatal QString errorString; for (int i=0;i<110;i++) errorString+="reallylong"; errorString+=" error"; - QVERIFY_SQL( q, exec("create procedure " + qTableName( "tst_raiseError" ) + " as\n" + QVERIFY_SQL( q, exec("create procedure " + qTableName( "tst_raiseError", __FILE__ ) + " as\n" "begin\n" " raiserror('" + errorString + "', 16, 1)\n" "end\n" )); - q.exec( "{call " + qTableName( "tst_raiseError" ) + "}" ); + q.exec( "{call " + qTableName( "tst_raiseError", __FILE__ ) + "}" ); QVERIFY(q.lastError().text().contains(errorString)); } @@ -3002,7 +3019,7 @@ void tst_QSqlQuery::QTBUG_6852() QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); QSqlQuery q(db); - QString tableName(qTableName(QLatin1String("bug6852"))), procName(qTableName(QLatin1String("bug6852_proc"))); + const QString tableName(qTableName("bug6852", __FILE__)), procName(qTableName("bug6852_proc", __FILE__)); QVERIFY_SQL(q, exec("DROP PROCEDURE IF EXISTS "+procName)); QVERIFY_SQL(q, exec("CREATE TABLE "+tableName+"(\n" @@ -3036,7 +3053,7 @@ void tst_QSqlQuery::QTBUG_5765() QSKIP( "Test requires MySQL >= 4.1", SkipSingle ); QSqlQuery q(db); - QString tableName(qTableName(QLatin1String("bug5765"))); + const QString tableName(qTableName("bug5765", __FILE__)); QVERIFY_SQL(q, exec("CREATE TABLE "+tableName+"(testval TINYINT(1) DEFAULT 0)")); q.prepare("INSERT INTO "+tableName+" SET testval = :VALUE"); @@ -3074,7 +3091,7 @@ void tst_QSqlQuery::benchmark() QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); QSqlQuery q(db); - QString tableName(qTableName(QLatin1String("benchmark"))); + const QString tableName(qTableName("benchmark", __FILE__)); tst_Databases::safeDropTable( db, tableName ); diff --git a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp index 7e75d28..b64d599 100644 --- a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp +++ b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp @@ -148,10 +148,10 @@ void tst_QSqlQueryModel::cleanupTestCase() void tst_QSqlQueryModel::dropTestTables(QSqlDatabase db) { QStringList tableNames; - tableNames << qTableName("test") - << qTableName("test2") - << qTableName("test3") - << qTableName("many"); + tableNames << qTableName("test", __FILE__) + << qTableName("test2", __FILE__) + << qTableName("test3", __FILE__) + << qTableName("many", __FILE__); tst_Databases::safeDropTables(db, tableNames); } @@ -161,10 +161,10 @@ void tst_QSqlQueryModel::createTestTables(QSqlDatabase db) QSqlQuery q(db); if(tst_Databases::isPostgreSQL(db)) QVERIFY_SQL( q, exec("set client_min_messages='warning'")); - QVERIFY_SQL( q, exec("create table " + qTableName("test") + "(id integer not null, name varchar(20), title integer, primary key (id))")); - QVERIFY_SQL( q, exec("create table " + qTableName("test2") + "(id integer not null, title varchar(20), primary key (id))")); - QVERIFY_SQL( q, exec("create table " + qTableName("test3") + "(id integer not null, primary key (id))")); - QVERIFY_SQL( q, exec("create table " + qTableName("many") + "(id integer not null, name varchar(20), primary key (id))")); + QVERIFY_SQL( q, exec("create table " + qTableName("test", __FILE__) + "(id integer not null, name varchar(20), title integer, primary key (id))")); + QVERIFY_SQL( q, exec("create table " + qTableName("test2", __FILE__) + "(id integer not null, title varchar(20), primary key (id))")); + QVERIFY_SQL( q, exec("create table " + qTableName("test3", __FILE__) + "(id integer not null, primary key (id))")); + QVERIFY_SQL( q, exec("create table " + qTableName("many", __FILE__) + "(id integer not null, name varchar(20), primary key (id))")); } void tst_QSqlQueryModel::populateTestTables(QSqlDatabase db) @@ -174,38 +174,38 @@ void tst_QSqlQueryModel::populateTestTables(QSqlDatabase db) QSqlQuery q(db), q2(db); - tst_Databases::safeDropTables(db, QStringList() << qTableName("manytmp") << qTableName("test3tmp")); - QVERIFY_SQL(q, exec("create table " + qTableName("manytmp") + "(id integer not null, name varchar(20), primary key (id))")); - QVERIFY_SQL(q, exec("create table " + qTableName("test3tmp") + "(id integer not null, primary key (id))")); + tst_Databases::safeDropTables(db, QStringList() << qTableName("manytmp", __FILE__) << qTableName("test3tmp", __FILE__)); + QVERIFY_SQL(q, exec("create table " + qTableName("manytmp", __FILE__) + "(id integer not null, name varchar(20), primary key (id))")); + QVERIFY_SQL(q, exec("create table " + qTableName("test3tmp", __FILE__) + "(id integer not null, primary key (id))")); if (hasTransactions) QVERIFY_SQL(db, transaction()); - QVERIFY_SQL(q, exec("insert into " + qTableName("test") + " values(1, 'harry', 1)")); - QVERIFY_SQL(q, exec("insert into " + qTableName("test") + " values(2, 'trond', 2)")); - QVERIFY_SQL(q, exec("insert into " + qTableName("test2") + " values(1, 'herr')")); - QVERIFY_SQL(q, exec("insert into " + qTableName("test2") + " values(2, 'mister')")); + QVERIFY_SQL(q, exec("insert into " + qTableName("test", __FILE__) + " values(1, 'harry', 1)")); + QVERIFY_SQL(q, exec("insert into " + qTableName("test", __FILE__) + " values(2, 'trond', 2)")); + QVERIFY_SQL(q, exec("insert into " + qTableName("test2", __FILE__) + " values(1, 'herr')")); + QVERIFY_SQL(q, exec("insert into " + qTableName("test2", __FILE__) + " values(2, 'mister')")); - QVERIFY_SQL(q, exec(QString("insert into " + qTableName("test3") + " values(0)"))); - QVERIFY_SQL(q, prepare("insert into "+qTableName("test3")+"(id) select id + ? from "+qTableName("test3tmp"))); + QVERIFY_SQL(q, exec(QString("insert into " + qTableName("test3", __FILE__) + " values(0)"))); + QVERIFY_SQL(q, prepare("insert into "+qTableName("test3", __FILE__)+"(id) select id + ? from "+qTableName("test3tmp", __FILE__))); for (int i=1; i<260; i*=2) { - q2.exec("delete from "+qTableName("test3tmp")); - QVERIFY_SQL(q2, exec("insert into "+qTableName("test3tmp")+"(id) select id from "+qTableName("test3"))); + q2.exec("delete from "+qTableName("test3tmp", __FILE__)); + QVERIFY_SQL(q2, exec("insert into "+qTableName("test3tmp", __FILE__)+"(id) select id from "+qTableName("test3", __FILE__))); q.bindValue(0, i); QVERIFY_SQL(q, exec()); } - QVERIFY_SQL(q, exec(QString("insert into " + qTableName("many") + "(id, name) values (0, \'harry\')"))); - QVERIFY_SQL(q, prepare("insert into "+qTableName("many")+"(id, name) select id + ?, name from "+qTableName("manytmp"))); + QVERIFY_SQL(q, exec(QString("insert into " + qTableName("many", __FILE__) + "(id, name) values (0, \'harry\')"))); + QVERIFY_SQL(q, prepare("insert into "+qTableName("many", __FILE__)+"(id, name) select id + ?, name from "+qTableName("manytmp", __FILE__))); for (int i=1; i < 2048; i*=2) { - q2.exec("delete from "+qTableName("manytmp")); - QVERIFY_SQL(q2, exec("insert into "+qTableName("manytmp")+"(id, name) select id, name from "+qTableName("many"))); + q2.exec("delete from "+qTableName("manytmp", __FILE__)); + QVERIFY_SQL(q2, exec("insert into "+qTableName("manytmp", __FILE__)+"(id, name) select id, name from "+qTableName("many", __FILE__))); q.bindValue(0, i); QVERIFY_SQL(q, exec()); } if (hasTransactions) QVERIFY_SQL(db, commit()); - tst_Databases::safeDropTables(db, QStringList() << qTableName("manytmp") << qTableName("test3tmp")); + tst_Databases::safeDropTables(db, QStringList() << qTableName("manytmp", __FILE__) << qTableName("test3tmp", __FILE__)); } void tst_QSqlQueryModel::generic_data(const QString& engine) @@ -233,7 +233,7 @@ void tst_QSqlQueryModel::removeColumn() CHECK_DATABASE(db); DBTestModel model; - model.setQuery(QSqlQuery("select * from " + qTableName("test"), db)); + model.setQuery(QSqlQuery("select * from " + qTableName("test", __FILE__), db)); model.fetchMore(); QSignalSpy spy(&model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int))); @@ -315,7 +315,7 @@ void tst_QSqlQueryModel::insertColumn() CHECK_DATABASE(db); DBTestModel model; - model.setQuery(QSqlQuery("select * from " + qTableName("test"), db)); + model.setQuery(QSqlQuery("select * from " + qTableName("test", __FILE__), db)); model.fetchMore(); // necessary??? QSignalSpy spy(&model, SIGNAL(columnsInserted(QModelIndex, int, int))); @@ -395,7 +395,7 @@ void tst_QSqlQueryModel::record() CHECK_DATABASE(db); QSqlQueryModel model; - model.setQuery(QSqlQuery("select * from " + qTableName("test"), db)); + model.setQuery(QSqlQuery("select * from " + qTableName("test", __FILE__), db)); QSqlRecord rec = model.record(); @@ -429,7 +429,7 @@ void tst_QSqlQueryModel::setHeaderData() QVERIFY(!model.setHeaderData(5, Qt::Vertical, "foo")); QVERIFY(model.headerData(5, Qt::Vertical).isValid()); - model.setQuery(QSqlQuery("select * from " + qTableName("test"), db)); + model.setQuery(QSqlQuery("select * from " + qTableName("test", __FILE__), db)); qRegisterMetaType("Qt::Orientation"); QSignalSpy spy(&model, SIGNAL(headerDataChanged(Qt::Orientation, int, int))); @@ -459,7 +459,7 @@ void tst_QSqlQueryModel::fetchMore() QSqlQueryModel model; QSignalSpy spy(&model, SIGNAL(rowsInserted(QModelIndex, int, int))); - model.setQuery(QSqlQuery("select * from " + qTableName("many"), db)); + model.setQuery(QSqlQuery("select * from " + qTableName("many", __FILE__), db)); int rowCount = model.rowCount(); QCOMPARE(spy.value(0).value(1).toInt(), 0); @@ -491,7 +491,7 @@ void tst_QSqlQueryModel::withSortFilterProxyModel() QSKIP("Test applies only for drivers not reporting the query size.", SkipSingle); QSqlQueryModel model; - model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test3"), db)); + model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test3", __FILE__), db)); QSortFilterProxyModel proxy; proxy.setSourceModel(&model); @@ -500,7 +500,7 @@ void tst_QSqlQueryModel::withSortFilterProxyModel() QSignalSpy modelRowsRemovedSpy(&model, SIGNAL(rowsRemoved(const QModelIndex &, int, int))); QSignalSpy modelRowsInsertedSpy(&model, SIGNAL(rowsInserted(const QModelIndex &, int, int))); - model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test3"), db)); + model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test3", __FILE__), db)); view.scrollToBottom(); QTestEventLoop::instance().enterLoop(1); @@ -536,12 +536,12 @@ void tst_QSqlQueryModel::setQuerySignalEmission() QSignalSpy modelRowsRemovedSpy(&model, SIGNAL(rowsRemoved(const QModelIndex &, int, int))); // First select, the model was empty and no rows had to be removed! - model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test"), db)); + model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test", __FILE__), db)); QCOMPARE(modelRowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(modelRowsRemovedSpy.count(), 0); // Second select, the model wasn't empty and two rows had to be removed! - model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test"), db)); + model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test", __FILE__), db)); QCOMPARE(modelRowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(modelRowsAboutToBeRemovedSpy.value(0).value(1).toInt(), 0); QCOMPARE(modelRowsAboutToBeRemovedSpy.value(0).value(2).toInt(), 1); @@ -564,7 +564,7 @@ void tst_QSqlQueryModel::setQueryWithNoRowsInResultSet() // The query's result set will be empty so no signals should be emitted! QSqlQuery query(db); - QVERIFY_SQL(query, exec("SELECT * FROM " + qTableName("test") + " where 0 = 1")); + QVERIFY_SQL(query, exec("SELECT * FROM " + qTableName("test", __FILE__) + " where 0 = 1")); model.setQuery(query); QCOMPARE(modelRowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(modelRowsInsertedSpy.count(), 0); @@ -578,13 +578,14 @@ void tst_QSqlQueryModel::task_180617() QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); + const QString test3(qTableName("test3", __FILE__)); QTableView view; QCOMPARE(view.columnAt(0), -1); QCOMPARE(view.rowAt(0), -1); QSqlQueryModel model; - model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db ); + model.setQuery( "SELECT TOP 0 * FROM " + test3, db ); view.setModel(&model); bool error = false; @@ -595,10 +596,10 @@ void tst_QSqlQueryModel::task_180617() QCOMPARE(view.columnAt(0), (error)?-1:0 ); QCOMPARE(view.rowAt(0), -1); - model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db ); - model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db ); - model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db ); - model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db ); + model.setQuery( "SELECT TOP 0 * FROM " + test3, db ); + model.setQuery( "SELECT TOP 0 * FROM " + test3, db ); + model.setQuery( "SELECT TOP 0 * FROM " + test3, db ); + model.setQuery( "SELECT TOP 0 * FROM " + test3, db ); QCOMPARE(view.columnAt(0), (error)?-1:0 ); QCOMPARE(view.rowAt(0), -1); diff --git a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp index eab1364..c4bd540 100644 --- a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp +++ b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp @@ -45,6 +45,11 @@ #include "../qsqldatabase/tst_databases.h" +const QString reltest1(qTableName("reltest1", __FILE__)), + reltest2(qTableName("reltest2", __FILE__)), + reltest3(qTableName("reltest3", __FILE__)), + reltest4(qTableName("reltest4", __FILE__)), + reltest5(qTableName("reltest5", __FILE__)); //TESTED_CLASS= @@ -107,37 +112,37 @@ void tst_QSqlRelationalTableModel::recreateTestTables(QSqlDatabase db) dropTestTables(db); QSqlQuery q(db); - QVERIFY_SQL( q, exec("create table " + qTableName("reltest1") + + QVERIFY_SQL( q, exec("create table " + reltest1 + " (id int not null primary key, name varchar(20), title_key int, another_title_key int)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest1") + " values(1, 'harry', 1, 2)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest1") + " values(2, 'trond', 2, 1)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest1") + " values(3, 'vohi', 1, 2)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest1") + " values(4, 'boris', 2, 2)")); + QVERIFY_SQL( q, exec("insert into " + reltest1 + " values(1, 'harry', 1, 2)")); + QVERIFY_SQL( q, exec("insert into " + reltest1 + " values(2, 'trond', 2, 1)")); + QVERIFY_SQL( q, exec("insert into " + reltest1 + " values(3, 'vohi', 1, 2)")); + QVERIFY_SQL( q, exec("insert into " + reltest1 + " values(4, 'boris', 2, 2)")); - QVERIFY_SQL( q, exec("create table " + qTableName("reltest2") + " (tid int not null primary key, title varchar(20))")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest2") + " values(1, 'herr')")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest2") + " values(2, 'mister')")); + QVERIFY_SQL( q, exec("create table " + reltest2 + " (tid int not null primary key, title varchar(20))")); + QVERIFY_SQL( q, exec("insert into " + reltest2 + " values(1, 'herr')")); + QVERIFY_SQL( q, exec("insert into " + reltest2 + " values(2, 'mister')")); - QVERIFY_SQL( q, exec("create table " + qTableName("reltest3") + " (id int not null primary key, name varchar(20), city_key int)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest3") + " values(1, 'Gustav', 1)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest3") + " values(2, 'Heidi', 2)")); + QVERIFY_SQL( q, exec("create table " + reltest3 + " (id int not null primary key, name varchar(20), city_key int)")); + QVERIFY_SQL( q, exec("insert into " + reltest3 + " values(1, 'Gustav', 1)")); + QVERIFY_SQL( q, exec("insert into " + reltest3 + " values(2, 'Heidi', 2)")); - QVERIFY_SQL( q, exec("create table " + qTableName("reltest4") + " (id int not null primary key, name varchar(20))")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest4") + " values(1, 'Oslo')")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest4") + " values(2, 'Trondheim')")); + QVERIFY_SQL( q, exec("create table " + reltest4 + " (id int not null primary key, name varchar(20))")); + QVERIFY_SQL( q, exec("insert into " + reltest4 + " values(1, 'Oslo')")); + QVERIFY_SQL( q, exec("insert into " + reltest4 + " values(2, 'Trondheim')")); - QVERIFY_SQL( q, exec("create table " + qTableName("reltest5") + " (title varchar(20) not null primary key, abbrev varchar(20))")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest5") + " values('herr', 'Hr')")); - QVERIFY_SQL( q, exec("insert into " + qTableName("reltest5") + " values('mister', 'Mr')")); + QVERIFY_SQL( q, exec("create table " + reltest5 + " (title varchar(20) not null primary key, abbrev varchar(20))")); + QVERIFY_SQL( q, exec("insert into " + reltest5 + " values('herr', 'Hr')")); + QVERIFY_SQL( q, exec("insert into " + reltest5 + " values('mister', 'Mr')")); if (testWhiteSpaceNames(db.driverName())) { - QString reltest6 = db.driver()->escapeIdentifier(qTableName("rel test6"), QSqlDriver::TableName); + QString reltest6 = db.driver()->escapeIdentifier(qTableName("rel", __FILE__)+" test6", QSqlDriver::TableName); QVERIFY_SQL( q, exec("create table " + reltest6 + " (id int not null primary key, " + db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName) + " int, " + db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName) + " int)")); QVERIFY_SQL( q, exec("insert into " + reltest6 + " values(1, 1,9)")); QVERIFY_SQL( q, exec("insert into " + reltest6 + " values(2, 2,8)")); - QString reltest7 = db.driver()->escapeIdentifier(qTableName("rel test7"), QSqlDriver::TableName); + QString reltest7 = db.driver()->escapeIdentifier(qTableName("rel", __FILE__)+" test7", QSqlDriver::TableName); QVERIFY_SQL( q, exec("create table " + reltest7 + " (" + db.driver()->escapeIdentifier("city id", QSqlDriver::TableName) + " int not null primary key, " + db.driver()->escapeIdentifier("city name", QSqlDriver::FieldName) + " varchar(20))")); QVERIFY_SQL( q, exec("insert into " + reltest7 + " values(1, 'New York')")); QVERIFY_SQL( q, exec("insert into " + reltest7 + " values(2, 'Washington')")); @@ -173,19 +178,19 @@ void tst_QSqlRelationalTableModel::cleanupTestCase() void tst_QSqlRelationalTableModel::dropTestTables( QSqlDatabase db ) { QStringList tableNames; - tableNames << qTableName( "reltest1" ) - << qTableName( "reltest2" ) - << qTableName( "reltest3" ) - << qTableName( "reltest4" ) - << qTableName( "reltest5" ) - << qTableName( "rel test6" ) - << qTableName( "rel test7" ) - << qTableName("CASETEST1" ) - << qTableName("casetest1" ); + tableNames << reltest1 + << reltest2 + << reltest3 + << reltest4 + << reltest5 + << (qTableName( "rel", __FILE__)+" test6") + << (qTableName( "rel", __FILE__)+" test7") + << qTableName("CASETEST1", db.driver() ) + << qTableName("casetest1", db.driver() ); tst_Databases::safeDropTables( db, tableNames ); - db.exec("DROP SCHEMA "+qTableName("QTBUG_5373")+" CASCADE"); - db.exec("DROP SCHEMA "+qTableName("QTBUG_5373_s2")+" CASCADE"); + db.exec("DROP SCHEMA "+qTableName("QTBUG_5373", __FILE__)+" CASCADE"); + db.exec("DROP SCHEMA "+qTableName("QTBUG_5373_s2", __FILE__)+" CASCADE"); } void tst_QSqlRelationalTableModel::init() @@ -204,8 +209,8 @@ void tst_QSqlRelationalTableModel::data() QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QCOMPARE(model.columnCount(), 4); @@ -219,8 +224,8 @@ void tst_QSqlRelationalTableModel::data() //check data retrieval when relational key is a non-integer type //in this case a string QSqlRelationalTableModel model2(0,db); - model2.setTable(qTableName("reltest2")); - model2.setRelation(1, QSqlRelation(qTableName("reltest5"),"title","abbrev")); + model2.setTable(reltest2); + model2.setRelation(1, QSqlRelation(reltest5,"title","abbrev")); QVERIFY_SQL(model2, select()); QCOMPARE(model2.data(model2.index(0, 1)).toString(), QString("Hr")); @@ -237,9 +242,9 @@ void tst_QSqlRelationalTableModel::setData() { QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); + model.setTable(reltest1); model.setSort(0, Qt::AscendingOrder); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QVERIFY(model.setData(model.index(0, 1), QString("harry2"))); @@ -260,7 +265,7 @@ void tst_QSqlRelationalTableModel::setData() } { //verify values QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); + model.setTable(reltest1); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -269,7 +274,7 @@ void tst_QSqlRelationalTableModel::setData() QCOMPARE(model.data(model.index(3, 1)).toString(), QString("boris2")); QCOMPARE(model.data(model.index(3, 2)).toInt(), 1); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); QCOMPARE(model.data(model.index(3,2)).toString(), QString("herr")); @@ -279,10 +284,10 @@ void tst_QSqlRelationalTableModel::setData() //set the values using OnFieldChange strategy { QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); + model.setTable(reltest1); model.setEditStrategy(QSqlTableModel::OnFieldChange); model.setSort(0, Qt::AscendingOrder); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QVERIFY(model.setData(model.index(1,1), QString("trond2"))); @@ -293,14 +298,14 @@ void tst_QSqlRelationalTableModel::setData() } { //verify values QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); + model.setTable(reltest1); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(1, 1)).toString(), QString("trond2")); QCOMPARE(model.data(model.index(2, 2)).toInt(), 2); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(2, 2)).toString(), QString("mister")); } @@ -309,13 +314,13 @@ void tst_QSqlRelationalTableModel::setData() { QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); //sybase doesn't allow tables with the same alias used twice as col names //so don't set up an identical relation when using the tds driver if (!db.driverName().startsWith("QTDS")) - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(3, QSqlRelation(reltest2, "tid", "title")); model.setEditStrategy(QSqlTableModel::OnManualSubmit); model.setSort(0, Qt::AscendingOrder); @@ -336,7 +341,7 @@ void tst_QSqlRelationalTableModel::setData() } { //verify values QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); + model.setTable(reltest1); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -344,9 +349,9 @@ void tst_QSqlRelationalTableModel::setData() QCOMPARE(model.data(model.index(3, 2)).toInt(), 1); QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); if (!db.driverName().startsWith("QTDS")) - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(3, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); @@ -361,8 +366,8 @@ void tst_QSqlRelationalTableModel::setData() { QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest2")); - model.setRelation(1, QSqlRelation(qTableName("reltest5"), "title", "abbrev")); + model.setTable(reltest2); + model.setRelation(1, QSqlRelation(reltest5, "title", "abbrev")); model.setEditStrategy(QSqlTableModel::OnManualSubmit); QVERIFY_SQL(model, select()); @@ -385,9 +390,9 @@ void tst_QSqlRelationalTableModel::multipleRelation() QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); - model.setRelation(3, QSqlRelation(qTableName("reltest4"), "id", "name")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); + model.setRelation(3, QSqlRelation(reltest4, "id", "name")); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -407,8 +412,8 @@ void tst_QSqlRelationalTableModel::insertRecord() QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -449,8 +454,8 @@ void tst_QSqlRelationalTableModel::setRecord() QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -502,12 +507,12 @@ void tst_QSqlRelationalTableModel::insertWithStrategies() QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); model.setSort(0, Qt::AscendingOrder); if (!db.driverName().startsWith("QTDS")) - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(3, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(0,0)).toInt(), 1); @@ -608,8 +613,8 @@ void tst_QSqlRelationalTableModel::removeColumn() QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QVERIFY_SQL(model, removeColumn(3)); @@ -639,8 +644,8 @@ void tst_QSqlRelationalTableModel::filter() QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); model.setFilter("title = 'herr'"); QVERIFY_SQL(model, select()); @@ -657,10 +662,10 @@ void tst_QSqlRelationalTableModel::sort() QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); if (!db.driverName().startsWith("QTDS")) - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(3, QSqlRelation(reltest2, "tid", "title")); model.setSort(2, Qt::DescendingOrder); QVERIFY_SQL(model, select()); @@ -755,9 +760,9 @@ void tst_QSqlRelationalTableModel::revert() QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); - model.setRelation(3, QSqlRelation(qTableName("reltest4"), "id", "name")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); + model.setRelation(3, QSqlRelation(reltest4, "id", "name")); model.setSort(0, Qt::AscendingOrder); @@ -781,11 +786,11 @@ void tst_QSqlRelationalTableModel::clearDisplayValuesCache() QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); if (!db.driverName().startsWith("QTDS")) - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(3, QSqlRelation(reltest2, "tid", "title")); model.setSort(1, Qt::AscendingOrder); model.setEditStrategy(QSqlTableModel::OnManualSubmit); @@ -833,19 +838,19 @@ void tst_QSqlRelationalTableModel::insertRecordDuplicateFieldNames() CHECK_DATABASE(db); QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest3")); + model.setTable(reltest3); model.setEditStrategy(QSqlTableModel::OnManualSubmit); model.setSort(0, Qt::AscendingOrder); // Duplication of "name", used in both reltest3 and reltest4. - model.setRelation(2, QSqlRelation(qTableName("reltest4"), "id", "name")); + model.setRelation(2, QSqlRelation(reltest4, "id", "name")); QVERIFY_SQL(model, select()); if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { - QCOMPARE(model.record(1).value(qTableName("reltest4").append(QLatin1String("_name_2")).toUpper()).toString(), + QCOMPARE(model.record(1).value((reltest4+QLatin1String("_name_2")).toUpper()).toString(), QString("Trondheim")); } else { - QCOMPARE(model.record(1).value(qTableName("reltest4").append(QLatin1String("_name_2"))).toString(), + QCOMPARE(model.record(1).value((reltest4+QLatin1String("_name_2"))).toString(), QString("Trondheim")); } @@ -864,9 +869,9 @@ void tst_QSqlRelationalTableModel::insertRecordDuplicateFieldNames() // The duplicate field names is aliased because it's comes from the relation's display column. if(db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) - QCOMPARE(rec.fieldName(2), (qTableName("reltest4").append(QLatin1String("_name_2"))).toUpper()); + QCOMPARE(rec.fieldName(2), (reltest4+QLatin1String("_name_2")).toUpper()); else - QCOMPARE(rec.fieldName(2), qTableName("reltest4").append(QLatin1String("_name_2"))); + QCOMPARE(rec.fieldName(2), reltest4+QLatin1String("_name_2")); QVERIFY(model.insertRecord(-1, rec)); QCOMPARE(model.data(model.index(2, 2)).toString(), QString("Oslo")); @@ -881,8 +886,8 @@ void tst_QSqlRelationalTableModel::invalidData() CHECK_DATABASE(db); QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); //try set a non-existent relational key @@ -900,8 +905,8 @@ void tst_QSqlRelationalTableModel::relationModel() CHECK_DATABASE(db); QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QVERIFY(model.relationModel(0) == NULL); @@ -910,7 +915,7 @@ void tst_QSqlRelationalTableModel::relationModel() QVERIFY(model.relationModel(3) == NULL); QVERIFY(model.relationModel(4) == NULL); - model.setRelation(3, QSqlRelation(qTableName("reltest4"), "id", "name")); + model.setRelation(3, QSqlRelation(reltest4, "id", "name")); QVERIFY_SQL(model, select()); QVERIFY(model.relationModel(0) == NULL); @@ -981,7 +986,7 @@ void tst_QSqlRelationalTableModel::casing() QSqlRelationalTableModel model(0, db); model.setTable(qTableName("CASETEST1", db.driver()).toUpper()); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); @@ -997,15 +1002,15 @@ void tst_QSqlRelationalTableModel::escapedRelations() recreateTestTables(db); QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); + model.setTable(reltest1); //try with relation table name quoted if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { - model.setRelation(2, QSqlRelation(db.driver()->escapeIdentifier(qTableName("reltest2").toUpper(),QSqlDriver::TableName), + model.setRelation(2, QSqlRelation(db.driver()->escapeIdentifier(reltest2.toUpper(),QSqlDriver::TableName), "tid", "title")); } else { - model.setRelation(2, QSqlRelation(db.driver()->escapeIdentifier(qTableName("reltest2"),QSqlDriver::TableName), + model.setRelation(2, QSqlRelation(db.driver()->escapeIdentifier(reltest2,QSqlDriver::TableName), "tid", "title")); @@ -1018,11 +1023,11 @@ void tst_QSqlRelationalTableModel::escapedRelations() //try with index column quoted if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { - model.setRelation(2, QSqlRelation(qTableName("reltest2"), + model.setRelation(2, QSqlRelation(reltest2, db.driver()->escapeIdentifier("tid", QSqlDriver::FieldName).toUpper(), "title")); } else { - model.setRelation(2, QSqlRelation(qTableName("reltest2"), + model.setRelation(2, QSqlRelation(reltest2, db.driver()->escapeIdentifier("tid", QSqlDriver::FieldName), "title")); } @@ -1036,11 +1041,11 @@ void tst_QSqlRelationalTableModel::escapedRelations() if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { - model.setRelation(2, QSqlRelation(qTableName("reltest2"), + model.setRelation(2, QSqlRelation(reltest2, "tid", db.driver()->escapeIdentifier("title", QSqlDriver::FieldName).toUpper())); } else { - model.setRelation(2, QSqlRelation(qTableName("reltest2"), + model.setRelation(2, QSqlRelation(reltest2, "tid", db.driver()->escapeIdentifier("title", QSqlDriver::FieldName))); } @@ -1054,11 +1059,11 @@ void tst_QSqlRelationalTableModel::escapedRelations() //try with tablename and index and display columns quoted in the relation if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { - model.setRelation(2, QSqlRelation(qTableName("reltest2"), + model.setRelation(2, QSqlRelation(reltest2, "tid", db.driver()->escapeIdentifier("title", QSqlDriver::FieldName).toUpper())); } else { - model.setRelation(2, QSqlRelation(qTableName("reltest2"), + model.setRelation(2, QSqlRelation(reltest2, "tid", db.driver()->escapeIdentifier("title", QSqlDriver::FieldName))); } @@ -1080,12 +1085,12 @@ void tst_QSqlRelationalTableModel::escapedTableName() QSqlRelationalTableModel model(0, db); if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { - model.setTable(db.driver()->escapeIdentifier(qTableName("reltest1").toUpper(), QSqlDriver::TableName)); + model.setTable(db.driver()->escapeIdentifier(reltest1.toUpper(), QSqlDriver::TableName)); } else { - model.setTable(db.driver()->escapeIdentifier(qTableName("reltest1"), QSqlDriver::TableName)); + model.setTable(db.driver()->escapeIdentifier(reltest1, QSqlDriver::TableName)); } model.setSort(0, Qt::AscendingOrder); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QVERIFY(model.setData(model.index(0, 1), QString("harry2"))); @@ -1106,7 +1111,7 @@ void tst_QSqlRelationalTableModel::escapedTableName() } { //verify values QSqlRelationalTableModel model(0, db); - model.setTable(qTableName("reltest1")); + model.setTable(reltest1); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -1115,7 +1120,7 @@ void tst_QSqlRelationalTableModel::escapedTableName() QCOMPARE(model.data(model.index(3, 1)).toString(), QString("boris2")); QCOMPARE(model.data(model.index(3, 2)).toInt(), 1); - model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); QCOMPARE(model.data(model.index(3,2)).toString(), QString("herr")); @@ -1132,9 +1137,9 @@ void tst_QSqlRelationalTableModel::whiteSpaceInIdentifiers() if (!testWhiteSpaceNames(db.driverName())) QSKIP("White space test irrelevant for driver", SkipAll); QSqlRelationalTableModel model(0, db); - model.setTable(db.driver()->escapeIdentifier(qTableName("rel test6"), QSqlDriver::TableName)); + model.setTable(db.driver()->escapeIdentifier(qTableName("rel", __FILE__)+" test6", QSqlDriver::TableName)); model.setSort(0, Qt::DescendingOrder); - model.setRelation(1, QSqlRelation(db.driver()->escapeIdentifier(qTableName("rel test7"), QSqlDriver::TableName), + model.setRelation(1, QSqlRelation(db.driver()->escapeIdentifier(qTableName("rel", __FILE__)+" test7", QSqlDriver::TableName), db.driver()->escapeIdentifier("city id", QSqlDriver::FieldName), db.driver()->escapeIdentifier("city name", QSqlDriver::FieldName))); QVERIFY_SQL(model, select()); @@ -1210,13 +1215,13 @@ void tst_QSqlRelationalTableModel::psqlSchemaTest() } QSqlRelationalTableModel model(0, db); QSqlQuery q(db); - QVERIFY_SQL(q, exec("create schema "+qTableName("QTBUG_5373"))); - QVERIFY_SQL(q, exec("create schema "+qTableName("QTBUG_5373_s2"))); - QVERIFY_SQL(q, exec("create table "+qTableName("QTBUG_5373")+"."+qTableName("document")+"(document_id int primary key, relatingid int, userid int)")); - QVERIFY_SQL(q, exec("create table "+qTableName("QTBUG_5373_s2")+"."+qTableName("user")+"(userid int primary key, username char(40))")); - model.setTable(qTableName("QTBUG_5373")+"."+qTableName("document")); - model.setRelation(1, QSqlRelation(qTableName("QTBUG_5373_s2")+"."+qTableName("user"), "userid", "username")); - model.setRelation(2, QSqlRelation(qTableName("QTBUG_5373_s2")+"."+qTableName("user"), "userid", "username")); + QVERIFY_SQL(q, exec("create schema "+qTableName("QTBUG_5373", __FILE__))); + QVERIFY_SQL(q, exec("create schema "+qTableName("QTBUG_5373_s2", __FILE__))); + QVERIFY_SQL(q, exec("create table "+qTableName("QTBUG_5373", __FILE__)+"."+qTableName("document", __FILE__)+"(document_id int primary key, relatingid int, userid int)")); + QVERIFY_SQL(q, exec("create table "+qTableName("QTBUG_5373_s2", __FILE__)+"."+qTableName("user", __FILE__)+"(userid int primary key, username char(40))")); + model.setTable(qTableName("QTBUG_5373", __FILE__)+"."+qTableName("document", __FILE__)); + model.setRelation(1, QSqlRelation(qTableName("QTBUG_5373_s2", __FILE__)+"."+qTableName("user", __FILE__), "userid", "username")); + model.setRelation(2, QSqlRelation(qTableName("QTBUG_5373_s2", __FILE__)+"."+qTableName("user", __FILE__), "userid", "username")); QVERIFY_SQL(model, select()); } diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp index b295838..8a084bb 100644 --- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp @@ -44,6 +44,10 @@ #include "../qsqldatabase/tst_databases.h" #include +const QString test(qTableName("test", __FILE__)), + test2(qTableName("test2", __FILE__)), + test3(qTableName("test3", __FILE__)); + //TESTED_CLASS= //TESTED_FILES= @@ -147,20 +151,20 @@ void tst_QSqlTableModel::dropTestTables() QVERIFY_SQL( q, exec("set client_min_messages='warning'")); QStringList tableNames; - tableNames << qTableName("test") - << qTableName("test2") - << qTableName("test3") - << qTableName("test4") - << qTableName("emptytable") - << qTableName("bigtable") - << qTableName("foo"); + tableNames << test + << test2 + << test3 + << qTableName("test4", __FILE__) + << qTableName("emptytable", __FILE__) + << qTableName("bigtable", __FILE__) + << qTableName("foo", __FILE__); if (testWhiteSpaceNames(db.driverName())) tableNames << qTableName("qtestw hitespace", db.driver()); tst_Databases::safeDropTables(db, tableNames); if (db.driverName().startsWith("QPSQL")) { - q.exec("DROP SCHEMA " + qTableName("testschema") + " CASCADE"); + q.exec("DROP SCHEMA " + qTableName("testschema", __FILE__) + " CASCADE"); } } } @@ -171,15 +175,15 @@ void tst_QSqlTableModel::createTestTables() QSqlDatabase db = QSqlDatabase::database(dbs.dbNames.at(i)); QSqlQuery q(db); - QVERIFY_SQL( q, exec("create table " + qTableName("test") + "(id int, name varchar(20), title int)")); + QVERIFY_SQL( q, exec("create table " + test + "(id int, name varchar(20), title int)")); - QVERIFY_SQL( q, exec("create table " + qTableName("test2") + "(id int, title varchar(20))")); + QVERIFY_SQL( q, exec("create table " + test2 + "(id int, title varchar(20))")); - QVERIFY_SQL( q, exec("create table " + qTableName("test3") + "(id int, random varchar(20), randomtwo varchar(20))")); + QVERIFY_SQL( q, exec("create table " + test3 + "(id int, random varchar(20), randomtwo varchar(20))")); - QVERIFY_SQL( q, exec("create table " + qTableName("test4") + "(column1 varchar(50), column2 varchar(50), column3 varchar(50))")); + QVERIFY_SQL( q, exec("create table " + qTableName("test4", __FILE__) + "(column1 varchar(50), column2 varchar(50), column3 varchar(50))")); - QVERIFY_SQL( q, exec("create table " + qTableName("emptytable") + "(id int)")); + QVERIFY_SQL( q, exec("create table " + qTableName("emptytable", __FILE__) + "(id int)")); if (testWhiteSpaceNames(db.driverName())) { QString qry = "create table " + qTableName("qtestw hitespace", db.driver()) + " ("+ db.driver()->escapeIdentifier("a field", QSqlDriver::FieldName) + " int)"; @@ -194,18 +198,18 @@ void tst_QSqlTableModel::repopulateTestTables() QSqlDatabase db = QSqlDatabase::database(dbs.dbNames.at(i)); QSqlQuery q(db); - q.exec("delete from " + qTableName("test")); - QVERIFY_SQL( q, exec("insert into " + qTableName("test") + " values(1, 'harry', 1)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("test") + " values(2, 'trond', 2)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("test") + " values(3, 'vohi', 3)")); + q.exec("delete from " + test); + QVERIFY_SQL( q, exec("insert into " + test + " values(1, 'harry', 1)")); + QVERIFY_SQL( q, exec("insert into " + test + " values(2, 'trond', 2)")); + QVERIFY_SQL( q, exec("insert into " + test + " values(3, 'vohi', 3)")); - q.exec("delete from " + qTableName("test2")); - QVERIFY_SQL( q, exec("insert into " + qTableName("test2") + " values(1, 'herr')")); - QVERIFY_SQL( q, exec("insert into " + qTableName("test2") + " values(2, 'mister')")); + q.exec("delete from " + test2); + QVERIFY_SQL( q, exec("insert into " + test2 + " values(1, 'herr')")); + QVERIFY_SQL( q, exec("insert into " + test2 + " values(2, 'mister')")); - q.exec("delete from " + qTableName("test3")); - QVERIFY_SQL( q, exec("insert into " + qTableName("test3") + " values(1, 'foo', 'bar')")); - QVERIFY_SQL( q, exec("insert into " + qTableName("test3") + " values(2, 'baz', 'joe')")); + q.exec("delete from " + test3); + QVERIFY_SQL( q, exec("insert into " + test3 + " values(1, 'foo', 'bar')")); + QVERIFY_SQL( q, exec("insert into " + test3 + " values(2, 'baz', 'joe')")); } } @@ -253,7 +257,7 @@ void tst_QSqlTableModel::select() CHECK_DATABASE(db); QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -294,7 +298,7 @@ void tst_QSqlTableModel::setRecord() QSqlTableModel model(0, db); model.setEditStrategy((QSqlTableModel::EditStrategy)submitpolicy); - model.setTable(qTableName("test3")); + model.setTable(test3); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -336,7 +340,7 @@ void tst_QSqlTableModel::insertRow() QSqlTableModel model(0, db); model.setEditStrategy(QSqlTableModel::OnRowChange); - model.setTable(qTableName("test")); + model.setTable(test); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -361,7 +365,7 @@ void tst_QSqlTableModel::insertRecord() QSqlTableModel model(0, db); model.setEditStrategy(QSqlTableModel::OnManualSubmit); - model.setTable(qTableName("test")); + model.setTable(test); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -394,7 +398,7 @@ void tst_QSqlTableModel::insertMultiRecords() QSqlTableModel model(0, db); model.setEditStrategy(QSqlTableModel::OnManualSubmit); - model.setTable(qTableName("test")); + model.setTable(test); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -421,7 +425,7 @@ void tst_QSqlTableModel::insertMultiRecords() QVERIFY(model.submitAll()); model.clear(); - model.setTable(qTableName("test")); + model.setTable(test); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -442,7 +446,7 @@ void tst_QSqlTableModel::submitAll() CHECK_DATABASE(db); QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); model.setSort(0, Qt::AscendingOrder); model.setEditStrategy(QSqlTableModel::OnManualSubmit); QVERIFY_SQL(model, select()); @@ -477,7 +481,7 @@ void tst_QSqlTableModel::removeRow() CHECK_DATABASE(db); QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); model.setSort(0, Qt::AscendingOrder); model.setEditStrategy(QSqlTableModel::OnManualSubmit); QVERIFY_SQL(model, select()); @@ -502,7 +506,7 @@ void tst_QSqlTableModel::removeRow() recreateTestTables(); - model.setTable(qTableName("test")); + model.setTable(test); model.setEditStrategy(QSqlTableModel::OnRowChange); QVERIFY_SQL(model, select()); QCOMPARE(model.rowCount(), 3); @@ -523,7 +527,7 @@ void tst_QSqlTableModel::removeRows() CHECK_DATABASE(db); QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); model.setSort(0, Qt::AscendingOrder); model.setEditStrategy(QSqlTableModel::OnFieldChange); QVERIFY_SQL(model, select()); @@ -539,7 +543,7 @@ void tst_QSqlTableModel::removeRows() model.clear(); recreateTestTables(); - model.setTable(qTableName("test")); + model.setTable(test); model.setEditStrategy(QSqlTableModel::OnManualSubmit); QVERIFY_SQL(model, select()); QCOMPARE(model.rowCount(), 3); @@ -574,7 +578,7 @@ void tst_QSqlTableModel::removeInsertedRow() for (int i = 0; i <= 1; ++i) { QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); model.setSort(0, Qt::AscendingOrder); model.setEditStrategy(i == 0 @@ -607,7 +611,7 @@ void tst_QSqlTableModel::emptyTable() QCOMPARE(model.rowCount(), 0); QCOMPARE(model.columnCount(), 0); - model.setTable(qTableName("emptytable")); + model.setTable(qTableName("emptytable", __FILE__)); QCOMPARE(model.rowCount(), 0); QCOMPARE(model.columnCount(), 1); @@ -623,9 +627,9 @@ void tst_QSqlTableModel::tablesAndSchemas() CHECK_DATABASE(db); QSqlQuery q(db); - q.exec("DROP SCHEMA " + qTableName("testschema") + " CASCADE"); - QVERIFY_SQL( q, exec("create schema " + qTableName("testschema"))); - QString tableName = qTableName("testschema") + '.' + qTableName("testtable"); + q.exec("DROP SCHEMA " + qTableName("testschema", __FILE__) + " CASCADE"); + QVERIFY_SQL( q, exec("create schema " + qTableName("testschema", __FILE__))); + QString tableName = qTableName("testschema", __FILE__) + '.' + qTableName("testtable", __FILE__); QVERIFY_SQL( q, exec("create table " + tableName + "(id int)")); QVERIFY_SQL( q, exec("insert into " + tableName + " values(1)")); QVERIFY_SQL( q, exec("insert into " + tableName + " values(2)")); @@ -664,10 +668,10 @@ void tst_QSqlTableModel::primaryKeyOrder() if(tst_Databases::isPostgreSQL(db)) QVERIFY_SQL( q, exec("set client_min_messages='warning'")); - QVERIFY_SQL( q, exec("create table "+qTableName("foo")+"(a varchar(20), id int not null primary key, b varchar(20))")); + QVERIFY_SQL( q, exec("create table "+qTableName("foo", __FILE__)+"(a varchar(20), id int not null primary key, b varchar(20))")); QSqlTableModel model(0, db); - model.setTable(qTableName("foo")); + model.setTable(qTableName("foo", __FILE__)); QSqlIndex pk = model.primaryKey(); QCOMPARE(pk.count(), 1); @@ -693,7 +697,7 @@ void tst_QSqlTableModel::setInvalidFilter() // set an invalid filter, make sure it fails QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); model.setFilter("blahfahsel"); QCOMPARE(model.filter(), QString("blahfahsel")); @@ -711,7 +715,7 @@ void tst_QSqlTableModel::setFilter() CHECK_DATABASE(db); QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); model.setFilter("id = 1"); QCOMPARE(model.filter(), QString("id = 1")); QVERIFY_SQL(model, select()); @@ -762,12 +766,13 @@ void tst_QSqlTableModel::sqlite_bigTable() QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); + const QString bigtable(qTableName("bigtable", __FILE__)); bool hasTransactions = db.driver()->hasFeature(QSqlDriver::Transactions); if (hasTransactions) QVERIFY(db.transaction()); QSqlQuery q(db); - QVERIFY_SQL( q, exec("create table "+qTableName("bigtable")+"(id int primary key, name varchar)")); - QVERIFY_SQL( q, prepare("insert into "+qTableName("bigtable")+"(id, name) values (?, ?)")); + QVERIFY_SQL( q, exec("create table "+bigtable+"(id int primary key, name varchar)")); + QVERIFY_SQL( q, prepare("insert into "+bigtable+"(id, name) values (?, ?)")); QTime startTime; startTime.start(); for (int i = 0; i < 10000; ++i) { @@ -781,7 +786,7 @@ void tst_QSqlTableModel::sqlite_bigTable() if (hasTransactions) QVERIFY(db.commit()); QSqlTableModel model(0, db); - model.setTable(qTableName("bigtable")); + model.setTable(bigtable); QVERIFY_SQL(model, select()); QSqlRecord rec = model.record(); @@ -801,7 +806,7 @@ void tst_QSqlTableModel::insertRecordBeforeSelect() CHECK_DATABASE(db); QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); QCOMPARE(model.lastError().type(), QSqlError::NoError); QSqlRecord buffer = model.record(); @@ -820,7 +825,7 @@ void tst_QSqlTableModel::insertRecordBeforeSelect() QCOMPARE(model.rowCount(), 0); QSqlTableModel model2(0, db); - model2.setTable(qTableName("test")); + model2.setTable(test); QVERIFY_SQL(model2, select()); QCOMPARE(model2.rowCount(), rowCount); } @@ -838,7 +843,7 @@ void tst_QSqlTableModel::submitAllOnInvalidTable() // setTable returns a void, so the error can only be caught by // manually checking lastError(). ### Qt5: This should be changed! - model.setTable(qTableName("invalidTable")); + model.setTable(qTableName("invalidTable", __FILE__)); QCOMPARE(model.lastError().type(), QSqlError::StatementError); // This will give us an empty record which is expected behavior @@ -866,7 +871,7 @@ void tst_QSqlTableModel::insertRecordsInLoop() CHECK_DATABASE(db); QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); model.setEditStrategy(QSqlTableModel::OnManualSubmit); model.select(); @@ -952,7 +957,7 @@ void tst_QSqlTableModel::tableModifyWithBlank() CHECK_DATABASE(db); QSqlTableModel model(0, db); - model.setTable(qTableName("test4")); + model.setTable(qTableName("test4", __FILE__)); model.select(); //generate a time stamp for the test. Add one second to the current time to make sure @@ -1008,7 +1013,7 @@ void tst_QSqlTableModel::removeColumnAndRow() CHECK_DATABASE(db); QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); model.setEditStrategy(QSqlTableModel::OnManualSubmit); QVERIFY_SQL(model, select()); QCOMPARE(model.rowCount(), 3); @@ -1023,7 +1028,7 @@ void tst_QSqlTableModel::removeColumnAndRow() // check with another table because the model has been modified // but not the sql table QSqlTableModel model2(0, db); - model2.setTable(qTableName("test")); + model2.setTable(test); QVERIFY_SQL(model2, select()); QCOMPARE(model2.rowCount(), 2); QCOMPARE(model2.columnCount(), 3); @@ -1036,11 +1041,11 @@ void tst_QSqlTableModel::insertBeforeDelete() CHECK_DATABASE(db); QSqlQuery q(db); - QVERIFY_SQL( q, exec("insert into " + qTableName("test") + " values(9, 'andrew', 9)")); - QVERIFY_SQL( q, exec("insert into " + qTableName("test") + " values(10, 'justin', 10)")); + QVERIFY_SQL( q, exec("insert into " + test + " values(9, 'andrew', 9)")); + QVERIFY_SQL( q, exec("insert into " + test + " values(10, 'justin', 10)")); QSqlTableModel model(0, db); - model.setTable(qTableName("test")); + model.setTable(test); model.setEditStrategy(QSqlTableModel::OnManualSubmit); QVERIFY_SQL(model, select()); diff --git a/tests/auto/qsqlthread/tst_qsqlthread.cpp b/tests/auto/qsqlthread/tst_qsqlthread.cpp index 632586a28..971766b 100644 --- a/tests/auto/qsqlthread/tst_qsqlthread.cpp +++ b/tests/auto/qsqlthread/tst_qsqlthread.cpp @@ -53,6 +53,7 @@ #include #endif +const QString qtest(qTableName("qtest", __FILE__)); // set this define if Oracle is built with threading support //#define QOCI_THREADED @@ -115,7 +116,7 @@ public: QVERIFY_SQL(db, open()); int sum = 0; - QSqlQuery q("select id from " + qTableName("test"), db); + QSqlQuery q("select id from " + qtest, db); QVERIFY_SQL(q, isActive()); while (q.next()) sum += q.value(0).toInt(); @@ -150,7 +151,7 @@ public: QSqlDatabase db = QSqlDatabase::cloneDatabase(sourceDb, dbName); QVERIFY_SQL(db, open()); QSqlQuery q(db); - QVERIFY_SQL(q, prepare("insert into " + qTableName("test") + " values (?, ?, ?)")); + QVERIFY_SQL(q, prepare("insert into " + qtest + " values (?, ?, ?)")); int id = 10; for (int i = 0; i < ProdConIterations; ++i) { q.bindValue(0, ++id); @@ -187,10 +188,10 @@ public: QSqlDatabase db = QSqlDatabase::cloneDatabase(sourceDb, dbName); QVERIFY_SQL(db, open()); QSqlQuery q1(db), q2(db); - QVERIFY_SQL(q2, prepare("delete from " + qTableName("test") + " where id = :id")); + QVERIFY_SQL(q2, prepare("delete from " + qtest + " where id = :id")); for (int i = 0; i < ProdConIterations; ++i) { - QVERIFY_SQL(q1, exec("select max(id) from " + qTableName("test"))); + QVERIFY_SQL(q1, exec("select max(id) from " + qtest)); q1.first(); q2.bindValue("id", q1.value(0)); q1.clear(); @@ -231,7 +232,7 @@ public: // Executes a Query for reading, iterates over the first 4 results QSqlQuery q(sourceDb); for (int j = 0; j < ProdConIterations; ++j) { - QVERIFY_SQL(q, exec("select id,name from " + qTableName("test") + " order by id")); + QVERIFY_SQL(q, exec("select id,name from " + qtest + " order by id")); for (int i = 1; i < 4; ++i) { QVERIFY_SQL(q, next()); QCOMPARE(q.value(0).toInt(), i); @@ -242,7 +243,7 @@ public: // Executes a query for writing (appends a new row) QSqlQuery q(sourceDb); for (int j = 0; j < ProdConIterations; ++j) { - QVERIFY_SQL(q, exec(QString("insert into " + qTableName("test") + QVERIFY_SQL(q, exec(QString("insert into " + qtest + " (id, name) values(%1, '%2')") .arg(counter.fetchAndAddRelaxed(1)).arg("Robert"))); } @@ -250,7 +251,7 @@ public: case PreparedReading: { // Prepares a query for reading and iterates over the results QSqlQuery q(sourceDb); - QVERIFY_SQL(q, prepare("select id, name from " + qTableName("test") + " where id = ?")); + QVERIFY_SQL(q, prepare("select id, name from " + qtest + " where id = ?")); for (int j = 0; j < ProdConIterations; ++j) { q.addBindValue(j % 3 + 1); QVERIFY_SQL(q, exec()); @@ -260,7 +261,7 @@ public: break; } case PreparedWriting: { QSqlQuery q(sourceDb); - QVERIFY_SQL(q, prepare("insert into " + qTableName("test") + " (id, name) " + QVERIFY_SQL(q, prepare("insert into " + qtest + " (id, name) " "values(?, ?)")); for (int i = 0; i < ProdConIterations; ++i) { q.addBindValue(counter.fetchAndAddRelaxed(1)); @@ -302,7 +303,7 @@ void tst_QSqlThread::dropTestTables() QSqlDatabase db = QSqlDatabase::database(dbs.dbNames.at(i)); QSqlQuery q(db); - tst_Databases::safeDropTables(db, QStringList() << qTableName("test") << qTableName("test2") << qTableName("emptytable")); + tst_Databases::safeDropTables(db, QStringList() << qtest << qTableName("qtest2", __FILE__) << qTableName("emptytable", __FILE__)); } } @@ -312,13 +313,13 @@ void tst_QSqlThread::createTestTables() QSqlDatabase db = QSqlDatabase::database(dbs.dbNames.at(i)); QSqlQuery q(db); - QVERIFY_SQL(q, exec("create table " + qTableName("test") + QVERIFY_SQL(q, exec("create table " + qtest + "(id int NOT NULL primary key, name varchar(20), title int)")); - QVERIFY_SQL(q, exec("create table " + qTableName("test2") + QVERIFY_SQL(q, exec("create table " + qTableName("qtest2", __FILE__) + "(id int NOT NULL primary key, title varchar(20))")); - QVERIFY_SQL(q, exec("create table " + qTableName("emptytable") + QVERIFY_SQL(q, exec("create table " + qTableName("emptytable", __FILE__) + "(id int NOT NULL primary key)")); } } @@ -329,14 +330,14 @@ void tst_QSqlThread::repopulateTestTables() QSqlDatabase db = QSqlDatabase::database(dbs.dbNames.at(i)); QSqlQuery q(db); - QVERIFY_SQL(q, exec("delete from " + qTableName("test"))); - QVERIFY_SQL(q, exec("insert into " + qTableName("test") + " values(1, 'harry', 1)")); - QVERIFY_SQL(q, exec("insert into " + qTableName("test") + " values(2, 'trond', 2)")); - QVERIFY_SQL(q, exec("insert into " + qTableName("test") + " values(3, 'vohi', 3)")); + QVERIFY_SQL(q, exec("delete from " + qtest)); + QVERIFY_SQL(q, exec("insert into " + qtest + " values(1, 'harry', 1)")); + QVERIFY_SQL(q, exec("insert into " + qtest + " values(2, 'trond', 2)")); + QVERIFY_SQL(q, exec("insert into " + qtest + " values(3, 'vohi', 3)")); - QVERIFY_SQL(q, exec("delete from " + qTableName("test2"))); - QVERIFY_SQL(q, exec("insert into " + qTableName("test2") + " values(1, 'herr')")); - QVERIFY_SQL(q, exec("insert into " + qTableName("test2") + " values(2, 'mister')")); + QVERIFY_SQL(q, exec("delete from " + qTableName("test2", __FILE__))); + QVERIFY_SQL(q, exec("insert into " + qTableName("test2", __FILE__) + " values(1, 'herr')")); + QVERIFY_SQL(q, exec("insert into " + qTableName("test2", __FILE__) + " values(2, 'mister')")); } } -- cgit v0.12