SQL/Tests: remove some unused functions

remove toHex() as it's not used at all and qTableName() with two params.
Also remove some SQLite 2 specific stuff

Change-Id: If285febdfbee5833f7174d70f386bd54674bd539
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Christian Ehrlicher 2023-02-28 20:50:39 +01:00
parent 5123645831
commit 28d5da386f
6 changed files with 42 additions and 81 deletions

View File

@ -70,32 +70,6 @@ inline static QString qTableName(const QString &prefix, const char *sourceFileNa
return escape ? db.driver()->escapeIdentifier(tableStr, QSqlDriver::TableName) : tableStr;
}
inline static QString qTableName(const QString& prefix, QSqlDatabase db)
{
QString tableStr;
if (db.driverName().toLower().contains("ODBC"))
tableStr += QLatin1String("_odbc");
return fixupTableName(QString(db.driver()->escapeIdentifier(prefix + tableStr + QLatin1Char('_') +
qGetHostName(), QSqlDriver::TableName)),db);
}
inline static QString toHex( const QString& binary )
{
QString str;
static char const hexchars[] = "0123456789ABCDEF";
for ( int i = 0; i < binary.size(); i++ ) {
ushort code = binary.at(i).unicode();
str += (QChar)(hexchars[ (code >> 12) & 0x0F ]);
str += (QChar)(hexchars[ (code >> 8) & 0x0F ]);
str += (QChar)(hexchars[ (code >> 4) & 0x0F ]);
str += (QChar)(hexchars[ code & 0x0F ]);
}
return str;
}
class tst_Databases
{

View File

@ -2128,9 +2128,6 @@ void tst_QSqlDatabase::sqlite_bindAndFetchUInt()
QFETCH(QString, dbName);
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
if (db.driverName().startsWith("QSQLITE2"))
QSKIP("SQLite3 specific test");
QSqlQuery q(db);
const QString tableName(qTableName("uint_test", __FILE__, db));
QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(uint_field UNSIGNED INTEGER)").arg(tableName)));
@ -2244,9 +2241,6 @@ void tst_QSqlDatabase::sqlite_enableRegexp()
QFETCH(QString, dbName);
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
if (db.driverName().startsWith("QSQLITE2"))
QSKIP("SQLite3 specific test");
db.close();
db.setConnectOptions("QSQLITE_ENABLE_REGEXP");
QVERIFY_SQL(db, open());

View File

@ -89,10 +89,11 @@ void tst_QSqlDriver::cleanupTestCase()
{
foreach (const QString &dbName, dbs.dbNames) {
QSqlDatabase db = QSqlDatabase::database(dbName);
tst_Databases::safeDropTable(db, qTableName("relTEST1", __FILE__, db));
QStringList tables = {qTableName("relTEST1", __FILE__, db)};
const QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
if (dbType == QSqlDriver::Oracle)
tst_Databases::safeDropTable(db, qTableName("clobTable", __FILE__, db));
tables.push_back(qTableName("clobTable", __FILE__, db));
tst_Databases::safeDropTables(db, tables);
}
dbs.close();
}

View File

@ -1228,12 +1228,8 @@ void tst_QSqlQuery::numRowsAffected()
QSqlQuery q2(db);
QVERIFY_SQL(q2, exec(QLatin1String("insert into %1 values (42001, 'homer', 'marge')")
.arg(qtest)));
if (!db.driverName().startsWith("QSQLITE2")) {
// SQLite 2.x accumulates changed rows in nested queries. See task 33794
QCOMPARE(q2.numRowsAffected(), 1);
QCOMPARE(q2.numRowsAffected(), 1); // yes, we check twice
}
QCOMPARE(q2.numRowsAffected(), 1);
QCOMPARE(q2.numRowsAffected(), 1); // yes, we check twice
}
void tst_QSqlQuery::size()

View File

