diff options
-rw-r--r-- | tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp | 17 | ||||
-rw-r--r-- | tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qitemmodel/qitemmodel.pro | 3 | ||||
-rw-r--r-- | tests/auto/qsqldatabase/tst_databases.h | 14 | ||||
-rw-r--r-- | tests/auto/qsqldatabase/tst_qsqldatabase.cpp | 8 | ||||
-rw-r--r-- | tests/auto/qsqldriver/tst_qsqldriver.cpp | 8 | ||||
-rw-r--r-- | tests/auto/qsqlquery/tst_qsqlquery.cpp | 65 | ||||
-rw-r--r-- | tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp | 48 | ||||
-rw-r--r-- | tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp | 2 |
9 files changed, 62 insertions, 105 deletions
diff --git a/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp b/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp index a2f4a66..2d89639 100644 --- a/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp +++ b/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp @@ -132,6 +132,11 @@ void tst_Q3SqlCursor::createTestTables( QSqlDatabase db ) if ( !db.isValid() ) return; QSqlQuery q( db ); + + if (tst_Databases::isSqlServer(db)) { + QVERIFY_SQL(q, exec("SET ANSI_DEFAULTS ON")); + } + // 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," @@ -753,12 +758,12 @@ void tst_Q3SqlCursor::insertFieldNameContainsWS() { QString tableName = qTableName("qtestws"); QSqlQuery q(db); - q.exec(QString("DROP TABLE %1").arg(tableName)); + tst_Databases::safeDropTable(db, tableName); QString query = QString("CREATE TABLE %1 (id int, \"first Name\" varchar(20), " - "lastName varchar(20))"); - QVERIFY_SQL(q, exec(query.arg(tableName))); + "lastName varchar(20))").arg(tableName); + QVERIFY_SQL(q, exec(query)); - Q3SqlCursor cur(QString("%1").arg(tableName), true, db); + Q3SqlCursor cur(tableName, true, db); cur.select(); QSqlRecord *r = cur.primeInsert(); @@ -774,8 +779,8 @@ void tst_Q3SqlCursor::insertFieldNameContainsWS() { QVERIFY(cur.value(0) == 1); QCOMPARE(cur.value(1).toString(), QString("Kong")); QCOMPARE(cur.value(2).toString(), QString("Harald")); - - q.exec(QString("DROP TABLE %1").arg(tableName)); + + tst_Databases::safeDropTable(db, tableName); } diff --git a/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp b/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp index d026cbf..ec1f805 100644 --- a/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp +++ b/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp @@ -114,7 +114,7 @@ void tst_Q3SqlSelectCursor::createTestTables( QSqlDatabase db ) void tst_Q3SqlSelectCursor::dropTestTables( QSqlDatabase db ) { - tst_Databases::safeDropTables( db, QStringList() << qTableName( "qtest" ) ); + tst_Databases::safeDropTable( db, qTableName( "qtest" ) ); } void tst_Q3SqlSelectCursor::populateTestTables( QSqlDatabase db ) diff --git a/tests/auto/qitemmodel/qitemmodel.pro b/tests/auto/qitemmodel/qitemmodel.pro index c51f4c7..38c615b 100644 --- a/tests/auto/qitemmodel/qitemmodel.pro +++ b/tests/auto/qitemmodel/qitemmodel.pro @@ -1,6 +1,5 @@ -CONFIG += qtestlib +load(qttest_p4) SOURCES += tst_qitemmodel.cpp -TARGET = tst_qitemmodel QT += sql diff --git a/tests/auto/qsqldatabase/tst_databases.h b/tests/auto/qsqldatabase/tst_databases.h index a490a2f..b81182a 100644 --- a/tests/auto/qsqldatabase/tst_databases.h +++ b/tests/auto/qsqldatabase/tst_databases.h @@ -238,8 +238,8 @@ public: // addDb( "QIBASE", "/opt/firebird/databases/testdb.fdb", "testuser", "Ee4Gabf6_", "firebird2-nokia.trolltech.com.au" ); // Firebird 2.1.1 // use in-memory database to prevent local files - addDb("QSQLITE", ":memory:"); -// addDb( "QSQLITE", QDir::toNativeSeparators(QDir::tempPath()+"/foo.db") ); +// addDb("QSQLITE", ":memory:"); + addDb( "QSQLITE", QDir::toNativeSeparators(QDir::tempPath()+"/foo.db") ); // addDb( "QSQLITE2", QDir::toNativeSeparators(QDir::tempPath()+"/foo2.db") ); // 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", "" ); @@ -333,6 +333,11 @@ public: } } + static void safeDropTable( QSqlDatabase db, const QString& tableName ) + { + safeDropTables(db, QStringList() << tableName); + } + static void safeDropViews( QSqlDatabase db, const QStringList &viewNames ) { if ( isMSAccess( db ) ) // Access is sooo stupid. @@ -354,6 +359,11 @@ public: } } + static void safeDropView( QSqlDatabase db, const QString& tableName ) + { + safeDropViews(db, QStringList() << tableName); + } + // returns the type name of the blob datatype for the database db. // blobSize is only used if the db doesn't have a generic blob type static QString blobTypeName( QSqlDatabase db, int blobSize = 10000 ) diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp index cce4602..f697488 100644 --- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp @@ -249,7 +249,7 @@ struct FieldDef { // excluding the primary key field static int createFieldTable(const FieldDef fieldDefs[], QSqlDatabase db) { - tst_Databases::safeDropTables(db, QStringList() << qTableName("qtestfields")); + tst_Databases::safeDropTable(db, qTableName("qtestfields")); QSqlQuery q(db); // construct a create table statement consisting of all fieldtypes QString qs = "create table " + qTableName("qtestfields"); @@ -357,6 +357,7 @@ void tst_QSqlDatabase::dropTestTables(QSqlDatabase db) tableNames << (qTableName("qtest") + " test"); tst_Databases::safeDropTables(db, tableNames); + tst_Databases::safeDropView(db, qTableName("qtest_view")); } void tst_QSqlDatabase::populateTestTables(QSqlDatabase db) @@ -540,11 +541,6 @@ void tst_QSqlDatabase::tables() QVERIFY(tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive)); QVERIFY(tables.contains(qTableName("qtest"), Qt::CaseInsensitive)); - if (tst_Databases::isMSAccess(db)) - QSqlQuery("drop table " + qTableName("qtest_view"), db); - else - QSqlQuery("drop view " + qTableName("qtest_view"), db); - if (db.driverName().startsWith("QPSQL")) { QVERIFY(tables.contains(qTableName("qtest") + " test")); } diff --git a/tests/auto/qsqldriver/tst_qsqldriver.cpp b/tests/auto/qsqldriver/tst_qsqldriver.cpp index bbd7483..d8f7747 100644 --- a/tests/auto/qsqldriver/tst_qsqldriver.cpp +++ b/tests/auto/qsqldriver/tst_qsqldriver.cpp @@ -85,9 +85,7 @@ void tst_QSqlDriver::recreateTestTables(QSqlDatabase db) { QSqlQuery q(db); - QStringList tableNames; - tableNames << qTableName( "relTEST1" ); - tst_Databases::safeDropTables( db, tableNames ); + tst_Databases::safeDropTable( db, qTableName( "relTEST1" ) ); QVERIFY_SQL( q, exec("create table " + qTableName("relTEST1") + " (id int not null primary key, name varchar(20), title_key int, another_title_key int)")); @@ -105,11 +103,9 @@ void tst_QSqlDriver::initTestCase() void tst_QSqlDriver::cleanupTestCase() { - QStringList tableNames; - tableNames << qTableName( "relTEST1" ); foreach (const QString &dbName, dbs.dbNames) { QSqlDatabase db = QSqlDatabase::database(dbName); - tst_Databases::safeDropTables( db, tableNames ); + tst_Databases::safeDropTable( db, qTableName( "relTEST1" ) ); } dbs.close(); } diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 825db6c..9604fa8 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -289,7 +289,8 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) << qTableName( "bindtest" ) << qTableName( "more_results" ) << qTableName( "blobstest" ) - << qTableName( "oraRowId" ); + << qTableName( "oraRowId" ) + << qTableName( "qtest_batch" ); if ( db.driverName().startsWith("QSQLITE") ) tablenames << qTableName( "record_sqlite" ); @@ -303,6 +304,7 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) tablenames << qTableName( "Planet" ); #endif tablenames << qTableName( "task_250026" ); + tablenames << qTableName( "task_234422" ); tst_Databases::safeDropTables( db, tablenames ); } @@ -1902,71 +1904,48 @@ void tst_QSqlQuery::batchExec() QSKIP( "Database can't do BatchOperations", SkipSingle ); QSqlQuery q( db ); + QString tableName = qTableName( "qtest_batch" ); - q.exec( "drop table " + qTableName( "qtest_batch" ) ); - - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_batch" ) + " (id int, name varchar(20), dt date, num numeric(8, 4))" ) ); - - QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_batch" ) + " (id, name, dt, num) values (?, ?, ?, ?)" ) ); + 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 (?, ?, ?, ?)" ) ); QVariantList intCol; - intCol << 1 << 2 << QVariant( QVariant::Int ); QVariantList charCol; - charCol << QLatin1String( "harald" ) << QLatin1String( "boris" ) << QVariant( QVariant::String ); QVariantList dateCol; - QDateTime dt = QDateTime( QDate::currentDate(), QTime( 1, 2, 3 ) ); - dateCol << dt << dt.addDays( -1 ) << QVariant( QVariant::DateTime ); QVariantList numCol; - numCol << 2.3 << 3.4 << QVariant( QVariant::Double ); q.addBindValue( intCol ); - q.addBindValue( charCol ); - q.addBindValue( dateCol ); - q.addBindValue( numCol ); QVERIFY_SQL( q, execBatch() ); - - QVERIFY_SQL( q, exec( "select id, name, dt, num from " + qTableName( "qtest_batch" ) + " order by id" ) ); + QVERIFY_SQL( q, exec( "select id, name, dt, num from " + tableName + " order by id" ) ); QVERIFY( q.next() ); - QCOMPARE( q.value( 0 ).toInt(), 1 ); - QCOMPARE( q.value( 1 ).toString(), QString( "harald" ) ); - QCOMPARE( q.value( 2 ).toDateTime(), dt ); - QCOMPARE( q.value( 3 ).toDouble(), 2.3 ); QVERIFY( q.next() ); - QCOMPARE( q.value( 0 ).toInt(), 2 ); - QCOMPARE( q.value( 1 ).toString(), QString( "boris" ) ); - QCOMPARE( q.value( 2 ).toDateTime(), dt.addDays( -1 ) ); - QCOMPARE( q.value( 3 ).toDouble(), 3.4 ); QVERIFY( q.next() ); - QVERIFY( q.value( 0 ).isNull() ); - QVERIFY( q.value( 1 ).isNull() ); - QVERIFY( q.value( 2 ).isNull() ); - QVERIFY( q.value( 3 ).isNull() ); } @@ -2344,6 +2323,8 @@ void tst_QSqlQuery::sqlite_finish() QString tableName = qTableName( "qtest_lockedtable" ); QSqlQuery q( db ); + + tst_Databases::safeDropTable( db2, tableName ); q.exec( "CREATE TABLE " + tableName + " (pk_id INTEGER PRIMARY KEY, whatever TEXT)" ); q.exec( "INSERT INTO " + tableName + " values(1, 'whatever')" ); q.exec( "INSERT INTO " + tableName + " values(2, 'whatever more')" ); @@ -2361,7 +2342,8 @@ void tst_QSqlQuery::sqlite_finish() q.finish(); QVERIFY_SQL( q2, exec( "DELETE FROM " + tableName + " WHERE pk_id=2" ) ); QCOMPARE( q2.numRowsAffected(), 1 ); - q.exec( "DROP TABLE " + tableName ); + + tst_Databases::safeDropTable( db2, tableName ); } QSqlDatabase::removeDatabase( "sqlite_finish_sqlite" ); @@ -2574,71 +2556,47 @@ void tst_QSqlQuery::blobsPreparedQuery() QString tableName = qTableName( "blobstest" ); QSqlQuery q( db ); - q.setForwardOnly( true ); // This is needed to make the test work with DB2. - QString shortBLOB( "abc" ); - QString longerBLOB( "abcdefghijklmnopqrstuvxyz¿äëïöü¡ " ); // In PostgreSQL a BLOB is not called a BLOB, but a BYTEA! :-) // ... and in SQL Server it can be called a lot, but IMAGE will do. QString typeName( "BLOB" ); - if ( db.driverName().startsWith( "QPSQL" ) ) typeName = "BYTEA"; else if ( db.driverName().startsWith( "QODBC" ) ) typeName = "IMAGE"; QVERIFY_SQL( q, exec( QString( "CREATE TABLE %1(id INTEGER, data %2)" ).arg( tableName ).arg( typeName ) ) ); - q.prepare( QString( "INSERT INTO %1(id, data) VALUES(:id, :data)" ).arg( tableName ) ); - q.bindValue( ":id", 1 ); - q.bindValue( ":data", shortBLOB.toAscii() ); - QVERIFY_SQL( q, exec() ); q.bindValue( ":id", 2 ); - q.bindValue( ":data", longerBLOB.toAscii() ); - QVERIFY_SQL( q, exec() ); // Two executions and result sets q.prepare( QString( "SELECT data FROM %1 WHERE id = ?" ).arg( tableName ) ); - q.bindValue( 0, QVariant( 1 ) ); - QVERIFY_SQL( q, exec() ); - QVERIFY_SQL( q, next() ); - QCOMPARE( q.value( 0 ).toString(), shortBLOB ); q.bindValue( 0, QVariant( 2 ) ); - QVERIFY_SQL( q, exec() ); - QVERIFY_SQL( q, next() ); - QCOMPARE( q.value( 0 ).toString(), longerBLOB ); // Only one execution and result set q.prepare( QString( "SELECT id, data FROM %1 ORDER BY id" ).arg( tableName ) ); - QVERIFY_SQL( q, exec() ); - QVERIFY_SQL( q, next() ); - QCOMPARE( q.value( 1 ).toString(), shortBLOB ); - QVERIFY_SQL( q, next() ); - QCOMPARE( q.value( 1 ).toString(), longerBLOB ); - - q.exec( QString( "DROP TABLE %1" ).arg( tableName ) ); } // There were problems with navigating past the end of a table returning an error on mysql @@ -2792,7 +2750,6 @@ void tst_QSqlQuery::task_234422() QString tableName = qTableName( "task_234422" ); - query.exec("DROP TABLE " + tableName); QVERIFY_SQL(query,exec("CREATE TABLE " + tableName + " (id int primary key, " "name varchar(20), homecountry varchar(2))")); for (int i = 0; i < m_airlines.count(); ++i) { diff --git a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp index 4588af8..e2dace8 100644 --- a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp +++ b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp @@ -86,6 +86,9 @@ private slots: void escapedRelations(); void escapedTableName(); void whiteSpaceInIdentifiers(); + +private: + void dropTestTables( QSqlDatabase db ); }; @@ -100,18 +103,9 @@ void tst_QSqlRelationalTableModel::initTestCase_data() void tst_QSqlRelationalTableModel::recreateTestTables(QSqlDatabase db) { - QSqlQuery q(db); - - QStringList tableNames; - tableNames << qTableName( "reltest1" ) - << qTableName( "reltest2" ) - << qTableName( "reltest3" ) - << qTableName( "reltest4" ) - << qTableName( "reltest5" ) - << db.driver()->escapeIdentifier(qTableName( "rel test6" ), QSqlDriver::TableName) - << db.driver()->escapeIdentifier(qTableName( "rel test7" ), QSqlDriver::TableName); - tst_Databases::safeDropTables( db, tableNames ); + dropTestTables(db); + QSqlQuery q(db); QVERIFY_SQL( q, exec("create table " + qTableName("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)")); @@ -157,20 +151,27 @@ void tst_QSqlRelationalTableModel::initTestCase() void tst_QSqlRelationalTableModel::cleanupTestCase() { + foreach (const QString &dbName, dbs.dbNames) { + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE( db ); + dropTestTables( QSqlDatabase::database(dbName) ); + } + dbs.close(); +} + +void tst_QSqlRelationalTableModel::dropTestTables( QSqlDatabase db ) +{ QStringList tableNames; tableNames << qTableName( "reltest1" ) << qTableName( "reltest2" ) << qTableName( "reltest3" ) << qTableName( "reltest4" ) - << qTableName( "reltest5" ); - foreach (const QString &dbName, dbs.dbNames) { - QSqlDatabase db = QSqlDatabase::database(dbName); - QStringList tables = tableNames; - tables << db.driver()->escapeIdentifier(qTableName( "rel test6" ), QSqlDriver::TableName) - << db.driver()->escapeIdentifier(qTableName( "rel test7" ), QSqlDriver::TableName); - tst_Databases::safeDropTables( db, tables ); - } - dbs.close(); + << qTableName( "reltest5" ) + << qTableName( "rel test6", db.driver() ) + << qTableName( "rel test7", db.driver() ) + << qTableName("CASETEST1", db.driver() ) + << qTableName("casetest1", db.driver() ); + tst_Databases::safeDropTables( db, tableNames ); } void tst_QSqlRelationalTableModel::init() @@ -916,11 +917,6 @@ void tst_QSqlRelationalTableModel::casing() if (db.driverName().startsWith("QSQLITE")) QSKIP("The casing test for SQLITE is irrelevant since SQLITE is case insensitive", SkipAll); - QStringList tableNames; - tableNames << qTableName("CASETEST1", db.driver()).toUpper(); - tableNames << qTableName("casetest1", db.driver()); - tst_Databases::safeDropTables(db, tableNames); - QSqlQuery q(db); QVERIFY_SQL( q, exec("create table " + qTableName("CASETEST1", db.driver()).toUpper() + " (id int not null primary key, name varchar(20), title_key int, another_title_key int)")); @@ -974,8 +970,6 @@ void tst_QSqlRelationalTableModel::casing() QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); - - tst_Databases::safeDropTables(db, tableNames); } void tst_QSqlRelationalTableModel::escapedRelations() diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp index aa882be..1445f34 100644 --- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp @@ -899,7 +899,7 @@ void tst_QSqlTableModel::sqlite_attachedDatabase() QVERIFY_SQL( q, exec("INSERT INTO atest2 VALUES(2, 'attached-atest2')")); QSqlQuery q2(db); - tst_Databases::safeDropTables(db, QStringList() << "atest"); + tst_Databases::safeDropTable(db, "atest"); QVERIFY_SQL(q2, exec("CREATE TABLE atest(id int, text varchar(20))")); QVERIFY_SQL(q2, exec("INSERT INTO atest VALUES(3, 'main')")); QVERIFY_SQL(q2, exec("ATTACH DATABASE \""+attachedDb.databaseName()+"\" as adb")); |