OCI: Match the constraints on the index_name column
When looking for the primary index, it is possible that the constraint_name in the all_ind_columns table does not match that of the index_name. Whereas the index_name will match in this case, so the query should set the where clause on the index_name in both tables. Task-number: QTBUG-64427 Change-Id: I1bf1fb580e620b9f75f2fde1ecf408842e377365 Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
This commit is contained in:
parent
66bace390b
commit
3dab19ffed
@ -2603,7 +2603,7 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const
|
||||
QString stmt(QLatin1String("select b.column_name, b.index_name, a.table_name, a.owner "
|
||||
"from all_constraints a, all_ind_columns b "
|
||||
"where a.constraint_type='P' "
|
||||
"and b.index_name = a.constraint_name "
|
||||
"and b.index_name = a.index_name "
|
||||
"and b.index_owner = a.owner"));
|
||||
|
||||
bool buildIndex = false;
|
||||
|
@ -100,6 +100,9 @@ void tst_QSqlDriver::cleanupTestCase()
|
||||
foreach (const QString &dbName, dbs.dbNames) {
|
||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||
tst_Databases::safeDropTable(db, qTableName("relTEST1", __FILE__, db));
|
||||
const QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
||||
if (dbType == QSqlDriver::Oracle)
|
||||
tst_Databases::safeDropTable(db, qTableName("clobTable", __FILE__, db));
|
||||
}
|
||||
dbs.close();
|
||||
}
|
||||
@ -214,6 +217,20 @@ void tst_QSqlDriver::primaryIndex()
|
||||
QCOMPARE(index.count(), 1); //mysql will always find the table name regardless of casing
|
||||
else
|
||||
QCOMPARE(index.count(), 0);
|
||||
|
||||
// Test getting a primary index for a table with a clob in it - QTBUG-64427
|
||||
if (dbType == QSqlDriver::Oracle) {
|
||||
const QString clobTable(qTableName("clobTable", __FILE__, db));
|
||||
QSqlQuery qry(db);
|
||||
QVERIFY_SQL(qry, exec("CREATE TABLE " + clobTable + " (id INTEGER, clobField CLOB)"));
|
||||
QVERIFY_SQL(qry, exec("CREATE UNIQUE INDEX " + clobTable + "IDX ON " + clobTable + " (id)"));
|
||||
QVERIFY_SQL(qry, exec("ALTER TABLE " + clobTable + " ADD CONSTRAINT " + clobTable +
|
||||
"PK PRIMARY KEY(id)"));
|
||||
QVERIFY_SQL(qry, exec("ALTER TABLE " + clobTable + " MODIFY (id NOT NULL ENABLE)"));
|
||||
const QSqlIndex primaryIndex = db.driver()->primaryIndex(clobTable);
|
||||
QCOMPARE(primaryIndex.count(), 1);
|
||||
QCOMPARE(primaryIndex.fieldName(0), QStringLiteral("ID"));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSqlDriver::formatValue()
|
||||
|
Loading…
Reference in New Issue
Block a user