@ -160,16 +160,11 @@ void tst_QSqlRelationalTableModel::cleanupTestCase()
void tst_QSqlRelationalTableModel::dropTestTables( QSqlDatabase db )
{
QStringList tableNames;
tableNames << reltest1
<< reltest2
<< reltest3
<< reltest4
<< reltest5
<< qTableName("rel test6", __FILE__, db)
<< qTableName("rel test7", __FILE__, db)
<< qTableName("CASETEST1", db)
<< qTableName("casetest1", db);
QStringList tableNames{reltest1, reltest2, reltest3, reltest4, reltest5,
qTableName("rel test6", __FILE__, db),
qTableName("rel test7", __FILE__, db),
qTableName("CASETEST1", __FILE__, db),
qTableName("casetest1", __FILE__, db)};
tst_Databases::safeDropTables( db, tableNames );
db.exec("DROP SCHEMA " + qTableName("QTBUG_5373", __FILE__, db) + " CASCADE");
@ -1095,54 +1090,57 @@ void tst_QSqlRelationalTableModel::casing()
QSKIP("The casing test for this database is irrelevant since this database does not treat different cases as separate entities");
QSqlQuery q(db);
QVERIFY_SQL( q, exec("create table " + qTableName("CASETEST1", db).toUpper() +
const QString caseTestUpper = qTableName("CASETEST1", __FILE__, db).toUpper();
const QString caseTestLower = qTableName("casetest1", __FILE__, db);
tst_Databases::safeDropTables(db, {caseTestUpper, caseTestLower});
QVERIFY_SQL( q, exec("create table " + caseTestUpper +
" (id int not null primary key, name varchar(20), title_key int, another_title_key int)"));
if (!q.exec("create table " + qTableName("casetest1", db) +
if (!q.exec("create table " + caseTestLower +
" (ident int not null primary key, name varchar(20), title_key int)"))
QSKIP("The casing test for this database is irrelevant since this database does not treat different cases as separate entities");
QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db).toUpper() + " values(1, 'harry', 1, 2)"));
QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db).toUpper() + " values(2, 'trond', 2, 1)"));
QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db).toUpper() + " values(3, 'vohi', 1, 2)"));
QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db).toUpper() + " values(4, 'boris', 2, 2)"));
QVERIFY_SQL( q, exec("insert into " + qTableName("casetest1", db) + " values(1, 'jerry', 1)"));
QVERIFY_SQL( q, exec("insert into " + qTableName("casetest1", db) + " values(2, 'george', 2)"));
QVERIFY_SQL( q, exec("insert into " + qTableName("casetest1", db) + " values(4, 'kramer', 2)"));
QVERIFY_SQL( q, exec("insert into " + caseTestUpper + " values(1, 'harry', 1, 2)"));
QVERIFY_SQL( q, exec("insert into " + caseTestUpper + " values(2, 'trond', 2, 1)"));
QVERIFY_SQL( q, exec("insert into " + caseTestUpper + " values(3, 'vohi', 1, 2)"));
QVERIFY_SQL( q, exec("insert into " + caseTestUpper + " values(4, 'boris', 2, 2)"));
QVERIFY_SQL( q, exec("insert into " + caseTestLower + " values(1, 'jerry', 1)"));
QVERIFY_SQL( q, exec("insert into " + caseTestLower + " values(2, 'george', 2)"));
QVERIFY_SQL( q, exec("insert into " + caseTestLower + " values(4, 'kramer', 2)"));
if (dbType == QSqlDriver::Oracle) {
//try an owner that doesn't exist
QSqlRecord rec = db.driver()->record("doug." + qTableName("CASETEST1", db).toUpper());
QSqlRecord rec = db.driver()->record("doug." + caseTestUpper);
QCOMPARE( rec.count(), 0);
//try an owner that does exist
rec = db.driver()->record(db.userName() + QLatin1Char('.') + qTableName("CASETEST1", db).toUpper());
rec = db.driver()->record(db.userName() + QLatin1Char('.') + caseTestUpper);
QCOMPARE( rec.count(), 4);
}
QSqlRecord rec = db.driver()->record(qTableName("CASETEST1", db).toUpper());
QSqlRecord rec = db.driver()->record(caseTestUpper);
QCOMPARE( rec.count(), 4);
rec = db.driver()->record(qTableName("casetest1", db));
rec = db.driver()->record(caseTestLower);
QCOMPARE( rec.count(), 3);
QSqlTableModel upperCaseModel(0, db);
upperCaseModel.setTable(qTableName("CASETEST1", db).toUpper());
upperCaseModel.setTable(caseTestUpper);
QCOMPARE(upperCaseModel.tableName(), qTableName("CASETEST1", db).toUpper());
QCOMPARE(upperCaseModel.tableName(), caseTestUpper);
QVERIFY_SQL(upperCaseModel, select());
QCOMPARE(upperCaseModel.rowCount(), 4);
QSqlTableModel lowerCaseModel(0, db);
lowerCaseModel.setTable(qTableName("casetest1", db));
QCOMPARE(lowerCaseModel.tableName(), qTableName("casetest1", db));
lowerCaseModel.setTable(caseTestLower);
QCOMPARE(lowerCaseModel.tableName(), caseTestLower);
QVERIFY_SQL(lowerCaseModel, select());
QCOMPARE(lowerCaseModel.rowCount(), 3);
QSqlRelationalTableModel model(0, db);
model.setTable(qTableName("CASETEST1", db).toUpper());
model.setTable(caseTestUpper);
model.setRelation(2, QSqlRelation(reltest2, "id", "title"));
QVERIFY_SQL(model, select());

