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 ** |
200 void sqlite_bindAndFetchUInt(); |
200 void sqlite_bindAndFetchUInt(); |
201 |
201 |
202 void sqlStatementUseIsNull_189093_data() { generic_data(); } |
202 void sqlStatementUseIsNull_189093_data() { generic_data(); } |
203 void sqlStatementUseIsNull_189093(); |
203 void sqlStatementUseIsNull_189093(); |
204 |
204 |
|
205 void sqlite_enable_cache_mode_data() { generic_data("QSQLITE"); } |
|
206 void sqlite_enable_cache_mode(); |
205 |
207 |
206 private: |
208 private: |
207 void createTestTables(QSqlDatabase db); |
209 void createTestTables(QSqlDatabase db); |
208 void dropTestTables(QSqlDatabase db); |
210 void dropTestTables(QSqlDatabase db); |
209 void populateTestTables(QSqlDatabase db); |
211 void populateTestTables(QSqlDatabase db); |
901 QFETCH(QString, dbName); |
903 QFETCH(QString, dbName); |
902 QSqlDatabase db = QSqlDatabase::database(dbName); |
904 QSqlDatabase db = QSqlDatabase::database(dbName); |
903 CHECK_DATABASE(db); |
905 CHECK_DATABASE(db); |
904 |
906 |
905 // runtime check for Oracle version since V8 doesn't support TIMESTAMPs |
907 // runtime check for Oracle version since V8 doesn't support TIMESTAMPs |
906 if (tst_Databases::getOraVersion(db) >= 9) { |
908 if (tst_Databases::getOraVersion(db) >= 9) |
907 qDebug("Detected Oracle >= 9, TIMESTAMP test enabled"); |
909 hasTimeStamp = true; |
908 hasTimeStamp = true; |
|
909 } else { |
|
910 qDebug("Detected Oracle < 9, TIMESTAMP test disabled"); |
|
911 } |
|
912 |
910 |
913 FieldDef tsdef; |
911 FieldDef tsdef; |
914 FieldDef tstzdef; |
912 FieldDef tstzdef; |
915 FieldDef tsltzdef; |
913 FieldDef tsltzdef; |
916 FieldDef intytm; |
914 FieldDef intytm; |
917 FieldDef intdts; |
915 FieldDef intdts; |
918 |
916 |
919 static const QDateTime dt(QDate::currentDate(), QTime(1, 2, 3, 0)); |
917 static const QDateTime dt(QDate::currentDate(), QTime(1, 2, 3, 0)); |
920 |
918 |
921 if (hasTimeStamp) { |
919 if (hasTimeStamp) { |
922 tsdef = FieldDef("timestamp", QVariant::DateTime, dt); |
920 tsdef = FieldDef("timestamp", QVariant::DateTime, dt); |
923 tstzdef = FieldDef("timestamp with time zone", QVariant::DateTime, dt); |
921 tstzdef = FieldDef("timestamp with time zone", QVariant::DateTime, dt); |
924 tsltzdef = FieldDef("timestamp with local time zone", QVariant::DateTime, dt); |
922 tsltzdef = FieldDef("timestamp with local time zone", QVariant::DateTime, dt); |
925 intytm = FieldDef("interval year to month", QVariant::String, QString("+01-01")); |
923 intytm = FieldDef("interval year to month", QVariant::String, QString("+01-01")); |
926 intdts = FieldDef("interval day to second", QVariant::String, QString("+01 00:00:01.000000")); |
924 intdts = FieldDef("interval day to second", QVariant::String, QString("+01 00:00:01.000000")); |
927 } |
925 } |
928 |
926 |
929 const FieldDef fieldDefs[] = { |
927 const FieldDef fieldDefs[] = { |
930 FieldDef("char(20)", QVariant::String, QString("blah1")), |
928 FieldDef("char(20)", QVariant::String, QString("blah1")), |
931 FieldDef("varchar(20)", QVariant::String, QString("blah2")), |
929 FieldDef("varchar(20)", QVariant::String, QString("blah2")), |
936 FieldDef("long raw", QVariant::ByteArray, QByteArray("blah5")), |
934 FieldDef("long raw", QVariant::ByteArray, QByteArray("blah5")), |
937 FieldDef("raw(2000)", QVariant::ByteArray, QByteArray("blah6"), false), |
935 FieldDef("raw(2000)", QVariant::ByteArray, QByteArray("blah6"), false), |
938 FieldDef("blob", QVariant::ByteArray, QByteArray("blah7")), |
936 FieldDef("blob", QVariant::ByteArray, QByteArray("blah7")), |
939 FieldDef("clob", QVariant::String, QString("blah8")), |
937 FieldDef("clob", QVariant::String, QString("blah8")), |
940 FieldDef("nclob", QVariant::String, QString("blah9")), |
938 FieldDef("nclob", QVariant::String, QString("blah9")), |
941 FieldDef("bfile", QVariant::ByteArray, QByteArray("blah10")), |
939 // FieldDef("bfile", QVariant::ByteArray, QByteArray("blah10")), |
942 |
940 |
943 intytm, |
941 intytm, |
944 // intdts, |
942 intdts, |
945 // tsdef, |
943 tsdef, |
946 // tstzdef, |
944 tstzdef, |
947 // tsltzdef, |
945 tsltzdef, |
948 FieldDef() |
946 FieldDef() |
949 }; |
947 }; |
950 |
948 |
951 const int fieldCount = createFieldTable(fieldDefs, db); |
949 const int fieldCount = createFieldTable(fieldDefs, db); |
952 QVERIFY(fieldCount > 0); |
950 QVERIFY(fieldCount > 0); |
953 |
951 |
954 commonFieldTest(fieldDefs, db, fieldCount); |
952 commonFieldTest(fieldDefs, db, fieldCount); |
955 checkNullValues(fieldDefs, db); |
953 checkNullValues(fieldDefs, db); |
956 for (int i = 0; i < ITERATION_COUNT; ++i) { |
954 for (int i = 0; i < ITERATION_COUNT; ++i) |
957 checkValues(fieldDefs, db); |
955 checkValues(fieldDefs, db); |
958 } |
|
959 |
956 |
960 // some additional tests |
957 // some additional tests |
961 QSqlRecord rec = db.record(qTableName("qtestfields")); |
958 QSqlRecord rec = db.record(qTableName("qtestfields")); |
962 QCOMPARE(rec.field("T_NUMBER").length(), 10); |
959 QCOMPARE(rec.field("T_NUMBER").length(), 10); |
963 QCOMPARE(rec.field("T_NUMBER").precision(), 5); |
960 QCOMPARE(rec.field("T_NUMBER").precision(), 5); |
2488 QVERIFY_SQL(q, exec("CREATE TABLE "+systemTableName+"(name VARCHAR(20))")); |
2485 QVERIFY_SQL(q, exec("CREATE TABLE "+systemTableName+"(name VARCHAR(20))")); |
2489 QVERIFY(!db.tables().contains(systemTableName.toUpper())); |
2486 QVERIFY(!db.tables().contains(systemTableName.toUpper())); |
2490 QVERIFY(db.tables(QSql::SystemTables).contains(systemTableName.toUpper())); |
2487 QVERIFY(db.tables(QSql::SystemTables).contains(systemTableName.toUpper())); |
2491 } |
2488 } |
2492 |
2489 |
|
2490 void tst_QSqlDatabase::sqlite_enable_cache_mode() |
|
2491 { |
|
2492 QFETCH(QString, dbName); |
|
2493 if(dbName.endsWith(":memory:")) |
|
2494 QSKIP( "cache mode is meaningless for :memory: databases", SkipSingle ); |
|
2495 QSqlDatabase db = QSqlDatabase::database(dbName); |
|
2496 CHECK_DATABASE(db); |
|
2497 db.close(); |
|
2498 db.setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE"); |
|
2499 QVERIFY_SQL(db, open()); |
|
2500 QSqlDatabase db2 = QSqlDatabase::cloneDatabase(db, dbName+":cachemodeconn2"); |
|
2501 db2.setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE"); |
|
2502 QVERIFY_SQL(db2, open()); |
|
2503 QSqlQuery q(db), q2(db2); |
|
2504 QVERIFY_SQL(q, exec("select * from "+qTableName("qtest"))); |
|
2505 QVERIFY_SQL(q2, exec("select * from "+qTableName("qtest"))); |
|
2506 } |
|
2507 |
2493 QTEST_MAIN(tst_QSqlDatabase) |
2508 QTEST_MAIN(tst_QSqlDatabase) |
2494 #include "tst_qsqldatabase.moc" |
2509 #include "tst_qsqldatabase.moc" |