diff options
author | Jason Barron <jbarron@trolltech.com> | 2009-06-30 09:21:56 (GMT) |
---|---|---|
committer | Jason Barron <jbarron@trolltech.com> | 2009-06-30 09:21:56 (GMT) |
commit | 197df24edfe095a10e2bf65116796e027fea44e2 (patch) | |
tree | 4ffb08f614b550298663f90297c9e559ecb47a3c /tests/auto/qsqlquery | |
parent | 1e84894225e31adf80a7a33da7f655fb5c38ea0e (diff) | |
parent | e3c1039d4d10aa383a1f681e7dd9c1129d22d8ca (diff) | |
download | Qt-197df24edfe095a10e2bf65116796e027fea44e2.zip Qt-197df24edfe095a10e2bf65116796e027fea44e2.tar.gz Qt-197df24edfe095a10e2bf65116796e027fea44e2.tar.bz2 |
Merge commit 'qt/master-stable' into 4.6-merged
Conflicts:
.gitignore
configure.exe
src/corelib/concurrent/qtconcurrentthreadengine.h
src/corelib/global/qnamespace.h
src/gui/graphicsview/qgraphicssceneevent.h
src/gui/kernel/qapplication.cpp
src/gui/kernel/qapplication.h
src/gui/kernel/qapplication_p.h
src/gui/kernel/qapplication_qws.cpp
src/gui/kernel/qwidget.h
src/gui/painting/qpaintengine_raster.cpp
src/gui/text/qfontdatabase.cpp
src/network/access/qnetworkaccesshttpbackend.cpp
tests/auto/network-settings.h
tests/auto/qscriptjstestsuite/qscriptjstestsuite.pro
tests/auto/qvariant/tst_qvariant.cpp
Diffstat (limited to 'tests/auto/qsqlquery')
-rw-r--r-- | tests/auto/qsqlquery/tst_qsqlquery.cpp | 168 |
1 files changed, 106 insertions, 62 deletions
diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 7f97972..9604fa8 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. +** contact the sales department at http://www.qtsoftware.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -177,6 +177,10 @@ private slots: #ifdef NOT_READY_YET void task_217003_data() { generic_data(); } void task_217003(); + void task_229811(); + void task_229811_data() { generic_data(); } + void task_234422_data() { generic_data(); } + void task_234422(); #endif void task_250026_data() { generic_data("QODBC"); } void task_250026(); @@ -184,7 +188,6 @@ private slots: void task_205701(); - private: // returns all database connections void generic_data(const QString &engine=QString()); @@ -286,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" ); @@ -300,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 ); } @@ -1899,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() ); } @@ -2341,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')" ); @@ -2358,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" ); @@ -2571,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 @@ -2715,12 +2676,12 @@ void tst_QSqlQuery::task_250026() void tst_QSqlQuery::task_205701() { - QSqlDatabase qsdb = QSqlDatabase::addDatabase("QMYSQL", "atest"); - qsdb.setHostName("test"); - qsdb.setDatabaseName("test"); - qsdb.setUserName("test"); - qsdb.setPassword("test"); - qsdb.open(); + QSqlDatabase qsdb = QSqlDatabase::addDatabase("QMYSQL", "atest"); + qsdb.setHostName("test"); + qsdb.setDatabaseName("test"); + qsdb.setUserName("test"); + qsdb.setPassword("test"); + qsdb.open(); // { QSqlQuery query(qsdb); @@ -2728,6 +2689,89 @@ void tst_QSqlQuery::task_205701() QSqlDatabase::removeDatabase("atest"); } +#ifdef NOT_READY_YET +// For task: 229811 +void tst_QSqlQuery::task_229811() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + + if (!db.driverName().startsWith( "QODBC" )) return; + + QSqlQuery q( db ); + + QString tableName = qTableName( "task_229811" ); + + if ( !q.exec( "CREATE TABLE " + tableName + " (Word varchar(20))" ) ) { + qDebug() << "Warning" << q.lastError(); + } + + QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " values ('Albert')" ) ); + QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " values ('Beehive')" ) ); + QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " values ('Alimony')" ) ); + QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " values ('Bohemian')" ) ); + QVERIFY_SQL( q, exec( "INSERT INTO " + tableName + " values ('AllStars')" ) ); + + + QString stmt = "SELECT * FROM " + tableName + " WHERE Word LIKE :name"; + QVERIFY_SQL(q,prepare(stmt)); + q.bindValue(":name", "A%"); + QVERIFY_SQL(q,exec()); + + QVERIFY(q.isActive()); + QVERIFY(q.isSelect()); + QVERIFY(q.first()); + + QSqlRecord rec = q.record(); + QCOMPARE(rec.field(0).value().toString(), QString("Albert")); + QVERIFY(q.next()); + rec = q.record(); + QCOMPARE(rec.field(0).value().toString(), QString("Alimony")); + QVERIFY(q.next()); + rec = q.record(); + QCOMPARE(rec.field(0).value().toString(),QString("AllStars")); + + q.exec("DROP TABLE " + tableName ); +} + +void tst_QSqlQuery::task_234422() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + + QSqlQuery query(db); + QStringList m_airlines; + QStringList m_countries; + + m_airlines << "Lufthansa" << "SAS" << "United" << "KLM" << "Aeroflot"; + m_countries << "DE" << "SE" << "US" << "NL" << "RU"; + + QString tableName = qTableName( "task_234422" ); + + 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) { + QVERIFY(query.exec(QString("INSERT INTO " + tableName + " values(%1, '%2', '%3')") + .arg(i).arg(m_airlines[i], m_countries[i]))); + } + + QVERIFY_SQL(query, exec("SELECT name FROM " + tableName)); + QVERIFY(query.isSelect()); + QVERIFY(query.first()); + QVERIFY(query.next()); + QCOMPARE(query.at(), 1); + + QSqlQuery query2(query); + + QVERIFY_SQL(query2,exec()); + QVERIFY(query2.first()); + QCOMPARE(query2.at(), 0); + QCOMPARE(query.at(), 1); +} + +#endif QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" |