View File

@ -155,17 +155,15 @@ void tst_QSqlTableModel::dropTestTables()
if (dbType == QSqlDriver::PostgreSQL)
QVERIFY_SQL( q, exec("set client_min_messages='warning'"));
QStringList tableNames;
tableNames << qTableName("test1", __FILE__, db)
<< qTableName("test2", __FILE__, db)
<< qTableName("test3", __FILE__, db)
<< qTableName("test4", __FILE__, db)
<< qTableName("emptytable", __FILE__, db)
<< qTableName("bigtable", __FILE__, db)
<< qTableName("foo", __FILE__, db)
<< qTableName("pktest", __FILE__, db)
<< qTableName("qtestw hitespace", db);
QStringList tableNames{qTableName("test1", __FILE__, db),
qTableName("test2", __FILE__, db),
qTableName("test3", __FILE__, db),
qTableName("test4", __FILE__, db),
qTableName("emptytable", __FILE__, db),
qTableName("bigtable", __FILE__, db),
qTableName("foo", __FILE__, db),
qTableName("pktest", __FILE__, db),
qTableName("qtestw hitespace", __FILE__, db)};
tst_Databases::safeDropTables(db, tableNames);
if (db.driverName().startsWith("QPSQL")) {
@ -196,7 +194,7 @@ void tst_QSqlTableModel::createTestTables()
QVERIFY_SQL(q, exec("create table " + qTableName("emptytable", __FILE__, db) + "(id int)"));
const auto fieldStr = db.driver()->escapeIdentifier("a field", QSqlDriver::FieldName);
QVERIFY_SQL(q, exec("create table " + qTableName("qtestw hitespace", db) + " ("+ fieldStr + " int)"));
QVERIFY_SQL(q, exec("create table " + qTableName("qtestw hitespace", __FILE__, db) + " ("+ fieldStr + " int)"));
QVERIFY_SQL(q, exec("create table " + qTableName("pktest", __FILE__, db) + "(id int not null primary key, a varchar(20))"));
}
@ -1697,7 +1695,7 @@ void tst_QSqlTableModel::whitespaceInIdentifiers()
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
QString tableName = qTableName("qtestw hitespace", db);
QString tableName = qTableName("qtestw hitespace", __FILE__, db);
QSqlTableModel model(0, db);
model.setTable(tableName);