diff options
Diffstat (limited to 'tests/auto/qsqlquery/tst_qsqlquery.cpp')
-rw-r--r-- | tests/auto/qsqlquery/tst_qsqlquery.cpp | 190 |
1 files changed, 75 insertions, 115 deletions
diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 019b111..074f16f 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ - #include <QtTest/QtTest> #include <QtSql/QtSql> @@ -94,7 +93,7 @@ private slots: void transaction(); void record_data() { generic_data(); } void record(); - void record_sqlite_data() { generic_data(); } + void record_sqlite_data() { generic_data("QSQLITE"); } void record_sqlite(); void finish_data() { generic_data(); } void finish(); @@ -108,13 +107,13 @@ private slots: void forwardOnly(); // bug specific tests - void bitField_data(); + void bitField_data() {generic_data("QTDS"); } void bitField(); - void nullBlob_data(); + void nullBlob_data() { generic_data("QOCI"); } void nullBlob(); void blob_data() { generic_data(); } void blob(); - void rawField_data(); + void rawField_data() { generic_data("QOCI"); } void rawField(); void precision_data() { generic_data(); } void precision(); @@ -130,22 +129,20 @@ private slots: void char1SelectUnicode(); void synonyms_data() { generic_data(); } void synonyms(); - void oraOutValues_data(); + void oraOutValues_data() { generic_data("QOCI"); } void oraOutValues(); - void mysqlOutValues_data(); + void mysqlOutValues_data() { generic_data("QMYSQL"); } void mysqlOutValues(); - void oraClob_data() { oraOutValues_data(); } + void oraClob_data() { generic_data("QOCI"); } void oraClob(); - void oraLong_data() { oraOutValues_data(); } + void oraLong_data() { generic_data("QOCI"); } void oraLong(); - void outValuesDB2_data(); + void outValuesDB2_data() { generic_data("QDB2"); } void outValuesDB2(); - void storedProceduresIBase_data(); + void storedProceduresIBase_data() {generic_data("QIBASE"); } void storedProceduresIBase(); - void oraRowId_data(); + void oraRowId_data() { generic_data("QOCI"); } void oraRowId(); - void oraXmlType_data(); - void oraXmlType(); void prepare_bind_exec_data() { generic_data(); } void prepare_bind_exec(); void prepared_select_data() { generic_data(); } @@ -178,13 +175,17 @@ private slots: void emptyTableNavigate(); #ifdef NOT_READY_YET - void bug217003_data() { generic_data(); } - void bug217003(); + void task_217003_data() { generic_data(); } + void task_217003(); #endif + void task_250026_data() { generic_data("QODBC"); } + void task_250026(); + + private: // returns all database connections - void generic_data(); + void generic_data(const QString &engine=QString()); void dropTestTables( QSqlDatabase db ); void createTestTables( QSqlDatabase db ); void populateTestTables( QSqlDatabase db ); @@ -250,34 +251,14 @@ void tst_QSqlQuery::cleanup() } } -void tst_QSqlQuery::bitField_data() -{ - if ( dbs.fillTestTable( "QTDS" ) == 0 ) - QSKIP( "No TDS database drivers are available in this Qt configuration", SkipAll ); -} - -void tst_QSqlQuery::nullBlob_data() -{ - if ( dbs.fillTestTable( "QOCI" ) == 0 ) - QSKIP( "No Oracle database drivers are available in this Qt configuration", SkipAll ); -} - -void tst_QSqlQuery::oraXmlType_data() -{ - if ( dbs.fillTestTable( "QOCI" ) == 0 ) - QSKIP( "No Oracle database drivers are available in this Qt configuration", SkipAll ); -} - -void tst_QSqlQuery::rawField_data() +void tst_QSqlQuery::generic_data(const QString& engine) { - if ( dbs.fillTestTable( "QOCI" ) == 0 ) - QSKIP( "No Oracle database drivers are available in this Qt configuration", SkipAll ); -} - -void tst_QSqlQuery::generic_data() -{ - if ( dbs.fillTestTable() == 0 ) - QSKIP( "No database drivers are available in this Qt configuration", SkipAll ); + if ( dbs.fillTestTable(engine) == 0 ) { + if(engine.isEmpty()) + QSKIP( "No database drivers are available in this Qt configuration", SkipAll ); + else + QSKIP( (QString("No database drivers of type %1 are available in this Qt configuration").arg(engine)).toLocal8Bit(), SkipAll ); + } } void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) @@ -305,7 +286,7 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) << qTableName( "blobstest" ) << qTableName( "oraRowId" ); - if ( db.driverName() == "QSQLITE" ) + if ( db.driverName().startsWith("QSQLITE") ) tablenames << qTableName( "record_sqlite" ); if ( tst_Databases::isSqlServer( db ) || db.driverName().startsWith( "QOCI" ) ) @@ -316,6 +297,7 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) #ifdef NOT_READY_YET tablenames << qTableName( "Planet" ); #endif + tablenames << qTableName( "task_250026" ); tst_Databases::safeDropTables( db, tablenames ); } @@ -430,12 +412,6 @@ void tst_QSqlQuery::char1SelectUnicode() QSKIP( "Database not unicode capable", SkipSingle ); } -void tst_QSqlQuery::oraRowId_data() -{ - if ( dbs.fillTestTable( "QOCI" ) == 0 ) - QSKIP( "No Oracle database drivers are available in this Qt configuration", SkipAll ); -} - void tst_QSqlQuery::oraRowId() { QFETCH( QString, dbName ); @@ -470,28 +446,6 @@ void tst_QSqlQuery::oraRowId() QCOMPARE( q.value( 0 ).toString(), QString( "b" ) ); } -void tst_QSqlQuery::oraXmlType() -{ - QFETCH( QString, dbName ); - QSqlDatabase db = QSqlDatabase::database( dbName ); - CHECK_DATABASE( db ); - - QString xmlStr = "<foo>" + QString().fill( 'a', 5000 ) + "</foo>"; - - QSqlQuery q( db ); - - QVERIFY_SQL( q, exec( "create table " + qTableName( "qxmltest" ) + " (col1 SYS.XMLTYPE)" ) ); - QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qxmltest" ) + " values (?)" ) ); - q.addBindValue( xmlStr, QSql::Binary ); - QVERIFY_SQL( q, exec() ); -} - -void tst_QSqlQuery::mysqlOutValues_data() -{ - if ( dbs.fillTestTable( "QMYSQL" ) == 0 ) - QSKIP( "No MySQL database drivers are available in this Qt configuration", SkipAll ); -} - void tst_QSqlQuery::mysqlOutValues() { QFETCH( QString, dbName ); @@ -542,12 +496,6 @@ void tst_QSqlQuery::mysqlOutValues() QVERIFY_SQL( q, exec( "drop procedure " + qTableName( "qtestproc" ) ) ); } -void tst_QSqlQuery::oraOutValues_data() -{ - if ( dbs.fillTestTable( "QOCI" ) == 0 ) - QSKIP( "No Oracle database drivers are available in this Qt configuration", SkipAll ); -} - void tst_QSqlQuery::oraOutValues() { QFETCH( QString, dbName ); @@ -657,8 +605,8 @@ void tst_QSqlQuery::oraClob() 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(?, ?, ?)" ) ); q.addBindValue( 1 ); - q.addBindValue( "bubu", QSql::Binary ); - q.addBindValue( "bubu", QSql::Binary ); + q.addBindValue( "bubu" ); + q.addBindValue( QByteArray("bubu") ); QVERIFY_SQL( q, exec() ); QVERIFY_SQL( q, exec( "select bl, cl from " + qTableName( "clobby" ) + " where id = 1" ) ); @@ -670,7 +618,7 @@ void tst_QSqlQuery::oraClob() QVERIFY_SQL( q, prepare( "insert into " + qTableName( "clobby" ) + " (id, cl, bl) values(?, ?, ?)" ) ); q.addBindValue( 2 ); q.addBindValue( "lala", QSql::Binary ); - 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" ) ); @@ -684,21 +632,15 @@ void tst_QSqlQuery::oraClob() QVERIFY_SQL( q, prepare( "insert into " + qTableName( "clobby" ) + " (id, cl, bl) values(?, ?, ?)" ) ); q.addBindValue( 3 ); q.addBindValue( loong, QSql::Binary ); - 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( q.next() ); QCOMPARE( q.value( 0 ).toString().count(), loong.count() ); QVERIFY( q.value( 0 ).toString() == loong ); - QCOMPARE( q.value( 1 ).toString().count(), loong.count() ); - QVERIFY( q.value( 1 ).toString() == loong ); -} - -void tst_QSqlQuery::storedProceduresIBase_data() -{ - if ( dbs.fillTestTable( "QIBASE" ) == 0 ) - QSKIP( "No Interbase database drivers are available in this Qt configuration", SkipAll ); + QCOMPARE( q.value( 1 ).toByteArray().count(), loong.toLatin1().count() ); + QVERIFY( q.value( 1 ).toByteArray() == loong.toLatin1() ); } void tst_QSqlQuery::storedProceduresIBase() @@ -706,7 +648,6 @@ void tst_QSqlQuery::storedProceduresIBase() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - DBMS_SPECIFIC( db, "QIBASE" ); QSqlQuery q( db ); q.exec( "drop procedure " + qTableName( "TESTPROC" ) ); @@ -738,12 +679,6 @@ void tst_QSqlQuery::storedProceduresIBase() q.exec( "drop procedure " + qTableName( "TestProc" ) ); } -void tst_QSqlQuery::outValuesDB2_data() -{ - if ( dbs.fillTestTable( "QDB2" ) == 0 ) - QSKIP( "No DB2 database drivers are available in this Qt configuration", SkipAll ); -} - void tst_QSqlQuery::outValuesDB2() { QFETCH( QString, dbName ); @@ -1380,7 +1315,6 @@ void tst_QSqlQuery::nullBlob() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - DBMS_SPECIFIC( db, "QOCI" ); QSqlQuery q( db ); QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_nullblob" ) + " (id int primary key, bb blob)" ) ); @@ -1410,7 +1344,6 @@ void tst_QSqlQuery::rawField() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - DBMS_SPECIFIC( db, "QOCI" ); QSqlQuery q( db ); q.setForwardOnly( true ); @@ -2082,7 +2015,7 @@ void tst_QSqlQuery::oraArrayBind() QVariantList list; - list << QString( "boris" ) << QString( "and" ) << QString( "harald" ) << QString( "both" ) << QString( "hate" ) << QString( "oracle" ); + list << QString( "lorem" ) << QString( "ipsum" ) << QString( "dolor" ) << QString( "sit" ) << QString( "amet" ); QVERIFY_SQL( q, prepare( "BEGIN " "ora_array_test.set_table(?); " @@ -2098,7 +2031,7 @@ void tst_QSqlQuery::oraArrayBind() list.clear(); - list << QString( 64,' ' ) << QString( 64,' ' ) << QString( 64,' ' ) << QString( 64,' ' ) << QString( 64,' ' ) << QString( 64,' ' ); + list << QString( 64,' ' ) << QString( 64,' ' ) << QString( 64,' ' ) << QString( 64,' ' ) << QString( 64,' ' ); q.bindValue( 0, list, QSql::Out ); @@ -2106,17 +2039,15 @@ void tst_QSqlQuery::oraArrayBind() QVariantList out_list = q.boundValue( 0 ).toList(); - QCOMPARE( out_list.at( 0 ).toString(), QString( "boris" ) ); - - QCOMPARE( out_list.at( 1 ).toString(), QString( "and" ) ); + QCOMPARE( out_list.at( 0 ).toString(), QString( "lorem" ) ); - QCOMPARE( out_list.at( 2 ).toString(), QString( "harald" ) ); + QCOMPARE( out_list.at( 1 ).toString(), QString( "ipsum" ) ); - QCOMPARE( out_list.at( 3 ).toString(), QString( "both" ) ); + QCOMPARE( out_list.at( 2 ).toString(), QString( "dolor" ) ); - QCOMPARE( out_list.at( 4 ).toString(), QString( "hate" ) ); + QCOMPARE( out_list.at( 3 ).toString(), QString( "sit" ) ); - QCOMPARE( out_list.at( 5 ).toString(), QString( "oracle" ) ); + QCOMPARE( out_list.at( 4 ).toString(), QString( "amet" ) ); QVERIFY_SQL( q, exec( "DROP PACKAGE ora_array_test" ) ); } @@ -2130,7 +2061,6 @@ void tst_QSqlQuery::record_sqlite() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - DBMS_SPECIFIC( db, "QSQLITE" ); QSqlQuery q( db ); @@ -2158,7 +2088,6 @@ void tst_QSqlQuery::oraLong() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - DBMS_SPECIFIC( db, "QOCI" ); QSqlQuery q( db ); @@ -2182,11 +2111,10 @@ void tst_QSqlQuery::execErrorRecovery() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - DBMS_SPECIFIC( db, "QSQLITE" ); QSqlQuery q( db ); - QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_exerr" ) + " (id int primary key)" ) ); + 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 (?)" ) ); q.addBindValue( 1 ); @@ -2396,7 +2324,10 @@ void tst_QSqlQuery::sqlite_finish() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - DBMS_SPECIFIC( db, "QSQLITE" ); + if (db.driverName() != QLatin1String("QSQLITE")) { + QSKIP("Sqlite3 specific test", SkipSingle); + return; + } if ( db.databaseName().startsWith( ':' ) ) QSKIP( "This test requires a database on the filesystem, not in-memory", SkipAll ); @@ -2723,7 +2654,7 @@ void tst_QSqlQuery::emptyTableNavigate() } #ifdef NOT_READY_YET -void tst_QSqlQuery::bug217003() +void tst_QSqlQuery::task_217003() { QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); @@ -2751,5 +2682,34 @@ void tst_QSqlQuery::bug217003() } #endif +void tst_QSqlQuery::task_250026() +{ + QString data258, data1026; + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + QSqlQuery q( db ); + + QString tableName = qTableName( "task_250026" ); + + if ( !q.exec( "create table " + tableName + " (longfield varchar(1100))" ) ) { + qDebug() << "Error" << q.lastError(); + QSKIP( "Db doesn't support \"1100\" as a size for fields", SkipSingle ); + } + + data258.fill( 'A', 258 ); + data1026.fill( 'A', 1026 ); + QVERIFY_SQL( q, prepare( "insert into " + tableName + "(longfield) VALUES (:longfield)" ) ); + q.bindValue( "longfield", data258 ); + QVERIFY_SQL( q, exec() ); + q.bindValue( "longfield", data1026 ); + QVERIFY_SQL( q, exec() ); + QVERIFY_SQL( q, exec( "select * from " + tableName ) ); + QVERIFY_SQL( q, next() ); + QCOMPARE( q.value( 0 ).toString().length(), data258.length() ); + QVERIFY_SQL( q, next() ); + QCOMPARE( q.value( 0 ).toString().length(), data1026.length() ); +} + QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" |