tests/auto/qsqlquery/tst_qsqlquery.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   192     void task_233829();
   192     void task_233829();
   193 
   193 
   194     void sqlServerReturn0_data() { generic_data(); }
   194     void sqlServerReturn0_data() { generic_data(); }
   195     void sqlServerReturn0();
   195     void sqlServerReturn0();
   196 
   196 
       
   197     void QTBUG_551_data() { generic_data("QOCI"); }
       
   198     void QTBUG_551();
       
   199 
       
   200     void QTBUG_5251_data() { generic_data("QPSQL"); }
       
   201     void QTBUG_5251();
       
   202     void QTBUG_6421_data() { generic_data("QOCI"); }
       
   203     void QTBUG_6421();
       
   204     void QTBUG_6618_data() { generic_data("QODBC"); }
       
   205     void QTBUG_6618();
       
   206 
   197 private:
   207 private:
   198     // returns all database connections
   208     // returns all database connections
   199     void generic_data(const QString &engine=QString());
   209     void generic_data(const QString &engine=QString());
   200     void dropTestTables( QSqlDatabase db );
   210     void dropTestTables( QSqlDatabase db );
   201     void createTestTables( QSqlDatabase db );
   211     void createTestTables( QSqlDatabase db );
   294                << qTableName( "clobby" )
   304                << qTableName( "clobby" )
   295                << qTableName( "bindtest" )
   305                << qTableName( "bindtest" )
   296                << qTableName( "more_results" )
   306                << qTableName( "more_results" )
   297                << qTableName( "blobstest" )
   307                << qTableName( "blobstest" )
   298                << qTableName( "oraRowId" )
   308                << qTableName( "oraRowId" )
   299                << qTableName( "qtest_batch" );
   309                << qTableName( "qtest_batch" )
       
   310                << qTableName(QLatin1String("bug6421")).toUpper();
   300 
   311 
   301     if ( db.driverName().startsWith("QPSQL") )
   312     if ( db.driverName().startsWith("QPSQL") )
   302         tablenames << qTableName("task_233829");
   313         tablenames << qTableName("task_233829");
   303 
   314 
   304     if ( db.driverName().startsWith("QSQLITE") )
   315     if ( db.driverName().startsWith("QSQLITE") )
   320     }
   331     }
   321 
   332 
   322     tablenames << qTableName("test141895");
   333     tablenames << qTableName("test141895");
   323 
   334 
   324     tst_Databases::safeDropTables( db, tablenames );
   335     tst_Databases::safeDropTables( db, tablenames );
       
   336 
       
   337     if ( db.driverName().startsWith( "QOCI" ) ) {
       
   338         QSqlQuery q( db );
       
   339         q.exec( "DROP PACKAGE " + qTableName("pkg") );
       
   340     }
   325 }
   341 }
   326 
   342 
   327 void tst_QSqlQuery::createTestTables( QSqlDatabase db )
   343 void tst_QSqlQuery::createTestTables( QSqlDatabase db )
   328 {
   344 {
   329     QSqlQuery q( db );
   345     QSqlQuery q( db );
   394 
   410 
   395     if(db.driverName().startsWith("QDB2"))
   411     if(db.driverName().startsWith("QDB2"))
   396         QSKIP("Needs someone with more Unicode knowledge than I have to fix", SkipSingle);
   412         QSKIP("Needs someone with more Unicode knowledge than I have to fix", SkipSingle);
   397 
   413 
   398     if ( db.driver()->hasFeature( QSqlDriver::Unicode ) ) {
   414     if ( db.driver()->hasFeature( QSqlDriver::Unicode ) ) {
   399         QString uniStr( QChar( 'का' ) );
   415         QString uniStr( QChar(0x0915) ); // DEVANAGARI LETTER KA
   400         QSqlQuery q( db );
   416         QSqlQuery q( db );
   401 
   417 
   402         if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 )
   418         if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 )
   403             QSKIP( "Test requires MySQL >= 5.0", SkipSingle );
   419             QSKIP( "Test requires MySQL >= 5.0", SkipSingle );
   404 
   420 
  2845     QVERIFY_SQL(q, exec("{CALL "+procName+"}"));
  2861     QVERIFY_SQL(q, exec("{CALL "+procName+"}"));
  2846 
  2862 
  2847     QVERIFY_SQL(q, next());
  2863     QVERIFY_SQL(q, next());
  2848 }
  2864 }
  2849 
  2865 
       
  2866 void tst_QSqlQuery::QTBUG_551()
       
  2867 {
       
  2868     QFETCH( QString, dbName );
       
  2869     QSqlDatabase db = QSqlDatabase::database( dbName );
       
  2870     CHECK_DATABASE( db );
       
  2871     QSqlQuery q(db);
       
  2872     QString pkgname=qTableName("pkg");
       
  2873     QVERIFY_SQL(q, exec("CREATE OR REPLACE PACKAGE "+pkgname+" IS \n\
       
  2874             \n\
       
  2875             TYPE IntType IS TABLE OF INTEGER      INDEX BY BINARY_INTEGER;\n\
       
  2876             TYPE VCType  IS TABLE OF VARCHAR2(60) INDEX BY BINARY_INTEGER;\n\
       
  2877             PROCEDURE P (Inp IN IntType,  Outp OUT VCType);\n\
       
  2878             END "+pkgname+";"));
       
  2879 
       
  2880      QVERIFY_SQL(q, exec("CREATE OR REPLACE PACKAGE BODY "+pkgname+" IS\n\
       
  2881             PROCEDURE P (Inp IN IntType,  Outp OUT VCType)\n\
       
  2882             IS\n\
       
  2883             BEGIN\n\
       
  2884              Outp(1) := '1. Value is ' ||TO_CHAR(Inp(1));\n\
       
  2885              Outp(2) := '2. Value is ' ||TO_CHAR(Inp(2));\n\
       
  2886              Outp(3) := '3. Value is ' ||TO_CHAR(Inp(3));\n\
       
  2887             END p;\n\
       
  2888             END "+pkgname+";"));
       
  2889 
       
  2890     QVariantList inLst, outLst, res_outLst;
       
  2891 
       
  2892     q.prepare("begin "+pkgname+".p(:inp, :outp); end;");
       
  2893 
       
  2894     QString StVal;
       
  2895     StVal.reserve(60);
       
  2896 
       
  2897     // loading arrays
       
  2898     for (int Cnt=0; Cnt < 3; Cnt++) {
       
  2899         inLst << Cnt;
       
  2900         outLst << StVal;
       
  2901     }
       
  2902 
       
  2903     q.bindValue(":inp", inLst);
       
  2904     q.bindValue(":outp", outLst, QSql::Out);
       
  2905 
       
  2906     QVERIFY_SQL(q, execBatch(QSqlQuery::ValuesAsColumns) );
       
  2907     res_outLst = qVariantValue<QVariantList>(q.boundValues()[":outp"]);
       
  2908     QCOMPARE(res_outLst[0].toString(), QLatin1String("1. Value is 0"));
       
  2909     QCOMPARE(res_outLst[1].toString(), QLatin1String("2. Value is 1"));
       
  2910     QCOMPARE(res_outLst[2].toString(), QLatin1String("3. Value is 2"));
       
  2911 }
       
  2912 
       
  2913 void tst_QSqlQuery::QTBUG_5251()
       
  2914 {
       
  2915     QFETCH( QString, dbName );
       
  2916     QSqlDatabase db = QSqlDatabase::database( dbName );
       
  2917     CHECK_DATABASE( db );
       
  2918 
       
  2919     if (!db.driverName().startsWith( "QPSQL" )) return;
       
  2920 
       
  2921     QSqlQuery q(db);
       
  2922     q.exec("DROP TABLE " + qTableName("timetest"));
       
  2923     QVERIFY_SQL(q, exec("CREATE TABLE  " + qTableName("timetest") + " (t  TIME)"));
       
  2924     QVERIFY_SQL(q, exec("INSERT INTO " + qTableName("timetest") +  " VALUES ('1:2:3.666')"));
       
  2925 
       
  2926     QSqlTableModel timetestModel(0,db);
       
  2927     timetestModel.setEditStrategy(QSqlTableModel::OnManualSubmit);
       
  2928     timetestModel.setTable(qTableName("timetest"));
       
  2929     QVERIFY_SQL(timetestModel, select());
       
  2930 
       
  2931     QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("01:02:03.666"));
       
  2932     QVERIFY_SQL(timetestModel,setData(timetestModel.index(0, 0), QTime(0,12,34,500)));
       
  2933     QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500"));
       
  2934     QVERIFY_SQL(timetestModel, submitAll());
       
  2935     QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500"));
       
  2936 
       
  2937     QVERIFY_SQL(q, exec("UPDATE " + qTableName("timetest") + " SET t = '0:11:22.33'"));
       
  2938     QVERIFY_SQL(timetestModel, select());
       
  2939     QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:11:22.330"));
       
  2940 
       
  2941 }
       
  2942 
       
  2943 void tst_QSqlQuery::QTBUG_6421()
       
  2944 {
       
  2945     QFETCH( QString, dbName );
       
  2946     QSqlDatabase db = QSqlDatabase::database( dbName );
       
  2947     CHECK_DATABASE( db );
       
  2948 
       
  2949     QSqlQuery q(db);
       
  2950     QString tableName=qTableName(QLatin1String("bug6421")).toUpper();
       
  2951 
       
  2952     QVERIFY_SQL(q, exec("create table "+tableName+"(COL1 char(10), COL2 char(10), COL3 char(10))"));
       
  2953     QVERIFY_SQL(q, exec("create index INDEX1 on "+tableName+" (COL1 desc)"));
       
  2954     QVERIFY_SQL(q, exec("create index INDEX2 on "+tableName+" (COL2 desc)"));
       
  2955     QVERIFY_SQL(q, exec("create index INDEX3 on "+tableName+" (COL3 desc)"));
       
  2956     q.setForwardOnly(true);
       
  2957     QVERIFY_SQL(q, exec("select COLUMN_EXPRESSION from ALL_IND_EXPRESSIONS where TABLE_NAME='"+tableName+"'"));
       
  2958     QVERIFY_SQL(q, next());
       
  2959     QCOMPARE(q.value(0).toString(), QLatin1String("\"COL1\""));
       
  2960     QVERIFY_SQL(q, next());
       
  2961     QCOMPARE(q.value(0).toString(), QLatin1String("\"COL2\""));
       
  2962     QVERIFY_SQL(q, next());
       
  2963     QCOMPARE(q.value(0).toString(), QLatin1String("\"COL3\""));
       
  2964 }
       
  2965 
       
  2966 void tst_QSqlQuery::QTBUG_6618()
       
  2967 {
       
  2968     QFETCH( QString, dbName );
       
  2969     QSqlDatabase db = QSqlDatabase::database( dbName );
       
  2970     CHECK_DATABASE( db );
       
  2971     if (!tst_Databases::isSqlServer( db ))
       
  2972         QSKIP("SQL Server specific test", SkipSingle);
       
  2973 
       
  2974     QSqlQuery q(db);
       
  2975     q.exec( "drop procedure " + qTableName( "tst_raiseError" ) );  //non-fatal
       
  2976     QString errorString;
       
  2977     for (int i=0;i<110;i++)
       
  2978         errorString+="reallylong";
       
  2979     errorString+=" error";
       
  2980     QVERIFY_SQL( q, exec("create procedure " + qTableName( "tst_raiseError" ) + " as\n"
       
  2981                          "begin\n"
       
  2982                          "    raiserror('" + errorString + "', 16, 1)\n"
       
  2983                          "end\n" ));
       
  2984     q.exec( "{call " + qTableName( "tst_raiseError" ) + "}" );
       
  2985     QVERIFY(q.lastError().text().contains(errorString));
       
  2986 }
       
  2987 
  2850 QTEST_MAIN( tst_QSqlQuery )
  2988 QTEST_MAIN( tst_QSqlQuery )
  2851 #include "tst_qsqlquery.moc"
  2989 #include "tst_qsqlquery.moc"