summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsqlquery
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qsqlquery')
-rw-r--r--tests/auto/qsqlquery/qsqlquery.pro13
-rw-r--r--tests/auto/qsqlquery/tst_qsqlquery.cpp145
2 files changed, 96 insertions, 62 deletions
diff --git a/tests/auto/qsqlquery/qsqlquery.pro b/tests/auto/qsqlquery/qsqlquery.pro
index d70ede3..97646ed 100644
--- a/tests/auto/qsqlquery/qsqlquery.pro
+++ b/tests/auto/qsqlquery/qsqlquery.pro
@@ -10,5 +10,16 @@ QT = core sql
wince*: {
plugFiles.sources = ../../../plugins/sqldrivers
plugFiles.path = .
- DEPLOYMENT += plugFiles
+ DEPLOYMENT += plugFiles
+ LIBS += -lws2
+}
+
+symbian {
+ qt_not_deployed {
+ contains(S60_VERSION, 3.1)|contains(S60_VERSION, 3.2)|contains(S60_VERSION, 5.0) {
+ sqlite.path = /sys/bin
+ sqlite.sources = sqlite3.dll
+ DEPLOYMENT += sqlite
+ }
+ }
}
diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp
index 87774a3..4264a70 100644
--- a/tests/auto/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp
@@ -194,6 +194,9 @@ private slots:
void sqlServerReturn0_data() { generic_data(); }
void sqlServerReturn0();
+ void QTBUG_551_data() { generic_data("QOCI"); }
+ void QTBUG_551();
+
void QTBUG_5251_data() { generic_data("QPSQL"); }
void QTBUG_5251();
@@ -298,7 +301,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("QPSQL") )
tablenames << qTableName("task_233829");
@@ -314,6 +318,7 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
tablenames << qTableName( "Planet" );
tablenames << qTableName( "task_250026" );
+ tablenames << qTableName( "task_234422" );
if (tst_Databases::isSqlServer( db )) {
QSqlQuery q( db );
@@ -323,6 +328,11 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
tablenames << qTableName("test141895");
tst_Databases::safeDropTables( db, tablenames );
+
+ if ( db.driverName().startsWith( "QOCI" ) ) {
+ QSqlQuery q( db );
+ q.exec( "DROP PACKAGE " + qTableName("pkg") );
+ }
}
void tst_QSqlQuery::createTestTables( QSqlDatabase db )
@@ -333,6 +343,8 @@ void tst_QSqlQuery::createTestTables( QSqlDatabase db )
// ### stupid workaround until we find a way to hardcode this
// in the MySQL server startup script
q.exec( "set table_type=innodb" );
+ else if(tst_Databases::isPostgreSQL(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" ) );
@@ -391,8 +403,11 @@ void tst_QSqlQuery::char1SelectUnicode()
QSqlDatabase db = QSqlDatabase::database( dbName );
CHECK_DATABASE( db );
+ if(db.driverName().startsWith("QDB2"))
+ QSKIP("Needs someone with more Unicode knowledge than I have to fix", SkipSingle);
+
if ( db.driver()->hasFeature( QSqlDriver::Unicode ) ) {
- QString uniStr( QChar( 0xfb50 ) );
+ QString uniStr( QChar(0x0915) ); // DEVANAGARI LETTER KA
QSqlQuery q( db );
if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 )
@@ -1619,11 +1634,14 @@ void tst_QSqlQuery::prepare_bind_exec()
QFETCH( QString, dbName );
QSqlDatabase db = QSqlDatabase::database( dbName );
CHECK_DATABASE( db );
+ 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"))
+ QSKIP("Needs someone with more Unicode knowledge than I have to fix", SkipSingle);
{
// new scope for SQLITE
- static const unsigned short utf8arr[] = { 0xfb50,0xfb60,0xfb70,0xfb80,0xfbe0,0xfbf0,0x00 };
- static const QString utf8str = QString::fromUtf16( utf8arr );
+ static const QString utf8str = QString::fromUtf8( "काचं शक्नोम्यत्तुम् । नोपहिनस्ति माम् ॥" );
static const QString values[6] = { "Harry", "Trond", "Mark", "Ma?rk", "?", ":id" };
@@ -1636,12 +1654,15 @@ void tst_QSqlQuery::prepare_bind_exec()
QString createQuery;
+ if(tst_Databases::isPostgreSQL(db))
+ 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(20) null)";
- else if ( db.driverName().startsWith( "QMYSQL" ) && useUnicode )
- createQuery = "create table " + qTableName( "qtest_prepare" ) + " (id int not null primary key, name varchar(20) character set utf8)";
+ createQuery = "create table " + qTableName( "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)";
else
- createQuery = "create table " + qTableName( "qtest_prepare" ) + " (id int not null primary key, name varchar(20))";
+ createQuery = "create table " + qTableName( "qtest_prepare" ) + " (id int not null primary key, name varchar(200))";
QVERIFY_SQL( q, exec( createQuery ) );
@@ -1923,71 +1944,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() );
}
@@ -2365,6 +2363,8 @@ void tst_QSqlQuery::sqlite_finish()
QString tableName = qTableName( "qtest_lockedtable" );
QSqlQuery q( db );
+
+ tst_Databases::safeDropTable( db, 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')" );
@@ -2382,7 +2382,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( db, tableName );
}
QSqlDatabase::removeDatabase( "sqlite_finish_sqlite" );
@@ -2595,71 +2596,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" ) && tst_Databases::isSqlServer( db ))
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
@@ -2811,7 +2788,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) {
@@ -2882,6 +2858,53 @@ void tst_QSqlQuery::sqlServerReturn0()
QVERIFY_SQL(q, next());
}
+void tst_QSqlQuery::QTBUG_551()
+{
+ QFETCH( QString, dbName );
+ QSqlDatabase db = QSqlDatabase::database( dbName );
+ CHECK_DATABASE( db );
+ QSqlQuery q(db);
+ QString pkgname=qTableName("pkg");
+ QVERIFY_SQL(q, exec("CREATE OR REPLACE PACKAGE "+pkgname+" IS \n\
+ \n\
+ TYPE IntType IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;\n\
+ TYPE VCType IS TABLE OF VARCHAR2(60) INDEX BY BINARY_INTEGER;\n\
+ PROCEDURE P (Inp IN IntType, Outp OUT VCType);\n\
+ END "+pkgname+";"));
+
+ QVERIFY_SQL(q, exec("CREATE OR REPLACE PACKAGE BODY "+pkgname+" IS\n\
+ PROCEDURE P (Inp IN IntType, Outp OUT VCType)\n\
+ IS\n\
+ BEGIN\n\
+ Outp(1) := '1. Value is ' ||TO_CHAR(Inp(1));\n\
+ Outp(2) := '2. Value is ' ||TO_CHAR(Inp(2));\n\
+ Outp(3) := '3. Value is ' ||TO_CHAR(Inp(3));\n\
+ END p;\n\
+ END "+pkgname+";"));
+
+ QVariantList inLst, outLst, res_outLst;
+
+ q.prepare("begin "+pkgname+".p(:inp, :outp); end;");
+
+ QString StVal;
+ StVal.reserve(60);
+
+ // loading arrays
+ for (int Cnt=0; Cnt < 3; Cnt++) {
+ inLst << Cnt;
+ outLst << StVal;
+ }
+
+ q.bindValue(":inp", inLst);
+ q.bindValue(":outp", outLst, QSql::Out);
+
+ QVERIFY_SQL(q, execBatch(QSqlQuery::ValuesAsColumns) );
+ res_outLst = qVariantValue<QVariantList>(q.boundValues()[":outp"]);
+ QCOMPARE(res_outLst[0].toString(), QLatin1String("1. Value is 0"));
+ QCOMPARE(res_outLst[1].toString(), QLatin1String("2. Value is 1"));
+ QCOMPARE(res_outLst[2].toString(), QLatin1String("3. Value is 2"));
+}
+
void tst_QSqlQuery::QTBUG_5251()
{
QFETCH( QString, dbName );