SQL/Benchmarks: cleanup
The benchmarks were only copied from the tests without a proper cleanup - therefore clean them up now. Change-Id: I0285de3fd2b67c21e732d7f3f9d1f4937965be81 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
db705d0794
commit
dbcad6392b
@ -6,8 +6,6 @@
|
||||
|
||||
#include "../../../../auto/sql/kernel/qsqldatabase/tst_databases.h"
|
||||
|
||||
const QString qtest(qTableName("qtest", __FILE__, QSqlDatabase()));
|
||||
|
||||
class tst_QSqlQuery : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -29,10 +27,7 @@ private slots:
|
||||
|
||||
private:
|
||||
// returns all database connections
|
||||
void generic_data(const QString &engine=QString());
|
||||
void dropTestTables( QSqlDatabase db );
|
||||
void createTestTables( QSqlDatabase db );
|
||||
void populateTestTables( QSqlDatabase db );
|
||||
void generic_data(const QString &engine = QString());
|
||||
|
||||
tst_Databases dbs;
|
||||
};
|
||||
@ -42,24 +37,10 @@ QTEST_MAIN(tst_QSqlQuery)
|
||||
void tst_QSqlQuery::initTestCase()
|
||||
{
|
||||
dbs.open();
|
||||
|
||||
for (const auto &dbName : std::as_const(dbs.dbNames)) {
|
||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||
CHECK_DATABASE( db );
|
||||
dropTestTables( db ); //in case of leftovers
|
||||
createTestTables( db );
|
||||
populateTestTables( db );
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSqlQuery::cleanupTestCase()
|
||||
{
|
||||
for (const auto &dbName : std::as_const(dbs.dbNames)) {
|
||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||
CHECK_DATABASE( db );
|
||||
dropTestTables( db );
|
||||
}
|
||||
|
||||
dbs.close();
|
||||
}
|
||||
|
||||
@ -69,29 +50,11 @@ void tst_QSqlQuery::init()
|
||||
|
||||
void tst_QSqlQuery::cleanup()
|
||||
{
|
||||
QFETCH( QString, dbName );
|
||||
QSqlDatabase db = QSqlDatabase::database( dbName );
|
||||
CHECK_DATABASE( db );
|
||||
const QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
||||
|
||||
if ( QTest::currentTestFunction() == QLatin1String( "numRowsAffected" )
|
||||
|| QTest::currentTestFunction() == QLatin1String( "transactions" )
|
||||
|| QTest::currentTestFunction() == QLatin1String( "size" )
|
||||
|| QTest::currentTestFunction() == QLatin1String( "isActive" )
|
||||
|| QTest::currentTestFunction() == QLatin1String( "lastInsertId" ) ) {
|
||||
populateTestTables( db );
|
||||
}
|
||||
|
||||
if (QTest::currentTestFailed() && (dbType == QSqlDriver::Oracle || db.driverName().startsWith("QODBC"))) {
|
||||
//since Oracle ODBC totally craps out on error, we init again
|
||||
db.close();
|
||||
db.open();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSqlQuery::generic_data(const QString& engine)
|
||||
void tst_QSqlQuery::generic_data(const QString &engine)
|
||||
{
|
||||
if ( dbs.fillTestTable(engine) == 0 ) {
|
||||
if (dbs.fillTestTable(engine) == 0) {
|
||||
if (engine.isEmpty())
|
||||
QSKIP( "No database drivers are available in this Qt configuration");
|
||||
else
|
||||
@ -99,130 +62,31 @@ void tst_QSqlQuery::generic_data(const QString& engine)
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
|
||||
{
|
||||
QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
||||
QStringList tablenames;
|
||||
// drop all the table in case a testcase failed
|
||||
tablenames << qtest
|
||||
<< qTableName("qtest_null", __FILE__, db)
|
||||
<< qTableName("qtest_blob", __FILE__, db)
|
||||
<< qTableName("qtest_bittest", __FILE__, db)
|
||||
<< qTableName("qtest_nullblob", __FILE__, db)
|
||||
<< qTableName("qtest_rawtest", __FILE__, db)
|
||||
<< qTableName("qtest_precision", __FILE__, db)
|
||||
<< qTableName("qtest_prepare", __FILE__, db)
|
||||
<< qTableName("qtestj1", __FILE__, db)
|
||||
<< qTableName("qtestj2", __FILE__, db)
|
||||
<< qTableName("char1Select", __FILE__, db)
|
||||
<< qTableName("char1SU", __FILE__, db)
|
||||
<< qTableName("qxmltest", __FILE__, db)
|
||||
<< qTableName("qtest_exerr", __FILE__, db)
|
||||
<< qTableName("qtest_empty", __FILE__, db)
|
||||
<< qTableName("clobby", __FILE__, db)
|
||||
<< qTableName("bindtest", __FILE__, db)
|
||||
<< qTableName("more_results", __FILE__, db)
|
||||
<< qTableName("blobstest", __FILE__, db)
|
||||
<< qTableName("oraRowId", __FILE__, db)
|
||||
<< qTableName("qtest_batch", __FILE__, db)
|
||||
<< qTableName("bug6421", __FILE__, db).toUpper()
|
||||
<< qTableName("bug5765", __FILE__, db)
|
||||
<< qTableName("bug6852", __FILE__, db)
|
||||
<< qTableName("qtest_lockedtable", __FILE__, db)
|
||||
<< qTableName("Planet", __FILE__, db)
|
||||
<< qTableName("task_250026", __FILE__, db)
|
||||
<< qTableName("task_234422", __FILE__, db)
|
||||
<< qTableName("test141895", __FILE__, db)
|
||||
<< qTableName("qtest_oraOCINumber", __FILE__, db);
|
||||
|
||||
if (dbType == QSqlDriver::PostgreSQL)
|
||||
tablenames << qTableName("task_233829", __FILE__, db);
|
||||
|
||||
if (dbType == QSqlDriver::SQLite)
|
||||
tablenames << qTableName("record_sqlite", __FILE__, db);
|
||||
|
||||
if (dbType == QSqlDriver::MSSqlServer || dbType == QSqlDriver::Oracle)
|
||||
tablenames << qTableName("qtest_longstr", __FILE__, db);
|
||||
|
||||
QSqlQuery q(db);
|
||||
if (dbType == QSqlDriver::MSSqlServer)
|
||||
q.exec("DROP PROCEDURE " + qTableName("test141895_proc", __FILE__, db));
|
||||
|
||||
if (dbType == QSqlDriver::MySqlServer)
|
||||
q.exec("DROP PROCEDURE IF EXISTS "+qTableName("bug6852_proc", __FILE__, db));
|
||||
|
||||
tst_Databases::safeDropTables( db, tablenames );
|
||||
|
||||
if (dbType == QSqlDriver::Oracle)
|
||||
q.exec("DROP PACKAGE " + qTableName("pkg", __FILE__, db));
|
||||
}
|
||||
|
||||
void tst_QSqlQuery::createTestTables( QSqlDatabase db )
|
||||
{
|
||||
const QString qtestNull = qTableName("qtest_null", __FILE__, db);
|
||||
QSqlQuery q( db );
|
||||
QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
||||
if (dbType == QSqlDriver::MySqlServer)
|
||||
// ### stupid workaround until we find a way to hardcode this
|
||||
// in the MySQL server startup script
|
||||
q.exec( "set table_type=innodb" );
|
||||
else if (dbType == QSqlDriver::PostgreSQL)
|
||||
QVERIFY_SQL( q, exec("set client_min_messages='warning'"));
|
||||
|
||||
if (dbType == QSqlDriver::PostgreSQL)
|
||||
QVERIFY_SQL( q, exec( "create table " + qtest + " (id serial NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id)) WITH OIDS" ) );
|
||||
else
|
||||
QVERIFY_SQL( q, exec( "create table " + qtest + " (id int "+tst_Databases::autoFieldName(db) +" NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id))" ) );
|
||||
|
||||
if (dbType == QSqlDriver::MSSqlServer || dbType == QSqlDriver::Sybase)
|
||||
QVERIFY_SQL(q, exec("create table " + qtestNull + " (id int null, t_varchar varchar(20) null)"));
|
||||
else
|
||||
QVERIFY_SQL(q, exec("create table " + qtestNull + " (id int, t_varchar varchar(20))"));
|
||||
}
|
||||
|
||||
void tst_QSqlQuery::populateTestTables( QSqlDatabase db )
|
||||
{
|
||||
QSqlQuery q( db );
|
||||
const QString qtest_null(qTableName("qtest_null", __FILE__, db));
|
||||
q.exec( "delete from " + qtest );
|
||||
QVERIFY_SQL( q, exec( "insert into " + qtest + " values (1, 'VarChar1', 'Char1')" ) );
|
||||
QVERIFY_SQL( q, exec( "insert into " + qtest + " values (2, 'VarChar2', 'Char2')" ) );
|
||||
QVERIFY_SQL( q, exec( "insert into " + qtest + " values (3, 'VarChar3', 'Char3')" ) );
|
||||
QVERIFY_SQL( q, exec( "insert into " + qtest + " values (4, 'VarChar4', 'Char4')" ) );
|
||||
QVERIFY_SQL( q, exec( "insert into " + qtest + " values (5, 'VarChar5', 'Char5')" ) );
|
||||
|
||||
q.exec( "delete from " + qtest_null );
|
||||
QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (0, NULL)" ) );
|
||||
QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (1, 'n')" ) );
|
||||
QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (2, 'i')" ) );
|
||||
QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (3, NULL)" ) );
|
||||
}
|
||||
|
||||
void tst_QSqlQuery::benchmark()
|
||||
{
|
||||
QFETCH( QString, dbName );
|
||||
QSqlDatabase db = QSqlDatabase::database( dbName );
|
||||
CHECK_DATABASE( db );
|
||||
QFETCH(QString, dbName);
|
||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||
CHECK_DATABASE(db);
|
||||
QSqlQuery q(db);
|
||||
TableScope ts(db, "benchmark", __FILE__);
|
||||
|
||||
QVERIFY_SQL(q, exec("CREATE TABLE " + ts.tableName() + "(\n"
|
||||
"MainKey INT NOT NULL,\n"
|
||||
"OtherTextCol VARCHAR(45) NOT NULL,\n"
|
||||
"PRIMARY KEY(`MainKey`))"));
|
||||
"PRIMARY KEY(MainKey))"));
|
||||
|
||||
int i=1;
|
||||
|
||||
QBENCHMARK {
|
||||
const QString num = QString::number(i);
|
||||
QVERIFY_SQL(q, exec("INSERT INTO " + ts.tableName() + " VALUES(" + num + ", \"Value" + num + "\")"));
|
||||
QVERIFY_SQL(q, exec("INSERT INTO " + ts.tableName() + " VALUES(" + num + ", 'Value" + num + "')"));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSqlQuery::benchmarkSelectPrepared()
|
||||
{
|
||||
QFETCH( QString, dbName );
|
||||
QFETCH(QString, dbName);
|
||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||
CHECK_DATABASE(db);
|
||||
QSqlQuery q(db);
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
#include "../../../../auto/sql/kernel/qsqldatabase/tst_databases.h"
|
||||
|
||||
const QString qtest(qTableName("qtest", __FILE__, QSqlDatabase()));
|
||||
|
||||
class tst_QSqlRecord : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -27,9 +25,6 @@ private slots:
|
||||
|
||||
private:
|
||||
void generic_data(const QString &engine = QString());
|
||||
void dropTestTables(QSqlDatabase db);
|
||||
void createTestTables(QSqlDatabase db);
|
||||
void populateTestTables(QSqlDatabase db);
|
||||
|
||||
tst_Databases dbs;
|
||||
};
|
||||
@ -39,38 +34,15 @@ QTEST_MAIN(tst_QSqlRecord)
|
||||
void tst_QSqlRecord::initTestCase()
|
||||
{
|
||||
dbs.open();
|
||||
for (const auto &dbName : std::as_const(dbs.dbNames)) {
|
||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||
CHECK_DATABASE(db);
|
||||
dropTestTables(db); // In case of leftovers
|
||||
createTestTables(db);
|
||||
populateTestTables(db);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSqlRecord::cleanupTestCase()
|
||||
{
|
||||
for (const auto &dbName : std::as_const(dbs.dbNames)) {
|
||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||
CHECK_DATABASE(db);
|
||||
dropTestTables(db);
|
||||
}
|
||||
dbs.close();
|
||||
}
|
||||
|
||||
void tst_QSqlRecord::cleanup()
|
||||
{
|
||||
QFETCH(QString, dbName);
|
||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||
CHECK_DATABASE(db);
|
||||
const QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
||||
|
||||
if (QTest::currentTestFailed() && (dbType == QSqlDriver::Oracle ||
|
||||
db.driverName().startsWith("QODBC"))) {
|
||||
// Since Oracle ODBC has a problem when encountering an error, we init again
|
||||
db.close();
|
||||
db.open();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSqlRecord::generic_data(const QString &engine)
|
||||
@ -83,74 +55,28 @@ void tst_QSqlRecord::generic_data(const QString &engine)
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSqlRecord::dropTestTables(QSqlDatabase db)
|
||||
{
|
||||
QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
||||
QStringList tablenames;
|
||||
// drop all the tables in case a testcase failed
|
||||
tablenames << qtest
|
||||
<< qTableName("record", __FILE__, db);
|
||||
tst_Databases::safeDropTables(db, tablenames);
|
||||
|
||||
if (dbType == QSqlDriver::Oracle) {
|
||||
QSqlQuery q(db);
|
||||
q.exec("DROP PACKAGE " + qTableName("pkg", __FILE__, db));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSqlRecord::createTestTables(QSqlDatabase db)
|
||||
{
|
||||
QSqlQuery q(db);
|
||||
switch (tst_Databases::getDatabaseType(db)) {
|
||||
case QSqlDriver::PostgreSQL:
|
||||
QVERIFY_SQL(q, exec("set client_min_messages='warning'"));
|
||||
QVERIFY_SQL(q, exec("create table " + qtest + " (id serial NOT NULL, t_varchar varchar(20), "
|
||||
"t_char char(20), primary key(id)) WITH OIDS"));
|
||||
break;
|
||||
case QSqlDriver::MySqlServer:
|
||||
QVERIFY_SQL(q, exec("set table_type=innodb"));
|
||||
Q_FALLTHROUGH();
|
||||
default:
|
||||
QVERIFY_SQL(q, exec("create table " + qtest + " (id int " + tst_Databases::autoFieldName(db) +
|
||||
" NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id))"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSqlRecord::populateTestTables(QSqlDatabase db)
|
||||
{
|
||||
QSqlQuery q(db);
|
||||
QVERIFY_SQL(q, exec("delete from " + qtest));
|
||||
QVERIFY_SQL(q, exec("insert into " + qtest + " values (1, 'VarChar1', 'Char1')"));
|
||||
QVERIFY_SQL(q, exec("insert into " + qtest + " values (2, 'VarChar2', 'Char2')"));
|
||||
QVERIFY_SQL(q, exec("insert into " + qtest + " values (3, 'VarChar3', 'Char3')"));
|
||||
QVERIFY_SQL(q, exec("insert into " + qtest + " values (4, 'VarChar4', 'Char4')"));
|
||||
QVERIFY_SQL(q, exec("insert into " + qtest + " values (5, 'VarChar5', 'Char5')"));
|
||||
}
|
||||
|
||||
void tst_QSqlRecord::benchmarkRecord()
|
||||
{
|
||||
QFETCH(QString, dbName);
|
||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||
CHECK_DATABASE(db);
|
||||
const auto tableName = qTableName("record", __FILE__, db);
|
||||
TableScope ts(db, "record", __FILE__);
|
||||
{
|
||||
QSqlQuery qry(db);
|
||||
QVERIFY_SQL(qry, exec("create table " + tableName +
|
||||
QVERIFY_SQL(qry, exec("create table " + ts.tableName() +
|
||||
" (id int NOT NULL, t_varchar varchar(20), "
|
||||
"t_char char(20), primary key(id))"));
|
||||
// Limit to 500: at 600, the set-up takes nearly 5 minutes
|
||||
for (int i = 0; i < 500; i++)
|
||||
QVERIFY_SQL(qry, exec(QString("INSERT INTO " + tableName +
|
||||
QVERIFY_SQL(qry, exec(QString("INSERT INTO " + ts.tableName() +
|
||||
" VALUES (%1, 'VarChar%1', 'Char%1')").arg(i)));
|
||||
QVERIFY_SQL(qry, exec(QString("SELECT * from ") + tableName));
|
||||
QVERIFY_SQL(qry, exec(QString("SELECT * from ") + ts.tableName()));
|
||||
QBENCHMARK {
|
||||
while (qry.next())
|
||||
qry.record();
|
||||
QVERIFY(qry.seek(0));
|
||||
}
|
||||
}
|
||||
tst_Databases::safeDropTables(db, QStringList() << tableName);
|
||||
}
|
||||
|
||||
void tst_QSqlRecord::benchFieldName()
|
||||
@ -174,7 +100,6 @@ void tst_QSqlRecord::benchFieldIndex()
|
||||
QCOMPARE(tst_Databases::getDatabaseType(db), QSqlDriver::PostgreSQL);
|
||||
QSqlQuery qry(db);
|
||||
QVERIFY_SQL(qry, exec("SELECT GENERATE_SERIES(1,5000) AS r"));
|
||||
qry = db.exec("SELECT GENERATE_SERIES(1,5000) AS r");
|
||||
QBENCHMARK {
|
||||
while (qry.next())
|
||||
qry.value(0);
|
||||
|
Loading…
Reference in New Issue
Block a user