tests/auto/qsqldriver/tst_qsqldriver.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
    82 }
    82 }
    83 
    83 
    84 void tst_QSqlDriver::recreateTestTables(QSqlDatabase db)
    84 void tst_QSqlDriver::recreateTestTables(QSqlDatabase db)
    85 {
    85 {
    86     QSqlQuery q(db);
    86     QSqlQuery q(db);
       
    87     const QString relTEST1(qTableName("relTEST1", __FILE__));
    87 
    88 
    88     if(tst_Databases::isPostgreSQL(db))
    89     if(tst_Databases::isPostgreSQL(db))
    89         QVERIFY_SQL( q, exec("set client_min_messages='warning'"));
    90         QVERIFY_SQL( q, exec("set client_min_messages='warning'"));
    90 
    91 
    91     tst_Databases::safeDropTable( db, qTableName( "relTEST1" ) );
    92     tst_Databases::safeDropTable( db, relTEST1 );
    92 
    93 
    93     QVERIFY_SQL( q, exec("create table " + qTableName("relTEST1") +
    94     QVERIFY_SQL( q, exec("create table " + relTEST1 +
    94             " (id int not null primary key, name varchar(20), title_key int, another_title_key int)"));
    95             " (id int not null primary key, name varchar(20), title_key int, another_title_key int)"));
    95     QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(1, 'harry', 1, 2)"));
    96     QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(1, 'harry', 1, 2)"));
    96     QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(2, 'trond', 2, 1)"));
    97     QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(2, 'trond', 2, 1)"));
    97     QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(3, 'vohi', 1, 2)"));
    98     QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(3, 'vohi', 1, 2)"));
    98     QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(4, 'boris', 2, 2)"));
    99     QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(4, 'boris', 2, 2)"));
    99 }
   100 }
   100 
   101 
   101 void tst_QSqlDriver::initTestCase()
   102 void tst_QSqlDriver::initTestCase()
   102 {
   103 {
   103     foreach (const QString &dbname, dbs.dbNames)
   104     foreach (const QString &dbname, dbs.dbNames)
   106 
   107 
   107 void tst_QSqlDriver::cleanupTestCase()
   108 void tst_QSqlDriver::cleanupTestCase()
   108 {
   109 {
   109     foreach (const QString &dbName, dbs.dbNames) {
   110     foreach (const QString &dbName, dbs.dbNames) {
   110         QSqlDatabase db = QSqlDatabase::database(dbName);
   111         QSqlDatabase db = QSqlDatabase::database(dbName);
   111         tst_Databases::safeDropTable( db, qTableName( "relTEST1" ) );
   112         tst_Databases::safeDropTable( db, qTableName( "relTEST1", __FILE__ ) );
   112     }
   113     }
   113     dbs.close();
   114     dbs.close();
   114 }
   115 }
   115 
   116 
   116 void tst_QSqlDriver::init()
   117 void tst_QSqlDriver::init()
   125 {
   126 {
   126     QFETCH_GLOBAL(QString, dbName);
   127     QFETCH_GLOBAL(QString, dbName);
   127     QSqlDatabase db = QSqlDatabase::database(dbName);
   128     QSqlDatabase db = QSqlDatabase::database(dbName);
   128     CHECK_DATABASE(db);
   129     CHECK_DATABASE(db);
   129 
   130 
   130     QString tablename =  qTableName("relTEST1");
   131     QString tablename(qTableName("relTEST1", __FILE__));
   131     QStringList fields;
   132     QStringList fields;
   132     fields << "id" << "name" << "title_key" << "another_title_key";
   133     fields << "id" << "name" << "title_key" << "another_title_key";
   133 
   134 
   134     //check we can get records using an unquoted mixed case table name
   135     //check we can get records using an unquoted mixed case table name
   135     QSqlRecord rec = db.driver()->record(tablename);
   136     QSqlRecord rec = db.driver()->record(tablename);
   178 {
   179 {
   179     QFETCH_GLOBAL(QString, dbName);
   180     QFETCH_GLOBAL(QString, dbName);
   180     QSqlDatabase db = QSqlDatabase::database(dbName);
   181     QSqlDatabase db = QSqlDatabase::database(dbName);
   181     CHECK_DATABASE(db);
   182     CHECK_DATABASE(db);
   182 
   183 
   183     QString tablename =  qTableName("relTEST1");
   184     QString tablename(qTableName("relTEST1", __FILE__));
   184     //check that we can get primary index using unquoted mixed case table name
   185     //check that we can get primary index using unquoted mixed case table name
   185     QSqlIndex index = db.driver()->primaryIndex(tablename);
   186     QSqlIndex index = db.driver()->primaryIndex(tablename);
   186     QCOMPARE(index.count(), 1);
   187     QCOMPARE(index.count(), 1);
   187 
   188 
   188     if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2"))
   189     if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2"))