tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp
changeset 7 f7bc934e204c
parent 0 1918ee327afb
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the test suite of the Qt Toolkit.
     7 ** This file is part of the test suite of the Qt Toolkit.
     8 **
     8 **
   109     QSqlQuery q( db );
   109     QSqlQuery q( db );
   110     if(tst_Databases::isPostgreSQL(db))
   110     if(tst_Databases::isPostgreSQL(db))
   111         QVERIFY_SQL( q, exec("set client_min_messages='warning'"));
   111         QVERIFY_SQL( q, exec("set client_min_messages='warning'"));
   112     // please never ever change this table; otherwise fix all tests ;)
   112     // please never ever change this table; otherwise fix all tests ;)
   113     if (tst_Databases::isMSAccess(db))
   113     if (tst_Databases::isMSAccess(db))
   114         QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest" ) + " ( id int not null, t_varchar varchar(40) not null,"
   114         QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest", __FILE__ ) + " ( id int not null, t_varchar varchar(40) not null,"
   115                 "t_char char(40), t_numeric number, primary key (id, t_varchar) )" ));
   115                 "t_char char(40), t_numeric number, primary key (id, t_varchar) )" ));
   116     else
   116     else
   117         QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest" ) + " ( id int not null, t_varchar varchar(40) not null,"
   117         QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest", __FILE__ ) + " ( id int not null, t_varchar varchar(40) not null,"
   118                 "t_char char(40), t_numeric numeric(6, 3), primary key (id, t_varchar) )" ));
   118                 "t_char char(40), t_numeric numeric(6, 3), primary key (id, t_varchar) )" ));
   119 }
   119 }
   120 
   120 
   121 void tst_Q3SqlSelectCursor::dropTestTables( QSqlDatabase db )
   121 void tst_Q3SqlSelectCursor::dropTestTables( QSqlDatabase db )
   122 {
   122 {
   123     tst_Databases::safeDropTable( db, qTableName( "qtest" ) );
   123     tst_Databases::safeDropTable( db, qTableName( "qtest", __FILE__ ) );
   124 }
   124 }
   125 
   125 
   126 void tst_Q3SqlSelectCursor::populateTestTables( QSqlDatabase db )
   126 void tst_Q3SqlSelectCursor::populateTestTables( QSqlDatabase db )
   127 {
   127 {
   128     if ( !db.isValid() )
   128     if ( !db.isValid() )
   129 	return;
   129 	return;
   130     QSqlQuery q( db );
   130     QSqlQuery q( db );
   131 
   131 
   132     q.exec( "delete from " + qTableName( "qtest" ) ); //non-fatal
   132     q.exec( "delete from " + qTableName( "qtest", __FILE__ ) ); //non-fatal
   133     QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest" ) + " (id, t_varchar, t_char, t_numeric) values ( 0, 'VarChar0', 'Char0', 1.1 )" ));
   133     QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest", __FILE__ ) + " (id, t_varchar, t_char, t_numeric) values ( 0, 'VarChar0', 'Char0', 1.1 )" ));
   134     QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest" ) + " (id, t_varchar, t_char, t_numeric) values ( 1, 'VarChar1', 'Char1', 2.2 )" ));
   134     QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest", __FILE__ ) + " (id, t_varchar, t_char, t_numeric) values ( 1, 'VarChar1', 'Char1', 2.2 )" ));
   135     QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest" ) + " (id, t_varchar, t_char, t_numeric) values ( 2, 'VarChar2', 'Char2', 3.3 )" ));
   135     QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest", __FILE__ ) + " (id, t_varchar, t_char, t_numeric) values ( 2, 'VarChar2', 'Char2', 3.3 )" ));
   136     QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest" ) + " (id, t_varchar, t_char, t_numeric) values ( 3, 'VarChar3', 'Char3', 4.4 )" ));
   136     QVERIFY_SQL(q, exec( "insert into " + qTableName( "qtest", __FILE__ ) + " (id, t_varchar, t_char, t_numeric) values ( 3, 'VarChar3', 'Char3', 4.4 )" ));
   137 }
   137 }
   138 
   138 
   139 void tst_Q3SqlSelectCursor::initTestCase()
   139 void tst_Q3SqlSelectCursor::initTestCase()
   140 {
   140 {
   141     dbs.open();
   141     dbs.open();
   182 {
   182 {
   183     QFETCH( QString, dbName );
   183     QFETCH( QString, dbName );
   184     QSqlDatabase db = QSqlDatabase::database( dbName );
   184     QSqlDatabase db = QSqlDatabase::database( dbName );
   185     CHECK_DATABASE( db );
   185     CHECK_DATABASE( db );
   186 
   186 
   187     Q3SqlSelectCursor cur( "select * from " + qTableName( "qtest" ) + " order by id", db );
   187     Q3SqlSelectCursor cur( "select * from " + qTableName( "qtest", __FILE__ ) + " order by id", db );
   188     QVERIFY( cur.select() );
   188     QVERIFY( cur.select() );
   189     QVERIFY_SQL(cur, isActive());
   189     QVERIFY_SQL(cur, isActive());
   190     int i = 0;
   190     int i = 0;
   191     while ( cur.next() ) {
   191     while ( cur.next() ) {
   192 	QVERIFY( cur.value( "id" ).toInt() == i );
   192 	QVERIFY( cur.value( "id" ).toInt() == i );
   201     CHECK_DATABASE( db );
   201     CHECK_DATABASE( db );
   202     
   202     
   203     Q3SqlSelectCursor cur( QString(), db );
   203     Q3SqlSelectCursor cur( QString(), db );
   204     QVERIFY_SQL(cur, isActive() == false);
   204     QVERIFY_SQL(cur, isActive() == false);
   205 
   205 
   206     cur.exec( "select * from " + qTableName( "qtest" ) ); //nothing should happen
   206     cur.exec( "select * from " + qTableName( "qtest", __FILE__ ) ); //nothing should happen
   207     QVERIFY_SQL(cur, isActive());
   207     QVERIFY_SQL(cur, isActive());
   208     int i = 0;
   208     int i = 0;
   209     while ( cur.next() ) {
   209     while ( cur.next() ) {
   210 	QVERIFY( cur.value( "id" ).toInt() == i );
   210 	QVERIFY( cur.value( "id" ).toInt() == i );
   211 	i++;
   211 	i++;