SQL/Tests: remove safeDropTable() / add helper class
Add a helper class which makes sure that the used table does not exist before usage (e.g. due to leftovers from previous tests) and is properly cleaned up on exit. This also allows to remove all usages of safeDropTable(). Change-Id: Iefeffbd10e2f2f67985183ea822d7b6dd2b80be7 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
f19320748d
commit
18bd15a9ea
@ -72,12 +72,7 @@ inline static QString qTableName(const QString &prefix, const char *sourceFileNa
|
|||||||
|
|
||||||
class tst_Databases
|
class tst_Databases
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
tst_Databases(): counter( 0 )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~tst_Databases()
|
~tst_Databases()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
@ -322,11 +317,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void safeDropTable(QSqlDatabase db, const QString &tableName)
|
|
||||||
{
|
|
||||||
safeDropTables(db, {tableName});
|
|
||||||
}
|
|
||||||
|
|
||||||
static void safeDropViews(QSqlDatabase db, const QStringList &viewNames)
|
static void safeDropViews(QSqlDatabase db, const QStringList &viewNames)
|
||||||
{
|
{
|
||||||
if (isMSAccess(db)) // Access is sooo stupid.
|
if (isMSAccess(db)) // Access is sooo stupid.
|
||||||
@ -481,7 +471,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
QStringList dbNames;
|
QStringList dbNames;
|
||||||
int counter;
|
int counter = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTemporaryDir *dbDir()
|
QTemporaryDir *dbDir()
|
||||||
@ -499,5 +489,33 @@ private:
|
|||||||
QScopedPointer<QTemporaryDir> m_dbDir;
|
QScopedPointer<QTemporaryDir> m_dbDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TableScope
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TableScope(const QSqlDatabase &db, const QString &fullTableName)
|
||||||
|
: m_db(db)
|
||||||
|
, m_tableName(fullTableName)
|
||||||
|
{
|
||||||
|
tst_Databases::safeDropTables(m_db, {m_tableName});
|
||||||
|
}
|
||||||
|
TableScope(const QSqlDatabase &db, const char *tableName, const char *file, bool escape = true)
|
||||||
|
: TableScope(db, qTableName(tableName, file, db, escape))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~TableScope()
|
||||||
|
{
|
||||||
|
tst_Databases::safeDropTables(m_db, {m_tableName});
|
||||||
|
}
|
||||||
|
|
||||||
|
QString tableName() const
|
||||||
|
{
|
||||||
|
return m_tableName;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
QSqlDatabase m_db;
|
||||||
|
QString m_tableName;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ static int createFieldTable(const FieldDef fieldDefs[], QSqlDatabase db)
|
|||||||
{
|
{
|
||||||
QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
||||||
const QString tableName = qTableName("qtestfields", __FILE__, db);
|
const QString tableName = qTableName("qtestfields", __FILE__, db);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
tst_Databases::safeDropTables(db, {tableName});
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
// construct a create table statement consisting of all fieldtypes
|
// construct a create table statement consisting of all fieldtypes
|
||||||
QString qs = "create table " + tableName;
|
QString qs = "create table " + tableName;
|
||||||
@ -1157,12 +1157,11 @@ void tst_QSqlDatabase::caseSensivity()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Explicit test for case sensitive table creation without quoting
|
// Explicit test for case sensitive table creation without quoting
|
||||||
|
TableScope ts(db, "NoQuotes", __FILE__, false);
|
||||||
QSqlQuery qry(db);
|
QSqlQuery qry(db);
|
||||||
const auto noQuotesTable = qTableName("NoQuotes", __FILE__, db, false);
|
QVERIFY_SQL(qry, exec("CREATE TABLE " + ts.tableName() + " (id INTEGER)"));
|
||||||
tst_Databases::safeDropTable(db, noQuotesTable);
|
QVERIFY_SQL(qry, exec("INSERT INTO " + ts.tableName() + " VALUES(1)"));
|
||||||
QVERIFY_SQL(qry, exec("CREATE TABLE " + noQuotesTable + " (id INTEGER)"));
|
QVERIFY_SQL(qry, exec("SELECT * FROM " + ts.tableName()));
|
||||||
QVERIFY_SQL(qry, exec("INSERT INTO " + noQuotesTable + " VALUES(1)"));
|
|
||||||
QVERIFY_SQL(qry, exec("SELECT * FROM " + noQuotesTable));
|
|
||||||
QVERIFY_SQL(qry, next());
|
QVERIFY_SQL(qry, next());
|
||||||
QCOMPARE(qry.value(0).toInt(), 1);
|
QCOMPARE(qry.value(0).toInt(), 1);
|
||||||
// QMYSQLDriver::record() is using a mysql function instead of a query, so quoting
|
// QMYSQLDriver::record() is using a mysql function instead of a query, so quoting
|
||||||
@ -1172,7 +1171,7 @@ void tst_QSqlDatabase::caseSensivity()
|
|||||||
QVERIFY_SQL(qry, next());
|
QVERIFY_SQL(qry, next());
|
||||||
cs = qry.value(1).toInt() != 0;
|
cs = qry.value(1).toInt() != 0;
|
||||||
}
|
}
|
||||||
rec = db.record(cs ? noQuotesTable.toLower() : noQuotesTable);
|
rec = db.record(cs ? ts.tableName().toLower() : ts.tableName());
|
||||||
QVERIFY(rec.count() > 0);
|
QVERIFY(rec.count() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1439,11 +1438,10 @@ void tst_QSqlDatabase::infinityAndNan()
|
|||||||
QSKIP("checking for infinity/nan currently only works for PostgreSQL");
|
QSKIP("checking for infinity/nan currently only works for PostgreSQL");
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
const QString tableName(qTableName("infititytest", __FILE__, db));
|
TableScope ts(db, "infititytest", __FILE__);
|
||||||
tst_Databases::safeDropTables(db, {tableName});
|
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id smallint, val double precision)").arg(ts.tableName())));
|
||||||
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id smallint, val double precision)").arg(tableName)));
|
|
||||||
|
|
||||||
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES (?, ?)").arg(tableName)));
|
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES (?, ?)").arg(ts.tableName())));
|
||||||
|
|
||||||
q.bindValue(0, 1);
|
q.bindValue(0, 1);
|
||||||
q.bindValue(1, qQNaN());
|
q.bindValue(1, qQNaN());
|
||||||
@ -1455,7 +1453,7 @@ void tst_QSqlDatabase::infinityAndNan()
|
|||||||
q.bindValue(1, -qInf());
|
q.bindValue(1, -qInf());
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec(QString("SELECT val FROM %1 ORDER BY id").arg(tableName)));
|
QVERIFY_SQL(q, exec(QString("SELECT val FROM %1 ORDER BY id").arg(ts.tableName())));
|
||||||
|
|
||||||
QVERIFY_SQL(q, next());
|
QVERIFY_SQL(q, next());
|
||||||
QVERIFY(qIsNaN(q.value(0).toDouble()));
|
QVERIFY(qIsNaN(q.value(0).toDouble()));
|
||||||
@ -2105,21 +2103,20 @@ void tst_QSqlDatabase::eventNotificationSQLite()
|
|||||||
QSKIP("QSQLITE specific test");
|
QSKIP("QSQLITE specific test");
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
const QString tableName(qTableName("sqlitnotifytest", __FILE__, db));
|
TableScope ts(db, "sqlitnotifytest", __FILE__);
|
||||||
const auto noEscapeTableName(qTableName("sqlitnotifytest", __FILE__, db, false));
|
TableScope tsEscape(db, "sqlitnotifytest", __FILE__, false);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
|
|
||||||
QSqlDriver *driver = db.driver();
|
QSqlDriver *driver = db.driver();
|
||||||
QSignalSpy spy(driver, QOverload<const QString &, QSqlDriver::NotificationSource, const QVariant &>::of(&QSqlDriver::notification));
|
QSignalSpy spy(driver, QOverload<const QString &, QSqlDriver::NotificationSource, const QVariant &>::of(&QSqlDriver::notification));
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id INTEGER, realVal REAL)"));
|
QVERIFY_SQL(q, exec("CREATE TABLE " + ts.tableName() + " (id INTEGER, realVal REAL)"));
|
||||||
driver->subscribeToNotification(noEscapeTableName);
|
driver->subscribeToNotification(tsEscape.tableName());
|
||||||
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, realVal) VALUES (1, 2.3)"));
|
QVERIFY_SQL(q, exec("INSERT INTO " + ts.tableName() + " (id, realVal) VALUES (1, 2.3)"));
|
||||||
QTRY_COMPARE(spy.size(), 1);
|
QTRY_COMPARE(spy.size(), 1);
|
||||||
QList<QVariant> arguments = spy.takeFirst();
|
QList<QVariant> arguments = spy.takeFirst();
|
||||||
QCOMPARE(arguments.at(0).toString(), noEscapeTableName);
|
QCOMPARE(arguments.at(0).toString(), tsEscape.tableName());
|
||||||
driver->unsubscribeFromNotification(noEscapeTableName);
|
driver->unsubscribeFromNotification(tsEscape.tableName());
|
||||||
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, realVal) VALUES (1, 2.3)"));
|
QVERIFY_SQL(q, exec("INSERT INTO " + ts.tableName() + " (id, realVal) VALUES (1, 2.3)"));
|
||||||
QTRY_COMPARE(spy.size(), 0);
|
QTRY_COMPARE(spy.size(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2288,13 +2285,12 @@ void tst_QSqlDatabase::sqlite_check_json1()
|
|||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
const QString json1("{\"id\":1}");
|
const QString json1("{\"id\":1}");
|
||||||
const QString tableName(qTableName("sqlite_check_json1", __FILE__, db));
|
TableScope ts(db, "sqlite_check_json1", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(text TEXT)").arg(ts.tableName())));
|
||||||
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(text TEXT)").arg(tableName)));
|
QVERIFY_SQL(q, exec(QString("INSERT INTO %1 VALUES(json('%2'))").arg(ts.tableName(), json1)));
|
||||||
QVERIFY_SQL(q, exec(QString("INSERT INTO %1 VALUES(json('%2'))").arg(tableName, json1)));
|
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES(?)").arg(ts.tableName())));
|
||||||
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES(?)").arg(tableName)));
|
|
||||||
q.addBindValue("json('{\"id\":2}')");
|
q.addBindValue("json('{\"id\":2}')");
|
||||||
QVERIFY_SQL(q, prepare(QString("SELECT * from %1 WHERE text = json('%2')").arg(tableName, json1)));
|
QVERIFY_SQL(q, prepare(QString("SELECT * from %1 WHERE text = json('%2')").arg(ts.tableName(), json1)));
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
QVERIFY_SQL(q, next());
|
QVERIFY_SQL(q, next());
|
||||||
QCOMPARE(q.value(0).toString(), json1);
|
QCOMPARE(q.value(0).toString(), json1);
|
||||||
|
@ -52,13 +52,13 @@ void tst_QSqlDriver::initTestCase_data()
|
|||||||
void tst_QSqlDriver::recreateTestTables(QSqlDatabase db)
|
void tst_QSqlDriver::recreateTestTables(QSqlDatabase db)
|
||||||
{
|
{
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
const QString relTEST1(qTableName("relTEST1", __FILE__, db));
|
const QString tableName(qTableName("relTEST1", __FILE__, db));
|
||||||
|
tst_Databases::safeDropTables(db, {tableName});
|
||||||
|
|
||||||
QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
||||||
if (dbType == QSqlDriver::PostgreSQL)
|
if (dbType == QSqlDriver::PostgreSQL)
|
||||||
QVERIFY_SQL( q, exec("set client_min_messages='warning'"));
|
QVERIFY_SQL( q, exec("set client_min_messages='warning'"));
|
||||||
|
|
||||||
tst_Databases::safeDropTable( db, relTEST1 );
|
|
||||||
QString doubleField;
|
QString doubleField;
|
||||||
if (dbType == QSqlDriver::SQLite)
|
if (dbType == QSqlDriver::SQLite)
|
||||||
doubleField = "more_data double";
|
doubleField = "more_data double";
|
||||||
@ -71,12 +71,12 @@ void tst_QSqlDriver::recreateTestTables(QSqlDatabase db)
|
|||||||
else
|
else
|
||||||
doubleField = "more_data double(8,7)";
|
doubleField = "more_data double(8,7)";
|
||||||
const QString defValue(driverSupportsDefaultValues(dbType) ? QStringLiteral("DEFAULT 'defaultVal'") : QString());
|
const QString defValue(driverSupportsDefaultValues(dbType) ? QStringLiteral("DEFAULT 'defaultVal'") : QString());
|
||||||
QVERIFY_SQL( q, exec("create table " + relTEST1 +
|
QVERIFY_SQL( q, exec("create table " + tableName +
|
||||||
" (id int not null primary key, name varchar(20) " + defValue + ", title_key int, another_title_key int, " + doubleField + QLatin1Char(')')));
|
" (id int not null primary key, name varchar(20) " + defValue + ", title_key int, another_title_key int, " + doubleField + QLatin1Char(')')));
|
||||||
QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(1, 'harry', 1, 2, 1.234567)"));
|
QVERIFY_SQL( q, exec("insert into " + tableName + " values(1, 'harry', 1, 2, 1.234567)"));
|
||||||
QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(2, 'trond', 2, 1, 8.901234)"));
|
QVERIFY_SQL( q, exec("insert into " + tableName + " values(2, 'trond', 2, 1, 8.901234)"));
|
||||||
QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(3, 'vohi', 1, 2, 5.678901)"));
|
QVERIFY_SQL( q, exec("insert into " + tableName + " values(3, 'vohi', 1, 2, 5.678901)"));
|
||||||
QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(4, 'boris', 2, 2, 2.345678)"));
|
QVERIFY_SQL( q, exec("insert into " + tableName + " values(4, 'boris', 2, 2, 2.345678)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QSqlDriver::initTestCase()
|
void tst_QSqlDriver::initTestCase()
|
||||||
@ -216,14 +216,14 @@ void tst_QSqlDriver::primaryIndex()
|
|||||||
|
|
||||||
// Test getting a primary index for a table with a clob in it - QTBUG-64427
|
// Test getting a primary index for a table with a clob in it - QTBUG-64427
|
||||||
if (dbType == QSqlDriver::Oracle) {
|
if (dbType == QSqlDriver::Oracle) {
|
||||||
const QString clobTable(qTableName("clobTable", __FILE__, db));
|
TableScope ts(db, "clobTable", __FILE__);
|
||||||
QSqlQuery qry(db);
|
QSqlQuery qry(db);
|
||||||
QVERIFY_SQL(qry, exec("CREATE TABLE " + clobTable + " (id INTEGER, clobField CLOB)"));
|
QVERIFY_SQL(qry, exec("CREATE TABLE " + ts.tableName() + " (id INTEGER, clobField CLOB)"));
|
||||||
QVERIFY_SQL(qry, exec("CREATE UNIQUE INDEX " + clobTable + "IDX ON " + clobTable + " (id)"));
|
QVERIFY_SQL(qry, exec("CREATE UNIQUE INDEX " + ts.tableName() + "IDX ON " + ts.tableName() + " (id)"));
|
||||||
QVERIFY_SQL(qry, exec("ALTER TABLE " + clobTable + " ADD CONSTRAINT " + clobTable +
|
QVERIFY_SQL(qry, exec("ALTER TABLE " + ts.tableName() + " ADD CONSTRAINT " + ts.tableName() +
|
||||||
"PK PRIMARY KEY(id)"));
|
"PK PRIMARY KEY(id)"));
|
||||||
QVERIFY_SQL(qry, exec("ALTER TABLE " + clobTable + " MODIFY (id NOT NULL ENABLE)"));
|
QVERIFY_SQL(qry, exec("ALTER TABLE " + ts.tableName() + " MODIFY (id NOT NULL ENABLE)"));
|
||||||
const QSqlIndex primaryIndex = db.driver()->primaryIndex(clobTable);
|
const QSqlIndex primaryIndex = db.driver()->primaryIndex(ts.tableName());
|
||||||
QCOMPARE(primaryIndex.count(), 1);
|
QCOMPARE(primaryIndex.count(), 1);
|
||||||
QCOMPARE(primaryIndex.fieldName(0), QStringLiteral("ID"));
|
QCOMPARE(primaryIndex.fieldName(0), QStringLiteral("ID"));
|
||||||
}
|
}
|
||||||
|
@ -2491,9 +2491,8 @@ void tst_QSqlQuery::batchExec()
|
|||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
const QString tableName = qTableName("qtest_batch", __FILE__, db);
|
TableScope ts(db, "qtest_batch", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
const auto &tableName = ts.tableName();
|
||||||
|
|
||||||
const auto dbType = tst_Databases::getDatabaseType(db);
|
const auto dbType = tst_Databases::getDatabaseType(db);
|
||||||
QLatin1String timeStampString(dbType == QSqlDriver::Interbase ? "TIMESTAMP" : "TIMESTAMP (3)");
|
QLatin1String timeStampString(dbType == QSqlDriver::Interbase ? "TIMESTAMP" : "TIMESTAMP (3)");
|
||||||
|
|
||||||
@ -2829,13 +2828,13 @@ void tst_QSqlQuery::lastInsertId()
|
|||||||
// PostgreSQL >= 8.1 relies on lastval() which does not work if a value is
|
// PostgreSQL >= 8.1 relies on lastval() which does not work if a value is
|
||||||
// manually inserted to the serial field, so we create a table specifically
|
// manually inserted to the serial field, so we create a table specifically
|
||||||
if (tst_Databases::getDatabaseType(db) == QSqlDriver::PostgreSQL) {
|
if (tst_Databases::getDatabaseType(db) == QSqlDriver::PostgreSQL) {
|
||||||
const auto tst_lastInsertId = qTableName("tst_lastInsertId", __FILE__, db);
|
const auto tableName = qTableName("tst_lastInsertId", __FILE__, db);
|
||||||
tst_Databases::safeDropTable(db, tst_lastInsertId);
|
tst_Databases::safeDropTables(db, {tableName});
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("create table %1 (id serial not null, t_varchar "
|
QVERIFY_SQL(q, exec(QLatin1String("create table %1 (id serial not null, t_varchar "
|
||||||
"varchar(20), t_char char(20), primary key(id))")
|
"varchar(20), t_char char(20), primary key(id))")
|
||||||
.arg(tst_lastInsertId)));
|
.arg(tableName)));
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("insert into %1 (t_varchar, t_char) values "
|
QVERIFY_SQL(q, exec(QLatin1String("insert into %1 (t_varchar, t_char) values "
|
||||||
"('VarChar41', 'Char41')").arg(tst_lastInsertId)));
|
"('VarChar41', 'Char41')").arg(tableName)));
|
||||||
} else {
|
} else {
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("insert into %1 values (41, 'VarChar41', 'Char41')")
|
QVERIFY_SQL(q, exec(QLatin1String("insert into %1 values (41, 'VarChar41', 'Char41')")
|
||||||
.arg(qtest)));
|
.arg(qtest)));
|
||||||
@ -2919,10 +2918,9 @@ void tst_QSqlQuery::psql_specialFloatValues()
|
|||||||
|
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
QSqlQuery query(db);
|
QSqlQuery query(db);
|
||||||
const QString tableName = qTableName("floattest", __FILE__, db);
|
TableScope ts(db, "floattest", __FILE__);
|
||||||
const auto wrapup = qScopeGuard([&]() { tst_Databases::safeDropTable(db, tableName); });
|
QVERIFY_SQL(query, exec(QLatin1String("create table %1 (value float)").arg(ts.tableName())));
|
||||||
QVERIFY_SQL(query, exec(QLatin1String("create table %1 (value float)").arg(tableName)));
|
QVERIFY_SQL(query, prepare(QLatin1String("insert into %1 values(:value)").arg(ts.tableName())));
|
||||||
QVERIFY_SQL(query, prepare(QLatin1String("insert into %1 values(:value)").arg(tableName)));
|
|
||||||
|
|
||||||
const QVariant data[] = {
|
const QVariant data[] = {
|
||||||
QVariant(double(42.42)),
|
QVariant(double(42.42)),
|
||||||
@ -2937,8 +2935,6 @@ void tst_QSqlQuery::psql_specialFloatValues()
|
|||||||
query.bindValue(":value", v);
|
query.bindValue(":value", v);
|
||||||
QVERIFY_SQL(query, exec());
|
QVERIFY_SQL(query, exec());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY_SQL(query, exec("drop table " + tableName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For task 157397: Using QSqlQuery with an invalid QSqlDatabase
|
/* For task 157397: Using QSqlQuery with an invalid QSqlDatabase
|
||||||
@ -3087,11 +3083,10 @@ void tst_QSqlQuery::sqlite_finish()
|
|||||||
db2.setDatabaseName(db.databaseName());
|
db2.setDatabaseName(db.databaseName());
|
||||||
QVERIFY_SQL(db2, open());
|
QVERIFY_SQL(db2, open());
|
||||||
|
|
||||||
const QString tableName(qTableName("qtest_lockedtable", __FILE__, db));
|
TableScope ts(db, "qtest_lockedtable", __FILE__);
|
||||||
const auto wrapup = qScopeGuard([&]() { tst_Databases::safeDropTable(db, tableName); });
|
const auto &tableName = ts.tableName();
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
|
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
q.exec(QLatin1String("CREATE TABLE %1 (pk_id INTEGER PRIMARY KEY, whatever TEXT)")
|
q.exec(QLatin1String("CREATE TABLE %1 (pk_id INTEGER PRIMARY KEY, whatever TEXT)")
|
||||||
.arg(tableName));
|
.arg(tableName));
|
||||||
q.exec(QLatin1String("INSERT INTO %1 values(1, 'whatever')").arg(tableName));
|
q.exec(QLatin1String("INSERT INTO %1 values(1, 'whatever')").arg(tableName));
|
||||||
@ -3420,8 +3415,7 @@ void tst_QSqlQuery::timeStampParsing()
|
|||||||
QFETCH(QString, dbName);
|
QFETCH(QString, dbName);
|
||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
const QString tableName(qTableName("timeStampParsing", __FILE__, db));
|
TableScope ts(db, "timeStampParsing", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QLatin1String creator;
|
QLatin1String creator;
|
||||||
switch (tst_Databases::getDatabaseType(db)) {
|
switch (tst_Databases::getDatabaseType(db)) {
|
||||||
@ -3450,7 +3444,7 @@ void tst_QSqlQuery::timeStampParsing()
|
|||||||
"\"datefield\" timestamp);");
|
"\"datefield\" timestamp);");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QVERIFY_SQL(q, exec(creator.arg(tableName)));
|
QVERIFY_SQL(q, exec(creator.arg(ts.tableName())));
|
||||||
QLatin1String currentTimestamp;
|
QLatin1String currentTimestamp;
|
||||||
if (tst_Databases::getDatabaseType(db) == QSqlDriver::MimerSQL)
|
if (tst_Databases::getDatabaseType(db) == QSqlDriver::MimerSQL)
|
||||||
currentTimestamp = QLatin1String("localtimestamp");
|
currentTimestamp = QLatin1String("localtimestamp");
|
||||||
@ -3458,9 +3452,9 @@ void tst_QSqlQuery::timeStampParsing()
|
|||||||
currentTimestamp = QLatin1String("current_timestamp");
|
currentTimestamp = QLatin1String("current_timestamp");
|
||||||
QVERIFY_SQL(q,
|
QVERIFY_SQL(q,
|
||||||
exec(QLatin1String("INSERT INTO %1 (datefield) VALUES (%2);")
|
exec(QLatin1String("INSERT INTO %1 (datefield) VALUES (%2);")
|
||||||
.arg(tableName)
|
.arg(ts.tableName())
|
||||||
.arg(currentTimestamp)));
|
.arg(currentTimestamp)));
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("SELECT * FROM ") + tableName));
|
QVERIFY_SQL(q, exec(QLatin1String("SELECT * FROM ") + ts.tableName()));
|
||||||
while (q.next())
|
while (q.next())
|
||||||
QVERIFY(q.value(1).toDateTime().isValid());
|
QVERIFY(q.value(1).toDateTime().isValid());
|
||||||
}
|
}
|
||||||
@ -3747,15 +3741,14 @@ void tst_QSqlQuery::QTBUG_5251()
|
|||||||
QFETCH(QString, dbName);
|
QFETCH(QString, dbName);
|
||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
const QString timetest(qTableName("timetest", __FILE__, db));
|
TableScope ts(db, "timetest", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, timetest);
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (t TIME)").arg(timetest)));
|
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (t TIME)").arg(ts.tableName())));
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("INSERT INTO %1 VALUES ('1:2:3.666')").arg(timetest)));
|
QVERIFY_SQL(q, exec(QLatin1String("INSERT INTO %1 VALUES ('1:2:3.666')").arg(ts.tableName())));
|
||||||
|
|
||||||
QSqlTableModel timetestModel(0, db);
|
QSqlTableModel timetestModel(0, db);
|
||||||
timetestModel.setEditStrategy(QSqlTableModel::OnManualSubmit);
|
timetestModel.setEditStrategy(QSqlTableModel::OnManualSubmit);
|
||||||
timetestModel.setTable(timetest);
|
timetestModel.setTable(ts.tableName());
|
||||||
QVERIFY_SQL(timetestModel, select());
|
QVERIFY_SQL(timetestModel, select());
|
||||||
|
|
||||||
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"),
|
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"),
|
||||||
@ -3767,7 +3760,7 @@ void tst_QSqlQuery::QTBUG_5251()
|
|||||||
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"),
|
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"),
|
||||||
u"00:12:34.500");
|
u"00:12:34.500");
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("UPDATE %1 SET t = '0:11:22.33'").arg(timetest)));
|
QVERIFY_SQL(q, exec(QLatin1String("UPDATE %1 SET t = '0:11:22.33'").arg(ts.tableName())));
|
||||||
QVERIFY_SQL(timetestModel, select());
|
QVERIFY_SQL(timetestModel, select());
|
||||||
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"),
|
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"),
|
||||||
u"00:11:22.330");
|
u"00:11:22.330");
|
||||||
@ -4055,16 +4048,15 @@ void tst_QSqlQuery::QTBUG_14904()
|
|||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
|
|
||||||
QString tableName(qTableName("bug14904", __FILE__, db));
|
TableScope ts(db, "bug14904", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
|
|
||||||
q.prepare(QLatin1String("create table %1(val1 bool)").arg(tableName));
|
q.prepare(QLatin1String("create table %1(val1 bool)").arg(ts.tableName()));
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
q.prepare(QLatin1String("insert into %1(val1) values(?);").arg(tableName));
|
q.prepare(QLatin1String("insert into %1(val1) values(?);").arg(ts.tableName()));
|
||||||
q.addBindValue(true);
|
q.addBindValue(true);
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
|
|
||||||
QString sql = "select val1 AS value1 from " + tableName;
|
QString sql = "select val1 AS value1 from " + ts.tableName();
|
||||||
QVERIFY_SQL(q, exec(sql));
|
QVERIFY_SQL(q, exec(sql));
|
||||||
QVERIFY_SQL(q, next());
|
QVERIFY_SQL(q, next());
|
||||||
|
|
||||||
@ -4072,7 +4064,7 @@ void tst_QSqlQuery::QTBUG_14904()
|
|||||||
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Bool);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Bool);
|
||||||
QVERIFY(q.value(0).toBool());
|
QVERIFY(q.value(0).toBool());
|
||||||
|
|
||||||
sql = "select val1 AS 'value.one' from " + tableName;
|
sql = "select val1 AS 'value.one' from " + ts.tableName();
|
||||||
QVERIFY_SQL(q, exec(sql));
|
QVERIFY_SQL(q, exec(sql));
|
||||||
QVERIFY_SQL(q, next());
|
QVERIFY_SQL(q, next());
|
||||||
QCOMPARE(q.record().indexOf("value.one"), 0); // Was -1 before bug fix.
|
QCOMPARE(q.record().indexOf("value.one"), 0); // Was -1 before bug fix.
|
||||||
@ -4086,19 +4078,17 @@ void tst_QSqlQuery::QTBUG_2192()
|
|||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
{
|
{
|
||||||
const QString tableName(qTableName("bug2192", __FILE__, db));
|
TableScope ts(db, "bug2192", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (dt %2)")
|
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (dt %2)")
|
||||||
.arg(tableName, tst_Databases::dateTimeTypeName(db))));
|
.arg(ts.tableName(), tst_Databases::dateTimeTypeName(db))));
|
||||||
|
|
||||||
QDateTime dt = QDateTime(QDate(2012, 7, 4), QTime(23, 59, 59, 999));
|
QDateTime dt = QDateTime(QDate(2012, 7, 4), QTime(23, 59, 59, 999));
|
||||||
QVERIFY_SQL(q, prepare(QLatin1String("INSERT INTO %1 (dt) VALUES (?)").arg(tableName)));
|
QVERIFY_SQL(q, prepare(QLatin1String("INSERT INTO %1 (dt) VALUES (?)").arg(ts.tableName())));
|
||||||
q.bindValue(0, dt);
|
q.bindValue(0, dt);
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("SELECT dt FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT dt FROM " + ts.tableName()));
|
||||||
QVERIFY_SQL(q, next());
|
QVERIFY_SQL(q, next());
|
||||||
|
|
||||||
// Check if retrieved value preserves reported precision
|
// Check if retrieved value preserves reported precision
|
||||||
@ -4115,12 +4105,10 @@ void tst_QSqlQuery::QTBUG_36211()
|
|||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
if (tst_Databases::getDatabaseType(db) == QSqlDriver::PostgreSQL) {
|
if (tst_Databases::getDatabaseType(db) == QSqlDriver::PostgreSQL) {
|
||||||
const QString tableName(qTableName("bug36211", __FILE__, db));
|
TableScope ts(db, "bug36211", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (dtwtz timestamptz, dtwotz timestamp)")
|
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (dtwtz timestamptz, dtwotz timestamp)")
|
||||||
.arg(tableName)));
|
.arg(ts.tableName())));
|
||||||
|
|
||||||
#if QT_CONFIG(timezone)
|
#if QT_CONFIG(timezone)
|
||||||
QTimeZone l_tzBrazil("America/Sao_Paulo");
|
QTimeZone l_tzBrazil("America/Sao_Paulo");
|
||||||
@ -4129,7 +4117,7 @@ void tst_QSqlQuery::QTBUG_36211()
|
|||||||
QVERIFY(l_tzChina.isValid());
|
QVERIFY(l_tzChina.isValid());
|
||||||
QDateTime dt = QDateTime(QDate(2014, 10, 30), QTime(14, 12, 02, 357));
|
QDateTime dt = QDateTime(QDate(2014, 10, 30), QTime(14, 12, 02, 357));
|
||||||
QVERIFY_SQL(q, prepare(QLatin1String("INSERT INTO %1 (dtwtz, dtwotz) VALUES (:dt, :dt)")
|
QVERIFY_SQL(q, prepare(QLatin1String("INSERT INTO %1 (dtwtz, dtwotz) VALUES (:dt, :dt)")
|
||||||
.arg(tableName)));
|
.arg(ts.tableName())));
|
||||||
q.bindValue(":dt", dt);
|
q.bindValue(":dt", dt);
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
q.bindValue(":dt", dt.toTimeZone(l_tzBrazil));
|
q.bindValue(":dt", dt.toTimeZone(l_tzBrazil));
|
||||||
@ -4137,7 +4125,7 @@ void tst_QSqlQuery::QTBUG_36211()
|
|||||||
q.bindValue(":dt", dt.toTimeZone(l_tzChina));
|
q.bindValue(":dt", dt.toTimeZone(l_tzChina));
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("SELECT dtwtz, dtwotz FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT dtwtz, dtwotz FROM " + ts.tableName()));
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
QVERIFY_SQL(q, next());
|
QVERIFY_SQL(q, next());
|
||||||
@ -4163,23 +4151,21 @@ void tst_QSqlQuery::QTBUG_53969()
|
|||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
tableValues.reserve(values.size());
|
tableValues.reserve(values.size());
|
||||||
if (tst_Databases::getDatabaseType(db) == QSqlDriver::MySqlServer) {
|
if (tst_Databases::getDatabaseType(db) == QSqlDriver::MySqlServer) {
|
||||||
const QString tableName(qTableName("bug53969", __FILE__, db));
|
TableScope ts(db, "bug53969", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id INT AUTO_INCREMENT PRIMARY KEY, "
|
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id INT AUTO_INCREMENT PRIMARY KEY, "
|
||||||
"test_number TINYINT(3) UNSIGNED)")
|
"test_number TINYINT(3) UNSIGNED)")
|
||||||
.arg(tableName)));
|
.arg(ts.tableName())));
|
||||||
|
|
||||||
QVERIFY_SQL(q, prepare(QLatin1String("INSERT INTO %1 (test_number) VALUES (:value)")
|
QVERIFY_SQL(q, prepare(QLatin1String("INSERT INTO %1 (test_number) VALUES (:value)")
|
||||||
.arg(tableName)));
|
.arg(ts.tableName())));
|
||||||
|
|
||||||
for (int value : values) {
|
for (int value : values) {
|
||||||
q.bindValue(":value", value);
|
q.bindValue(":value", value);
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY_SQL(q, prepare("SELECT test_number FROM " + tableName));
|
QVERIFY_SQL(q, prepare("SELECT test_number FROM " + ts.tableName()));
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
|
|
||||||
while (q.next()) {
|
while (q.next()) {
|
||||||
@ -4198,15 +4184,14 @@ void tst_QSqlQuery::gisPointDatatype()
|
|||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
QSqlQuery sqlQuery(db);
|
QSqlQuery sqlQuery(db);
|
||||||
const auto tableName = qTableName("qtbug72140", __FILE__, db);
|
TableScope ts(db, "qtbug72140", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
QVERIFY(sqlQuery.exec(QLatin1String(
|
QVERIFY(sqlQuery.exec(QLatin1String(
|
||||||
"CREATE TABLE %1 (`lonlat_point` POINT NULL) ENGINE = InnoDB;")
|
"CREATE TABLE %1 (`lonlat_point` POINT NULL) ENGINE = InnoDB;")
|
||||||
.arg(tableName)));
|
.arg(ts.tableName())));
|
||||||
QVERIFY(sqlQuery.exec(QLatin1String(
|
QVERIFY(sqlQuery.exec(QLatin1String(
|
||||||
"INSERT INTO %1(lonlat_point) VALUES(ST_GeomFromText('POINT(1 1)'));")
|
"INSERT INTO %1(lonlat_point) VALUES(ST_GeomFromText('POINT(1 1)'));")
|
||||||
.arg(tableName)));
|
.arg(ts.tableName())));
|
||||||
QVERIFY(sqlQuery.exec(QLatin1String("SELECT * FROM %1;").arg(tableName)));
|
QVERIFY(sqlQuery.exec(QLatin1String("SELECT * FROM %1;").arg(ts.tableName())));
|
||||||
QCOMPARE(sqlQuery.record().field(0).metaType().id(), QMetaType::QByteArray);
|
QCOMPARE(sqlQuery.record().field(0).metaType().id(), QMetaType::QByteArray);
|
||||||
QVERIFY(sqlQuery.next());
|
QVERIFY(sqlQuery.next());
|
||||||
}
|
}
|
||||||
@ -4332,26 +4317,25 @@ void tst_QSqlQuery::sqlite_real()
|
|||||||
QFETCH(QString, dbName);
|
QFETCH(QString, dbName);
|
||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
const QString tableName(qTableName("sqliterealtype", __FILE__, db));
|
TableScope ts(db, "sqliterealtype", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id INTEGER, realVal REAL)")
|
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id INTEGER, realVal REAL)")
|
||||||
.arg(tableName)));
|
.arg(ts.tableName())));
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("INSERT INTO %1 (id, realVal) VALUES (1, 2.3)")
|
QVERIFY_SQL(q, exec(QLatin1String("INSERT INTO %1 (id, realVal) VALUES (1, 2.3)")
|
||||||
.arg(tableName)));
|
.arg(ts.tableName())));
|
||||||
QVERIFY_SQL(q, exec("SELECT realVal FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT realVal FROM " + ts.tableName()));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
QCOMPARE(q.value(0).toDouble(), 2.3);
|
QCOMPARE(q.value(0).toDouble(), 2.3);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
|
|
||||||
q.prepare(QLatin1String("INSERT INTO %1 (id, realVal) VALUES (?, ?)").arg(tableName));
|
q.prepare(QLatin1String("INSERT INTO %1 (id, realVal) VALUES (?, ?)").arg(ts.tableName()));
|
||||||
QVariant var((double)5.6);
|
QVariant var((double)5.6);
|
||||||
q.addBindValue(4);
|
q.addBindValue(4);
|
||||||
q.addBindValue(var);
|
q.addBindValue(var);
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("SELECT realVal FROM %1 WHERE ID=4").arg(tableName)));
|
QVERIFY_SQL(q, exec(QLatin1String("SELECT realVal FROM %1 WHERE ID=4").arg(ts.tableName())));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
QCOMPARE(q.value(0).toDouble(), 5.6);
|
QCOMPARE(q.value(0).toDouble(), 5.6);
|
||||||
}
|
}
|
||||||
@ -4366,19 +4350,17 @@ void tst_QSqlQuery::prepared_query_json_row()
|
|||||||
QSKIP("PostgreSQL / MySQL specific test");
|
QSKIP("PostgreSQL / MySQL specific test");
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString tableName(qTableName("tableWithJsonRow", __FILE__, db));
|
TableScope ts(db, "tableWithJsonRow", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
const QLatin1String vals[] = {QLatin1String("{\"certificateNumber\": \"CERT-001\"}"),
|
const QLatin1String vals[] = {QLatin1String("{\"certificateNumber\": \"CERT-001\"}"),
|
||||||
QLatin1String("{\"certificateNumber\": \"CERT-002\"}")};
|
QLatin1String("{\"certificateNumber\": \"CERT-002\"}")};
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id INTEGER, value JSON)").arg(tableName)));
|
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id INTEGER, value JSON)").arg(ts.tableName())));
|
||||||
for (const QLatin1String &json : vals) {
|
for (const QLatin1String &json : vals) {
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("INSERT INTO %1 (id, value) VALUES (1, '%2')")
|
QVERIFY_SQL(q, exec(QLatin1String("INSERT INTO %1 (id, value) VALUES (1, '%2')")
|
||||||
.arg(tableName, json)));
|
.arg(ts.tableName(), json)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY_SQL(q, prepare(QLatin1String("SELECT id, value FROM %1 WHERE id = ?").arg(tableName)));
|
QVERIFY_SQL(q, prepare(QLatin1String("SELECT id, value FROM %1 WHERE id = ?").arg(ts.tableName())));
|
||||||
q.addBindValue(1);
|
q.addBindValue(1);
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
|
|
||||||
@ -4413,8 +4395,8 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
countType = QMetaType::LongLong;
|
countType = QMetaType::LongLong;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const QString tableName(qTableName("numericFunctionsWithIntValues", __FILE__, db));
|
TableScope ts(db, "numericFunctionsWithIntValues", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
const auto &tableName = ts.tableName();
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id INTEGER)").arg(tableName)));
|
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id INTEGER)").arg(tableName)));
|
||||||
@ -4463,8 +4445,8 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QCOMPARE(q.record().field(0).metaType().id(), intType);
|
QCOMPARE(q.record().field(0).metaType().id(), intType);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const QString tableName(qTableName("numericFunctionsWithDoubleValues", __FILE__, db));
|
TableScope ts(db, "numericFunctionsWithDoubleValues", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
const auto &tableName = ts.tableName();
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id REAL)").arg(tableName)));
|
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id REAL)").arg(tableName)));
|
||||||
@ -4527,8 +4509,8 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const QString tableName(qTableName("stringFunctions", __FILE__, db));
|
TableScope ts(db, "stringFunctions", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
const auto &tableName = ts.tableName();
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id INTEGER, txt VARCHAR(50))")
|
QVERIFY_SQL(q, exec(QLatin1String("CREATE TABLE %1 (id INTEGER, txt VARCHAR(50))")
|
||||||
@ -4662,14 +4644,13 @@ void tst_QSqlQuery::QTBUG_57138()
|
|||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
QSqlQuery create(db);
|
QSqlQuery create(db);
|
||||||
QString tableName = qTableName("qtbug57138", __FILE__, db);
|
TableScope ts(db, "qtbug57138", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
|
|
||||||
QVERIFY_SQL(create, exec(QLatin1String(
|
QVERIFY_SQL(create, exec(QLatin1String(
|
||||||
"create table %1 (id int, dt_utc datetime, dt_lt datetime, "
|
"create table %1 (id int, dt_utc datetime, dt_lt datetime, "
|
||||||
"dt_tzoffset datetime)").arg(tableName)));
|
"dt_tzoffset datetime)").arg(ts.tableName())));
|
||||||
QVERIFY_SQL(create, prepare(QLatin1String("insert into %1 (id, dt_utc, dt_lt, dt_tzoffset) "
|
QVERIFY_SQL(create, prepare(QLatin1String("insert into %1 (id, dt_utc, dt_lt, dt_tzoffset) "
|
||||||
"values (?, ?, ?, ?)").arg(tableName)));
|
"values (?, ?, ?, ?)").arg(ts.tableName())));
|
||||||
|
|
||||||
create.addBindValue(0);
|
create.addBindValue(0);
|
||||||
create.addBindValue(utc);
|
create.addBindValue(utc);
|
||||||
@ -4679,7 +4660,7 @@ void tst_QSqlQuery::QTBUG_57138()
|
|||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
q.prepare(QLatin1String("SELECT dt_utc, dt_lt, dt_tzoffset FROM %1 WHERE id = ?")
|
q.prepare(QLatin1String("SELECT dt_utc, dt_lt, dt_tzoffset FROM %1 WHERE id = ?")
|
||||||
.arg(tableName));
|
.arg(ts.tableName()));
|
||||||
q.addBindValue(0);
|
q.addBindValue(0);
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
@ -4697,15 +4678,14 @@ void tst_QSqlQuery::QTBUG_73286()
|
|||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
QSqlQuery create(db);
|
QSqlQuery create(db);
|
||||||
QString tableName = qTableName("qtbug73286", __FILE__, db);
|
TableScope ts(db, "qtbug73286", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
|
|
||||||
QVERIFY_SQL(create, exec(QLatin1String(
|
QVERIFY_SQL(create, exec(QLatin1String(
|
||||||
"create table %1 (dec2 decimal(4,2), dec0 decimal(20,0), "
|
"create table %1 (dec2 decimal(4,2), dec0 decimal(20,0), "
|
||||||
"dec3 decimal(20,3))").arg(tableName)));
|
"dec3 decimal(20,3))").arg(ts.tableName())));
|
||||||
QVERIFY_SQL(create, prepare(QLatin1String(
|
QVERIFY_SQL(create, prepare(QLatin1String(
|
||||||
"insert into %1 (dec2, dec0, dec3) values (?, ?, ?)")
|
"insert into %1 (dec2, dec0, dec3) values (?, ?, ?)")
|
||||||
.arg(tableName)));
|
.arg(ts.tableName())));
|
||||||
|
|
||||||
create.addBindValue("99.99");
|
create.addBindValue("99.99");
|
||||||
create.addBindValue("12345678901234567890");
|
create.addBindValue("12345678901234567890");
|
||||||
@ -4714,7 +4694,7 @@ void tst_QSqlQuery::QTBUG_73286()
|
|||||||
QVERIFY_SQL(create, exec());
|
QVERIFY_SQL(create, exec());
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
q.prepare("SELECT dec2, dec0, dec3 FROM " + tableName);
|
q.prepare("SELECT dec2, dec0, dec3 FROM " + ts.tableName());
|
||||||
q.setNumericalPrecisionPolicy(QSql::HighPrecision);
|
q.setNumericalPrecisionPolicy(QSql::HighPrecision);
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
@ -4815,7 +4795,7 @@ void tst_QSqlQuery::dateTime()
|
|||||||
QFETCH(QList<QDateTime>, initialDateTimes);
|
QFETCH(QList<QDateTime>, initialDateTimes);
|
||||||
QFETCH(QList<QDateTime>, expectedDateTimes);
|
QFETCH(QList<QDateTime>, expectedDateTimes);
|
||||||
|
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
TableScope ts(db, tableName);
|
||||||
|
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + createTableString));
|
QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + createTableString));
|
||||||
@ -4881,8 +4861,8 @@ void tst_QSqlQuery::mysql_timeType()
|
|||||||
QFETCH(QString, dbName);
|
QFETCH(QString, dbName);
|
||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
const auto tableName = qTableName("mysqlTimeType", __FILE__, db);
|
TableScope ts(db, "mysqlTimeType", __FILE__);
|
||||||
tst_Databases::safeDropTables(db, { tableName });
|
const auto &tableName = ts.tableName();
|
||||||
QSqlQuery qry(db);
|
QSqlQuery qry(db);
|
||||||
QVERIFY_SQL(qry, exec(QLatin1String("create table %1 (t time(6))").arg(tableName)));
|
QVERIFY_SQL(qry, exec(QLatin1String("create table %1 (t time(6))").arg(tableName)));
|
||||||
|
|
||||||
@ -4943,14 +4923,13 @@ void tst_QSqlQuery::ibaseArray()
|
|||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
const auto arrayTable = qTableName("ibasearray", __FILE__, db);
|
TableScope ts(db, "ibasearray", __FILE__);
|
||||||
tst_Databases::safeDropTable(db, arrayTable);
|
|
||||||
QSqlQuery qry(db);
|
QSqlQuery qry(db);
|
||||||
QVERIFY_SQL(qry, exec(QLatin1String(
|
QVERIFY_SQL(qry, exec(QLatin1String(
|
||||||
"create table %1 (intData int[0:4], longData bigint[5], "
|
"create table %1 (intData int[0:4], longData bigint[5], "
|
||||||
"charData varchar(255)[5], boolData boolean[2])").arg(arrayTable)));
|
"charData varchar(255)[5], boolData boolean[2])").arg(ts.tableName())));
|
||||||
QVERIFY_SQL(qry, prepare(QLatin1String("insert into %1 (intData, longData, charData, boolData)"
|
QVERIFY_SQL(qry, prepare(QLatin1String("insert into %1 (intData, longData, charData, boolData)"
|
||||||
" values(?, ?, ?, ?)").arg(arrayTable)));
|
" values(?, ?, ?, ?)").arg(ts.tableName())));
|
||||||
const auto intArray = QVariant{QVariantList{1, 2, 3, 4711, 815}};
|
const auto intArray = QVariant{QVariantList{1, 2, 3, 4711, 815}};
|
||||||
const auto charArray = QVariant{QVariantList{"AAA", "BBB", "CCC", "DDD", "EEE"}};
|
const auto charArray = QVariant{QVariantList{"AAA", "BBB", "CCC", "DDD", "EEE"}};
|
||||||
const auto boolArray = QVariant{QVariantList{true, false}};
|
const auto boolArray = QVariant{QVariantList{true, false}};
|
||||||
@ -4959,7 +4938,7 @@ void tst_QSqlQuery::ibaseArray()
|
|||||||
qry.bindValue(2, charArray);
|
qry.bindValue(2, charArray);
|
||||||
qry.bindValue(3, boolArray);
|
qry.bindValue(3, boolArray);
|
||||||
QVERIFY_SQL(qry, exec());
|
QVERIFY_SQL(qry, exec());
|
||||||
QVERIFY_SQL(qry, exec("select * from " + arrayTable));
|
QVERIFY_SQL(qry, exec("select * from " + ts.tableName()));
|
||||||
QVERIFY(qry.next());
|
QVERIFY(qry.next());
|
||||||
QCOMPARE(qry.value(0).toList(), intArray.toList());
|
QCOMPARE(qry.value(0).toList(), intArray.toList());
|
||||||
QCOMPARE(qry.value(1).toList(), intArray.toList());
|
QCOMPARE(qry.value(1).toList(), intArray.toList());
|
||||||
|
@ -1939,14 +1939,16 @@ void tst_QSqlTableModel::sqlite_attachedDatabase()
|
|||||||
attachedDb.setDatabaseName(db.databaseName()+QLatin1String("attached.dat"));
|
attachedDb.setDatabaseName(db.databaseName()+QLatin1String("attached.dat"));
|
||||||
QVERIFY_SQL(attachedDb, open());
|
QVERIFY_SQL(attachedDb, open());
|
||||||
QSqlQuery q(attachedDb);
|
QSqlQuery q(attachedDb);
|
||||||
tst_Databases::safeDropTables(attachedDb, QStringList() << "atest" << "atest2");
|
TableScope ts(db, "atest", __FILE__);
|
||||||
|
TableScope tsAttached(attachedDb, "atest", __FILE__);
|
||||||
|
TableScope tsAttached2(attachedDb, "atest2", __FILE__);
|
||||||
|
|
||||||
QVERIFY_SQL( q, exec("CREATE TABLE atest(id int, text varchar(20))"));
|
QVERIFY_SQL( q, exec("CREATE TABLE atest(id int, text varchar(20))"));
|
||||||
QVERIFY_SQL( q, exec("CREATE TABLE atest2(id int, text varchar(20))"));
|
QVERIFY_SQL( q, exec("CREATE TABLE atest2(id int, text varchar(20))"));
|
||||||
QVERIFY_SQL( q, exec("INSERT INTO atest VALUES(1, 'attached-atest')"));
|
QVERIFY_SQL( q, exec("INSERT INTO atest VALUES(1, 'attached-atest')"));
|
||||||
QVERIFY_SQL( q, exec("INSERT INTO atest2 VALUES(2, 'attached-atest2')"));
|
QVERIFY_SQL( q, exec("INSERT INTO atest2 VALUES(2, 'attached-atest2')"));
|
||||||
|
|
||||||
QSqlQuery q2(db);
|
QSqlQuery q2(db);
|
||||||
tst_Databases::safeDropTable(db, "atest");
|
|
||||||
QVERIFY_SQL(q2, exec("CREATE TABLE atest(id int, text varchar(20))"));
|
QVERIFY_SQL(q2, exec("CREATE TABLE atest(id int, text varchar(20))"));
|
||||||
QVERIFY_SQL(q2, exec("INSERT INTO atest VALUES(3, 'main')"));
|
QVERIFY_SQL(q2, exec("INSERT INTO atest VALUES(3, 'main')"));
|
||||||
QVERIFY_SQL(q2, exec("ATTACH DATABASE \""+attachedDb.databaseName()+"\" as adb"));
|
QVERIFY_SQL(q2, exec("ATTACH DATABASE \""+attachedDb.databaseName()+"\" as adb"));
|
||||||
@ -2137,29 +2139,27 @@ void tst_QSqlTableModel::sqlite_selectFromIdentifierWithDot()
|
|||||||
{
|
{
|
||||||
QFETCH(QString, dbName);
|
QFETCH(QString, dbName);
|
||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
|
TableScope fieldDot(db, "fieldDot", __FILE__);
|
||||||
|
TableScope tableDot(db, u'[' + qTableName("table.dot", __FILE__, db) + u']');
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
{
|
{
|
||||||
const auto fieldDot = qTableName("fieldDot", __FILE__, db);
|
|
||||||
tst_Databases::safeDropTable(db, fieldDot);
|
|
||||||
QSqlQuery qry(db);
|
QSqlQuery qry(db);
|
||||||
QVERIFY_SQL(qry, exec("create table " + fieldDot + " (id int primary key, "
|
QVERIFY_SQL(qry, exec("create table " + fieldDot.tableName() + " (id int primary key, "
|
||||||
"\"person.firstname\" varchar(20))"));
|
"\"person.firstname\" varchar(20))"));
|
||||||
QVERIFY_SQL(qry, exec("insert into " + fieldDot + " values(1, 'Andy')"));
|
QVERIFY_SQL(qry, exec("insert into " + fieldDot.tableName() + " values(1, 'Andy')"));
|
||||||
QSqlTableModel model(0, db);
|
QSqlTableModel model(0, db);
|
||||||
model.setTable(fieldDot);
|
model.setTable(fieldDot.tableName());
|
||||||
QVERIFY_SQL(model, select());
|
QVERIFY_SQL(model, select());
|
||||||
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
|
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
|
||||||
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("Andy"));
|
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("Andy"));
|
||||||
}
|
}
|
||||||
const auto tableDot = QLatin1Char('[') + qTableName("table.dot", __FILE__, db) + QLatin1Char(']');
|
|
||||||
{
|
{
|
||||||
tst_Databases::safeDropTable(db, tableDot);
|
|
||||||
QSqlQuery qry(db);
|
QSqlQuery qry(db);
|
||||||
QVERIFY_SQL(qry, exec("create table " + tableDot + " (id int primary key, "
|
QVERIFY_SQL(qry, exec("create table " + tableDot.tableName() + " (id int primary key, "
|
||||||
"\"person.firstname\" varchar(20))"));
|
"\"person.firstname\" varchar(20))"));
|
||||||
QVERIFY_SQL(qry, exec("insert into " + tableDot + " values(1, 'Andy')"));
|
QVERIFY_SQL(qry, exec("insert into " + tableDot.tableName() + " values(1, 'Andy')"));
|
||||||
QSqlTableModel model(0, db);
|
QSqlTableModel model(0, db);
|
||||||
model.setTable(tableDot);
|
model.setTable(tableDot.tableName());
|
||||||
QVERIFY_SQL(model, select());
|
QVERIFY_SQL(model, select());
|
||||||
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
|
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
|
||||||
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("Andy"));
|
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("Andy"));
|
||||||
@ -2171,7 +2171,7 @@ void tst_QSqlTableModel::sqlite_selectFromIdentifierWithDot()
|
|||||||
QSqlQuery qry(attachedDb);
|
QSqlQuery qry(attachedDb);
|
||||||
QVERIFY_SQL(qry, exec(QString("attach '%1' AS 'attached'").arg(db.databaseName())));
|
QVERIFY_SQL(qry, exec(QString("attach '%1' AS 'attached'").arg(db.databaseName())));
|
||||||
QSqlTableModel model(0, attachedDb);
|
QSqlTableModel model(0, attachedDb);
|
||||||
model.setTable(QString("attached.%1").arg(tableDot));
|
model.setTable(QString("attached.%1").arg(tableDot.tableName()));
|
||||||
QVERIFY_SQL(model, select());
|
QVERIFY_SQL(model, select());
|
||||||
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
|
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
|
||||||
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("Andy"));
|
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("Andy"));
|
||||||
|
@ -13,8 +13,7 @@ class tst_QSqlQuery : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
tst_QSqlQuery();
|
using QObject::QObject;
|
||||||
virtual ~tst_QSqlQuery();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
@ -40,20 +39,12 @@ private:
|
|||||||
|
|
||||||
QTEST_MAIN(tst_QSqlQuery)
|
QTEST_MAIN(tst_QSqlQuery)
|
||||||
|
|
||||||
tst_QSqlQuery::tst_QSqlQuery()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
tst_QSqlQuery::~tst_QSqlQuery()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QSqlQuery::initTestCase()
|
void tst_QSqlQuery::initTestCase()
|
||||||
{
|
{
|
||||||
dbs.open();
|
dbs.open();
|
||||||
|
|
||||||
for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) {
|
for (const auto &dbName : std::as_const(dbs.dbNames)) {
|
||||||
QSqlDatabase db = QSqlDatabase::database(( *it ) );
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE( db );
|
CHECK_DATABASE( db );
|
||||||
dropTestTables( db ); //in case of leftovers
|
dropTestTables( db ); //in case of leftovers
|
||||||
createTestTables( db );
|
createTestTables( db );
|
||||||
@ -63,8 +54,8 @@ void tst_QSqlQuery::initTestCase()
|
|||||||
|
|
||||||
void tst_QSqlQuery::cleanupTestCase()
|
void tst_QSqlQuery::cleanupTestCase()
|
||||||
{
|
{
|
||||||
for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) {
|
for (const auto &dbName : std::as_const(dbs.dbNames)) {
|
||||||
QSqlDatabase db = QSqlDatabase::database(( *it ) );
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE( db );
|
CHECK_DATABASE( db );
|
||||||
dropTestTables( db );
|
dropTestTables( db );
|
||||||
}
|
}
|
||||||
@ -153,18 +144,17 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
|
|||||||
if (dbType == QSqlDriver::MSSqlServer || dbType == QSqlDriver::Oracle)
|
if (dbType == QSqlDriver::MSSqlServer || dbType == QSqlDriver::Oracle)
|
||||||
tablenames << qTableName("qtest_longstr", __FILE__, db);
|
tablenames << qTableName("qtest_longstr", __FILE__, db);
|
||||||
|
|
||||||
|
QSqlQuery q(db);
|
||||||
if (dbType == QSqlDriver::MSSqlServer)
|
if (dbType == QSqlDriver::MSSqlServer)
|
||||||
db.exec("DROP PROCEDURE " + qTableName("test141895_proc", __FILE__, db));
|
q.exec("DROP PROCEDURE " + qTableName("test141895_proc", __FILE__, db));
|
||||||
|
|
||||||
if (dbType == QSqlDriver::MySqlServer)
|
if (dbType == QSqlDriver::MySqlServer)
|
||||||
db.exec("DROP PROCEDURE IF EXISTS "+qTableName("bug6852_proc", __FILE__, db));
|
q.exec("DROP PROCEDURE IF EXISTS "+qTableName("bug6852_proc", __FILE__, db));
|
||||||
|
|
||||||
tst_Databases::safeDropTables( db, tablenames );
|
tst_Databases::safeDropTables( db, tablenames );
|
||||||
|
|
||||||
if (dbType == QSqlDriver::Oracle) {
|
if (dbType == QSqlDriver::Oracle)
|
||||||
QSqlQuery q( db );
|
|
||||||
q.exec("DROP PACKAGE " + qTableName("pkg", __FILE__, db));
|
q.exec("DROP PACKAGE " + qTableName("pkg", __FILE__, db));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QSqlQuery::createTestTables( QSqlDatabase db )
|
void tst_QSqlQuery::createTestTables( QSqlDatabase db )
|
||||||
@ -214,11 +204,9 @@ void tst_QSqlQuery::benchmark()
|
|||||||
QSqlDatabase db = QSqlDatabase::database( dbName );
|
QSqlDatabase db = QSqlDatabase::database( dbName );
|
||||||
CHECK_DATABASE( db );
|
CHECK_DATABASE( db );
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
const QString tableName(qTableName("benchmark", __FILE__, db));
|
TableScope ts(db, "benchmark", __FILE__);
|
||||||
|
|
||||||
tst_Databases::safeDropTable( db, tableName );
|
QVERIFY_SQL(q, exec("CREATE TABLE " + ts.tableName() + "(\n"
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("CREATE TABLE "+tableName+"(\n"
|
|
||||||
"MainKey INT NOT NULL,\n"
|
"MainKey INT NOT NULL,\n"
|
||||||
"OtherTextCol VARCHAR(45) NOT NULL,\n"
|
"OtherTextCol VARCHAR(45) NOT NULL,\n"
|
||||||
"PRIMARY KEY(`MainKey`))"));
|
"PRIMARY KEY(`MainKey`))"));
|
||||||
@ -226,11 +214,10 @@ void tst_QSqlQuery::benchmark()
|
|||||||
int i=1;
|
int i=1;
|
||||||
|
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" VALUES("+QString::number(i)+", \"Value"+QString::number(i)+"\")"));
|
const QString num = QString::number(i);
|
||||||
|
QVERIFY_SQL(q, exec("INSERT INTO " + ts.tableName() + " VALUES(" + num + ", \"Value" + num + "\")"));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
tst_Databases::safeDropTable( db, tableName );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QSqlQuery::benchmarkSelectPrepared()
|
void tst_QSqlQuery::benchmarkSelectPrepared()
|
||||||
@ -239,22 +226,20 @@ void tst_QSqlQuery::benchmarkSelectPrepared()
|
|||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
const QString tableName(qTableName("benchmark", __FILE__, db));
|
TableScope ts(db, "benchmark", __FILE__);
|
||||||
|
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
QVERIFY_SQL(q, exec("CREATE TABLE " + ts.tableName() + "(id INT NOT NULL)"));
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + "(id INT NOT NULL)"));
|
|
||||||
|
|
||||||
const int NUM_ROWS = 1000;
|
const int NUM_ROWS = 1000;
|
||||||
int expectedSum = 0;
|
int expectedSum = 0;
|
||||||
QString fillQuery = "INSERT INTO " + tableName + " VALUES (0)";
|
QString fillQuery = "INSERT INTO " + ts.tableName() + " VALUES (0)";
|
||||||
for (int i = 1; i < NUM_ROWS; ++i) {
|
for (int i = 1; i < NUM_ROWS; ++i) {
|
||||||
fillQuery += ", (" + QString::number(i) + QLatin1Char(')');
|
fillQuery += ", (" + QString::number(i) + QLatin1Char(')');
|
||||||
expectedSum += i;
|
expectedSum += i;
|
||||||
}
|
}
|
||||||
QVERIFY_SQL(q, exec(fillQuery));
|
QVERIFY_SQL(q, exec(fillQuery));
|
||||||
|
|
||||||
QVERIFY_SQL(q, prepare("SELECT id FROM "+tableName));
|
QVERIFY_SQL(q, prepare("SELECT id FROM " + ts.tableName()));
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
@ -264,8 +249,6 @@ void tst_QSqlQuery::benchmarkSelectPrepared()
|
|||||||
|
|
||||||
QCOMPARE(sum, expectedSum);
|
QCOMPARE(sum, expectedSum);
|
||||||
}
|
}
|
||||||
|
|
||||||
tst_Databases::safeDropTable(db, tableName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "main.moc"
|
#include "main.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user