With current function "TZOracleDatabaseMetadata.UncachedGetPrimaryKeys" in file "src\dbc\ZDbcOracleMetadata.pas"
Code: Select all
function TZOracleDatabaseMetadata.UncachedGetPrimaryKeys(const Catalog: string;
const Schema: string; const Table: string): IZResultSet;
var
SQL: string;
OwnerCondition,TableCondition: String;
function CreateExtraWhere: String;
begin
Result := '';
If OwnerCondition <> '' then
Result := OwnerCondition;
If TableCondition <> '' then
If Result <> '' then
Result := Result + ' AND ' + TableCondition
Else
Result := TableCondition;
If Result <> '' then
Result := ' AND ' + Result;
end;
begin
OwnerCondition := ConstructNameCondition(Schema,'A.OWNER');
TableCondition := ConstructNameCondition(Table,'A.TABLE_NAME');
SQL := 'SELECT NULL AS TABLE_CAT, A.OWNER AS TABLE_SCHEM, A.TABLE_NAME,'
+ ' B.COLUMN_NAME, B.COLUMN_POSITION AS KEY_SEQ, A.INDEX_NAME AS PK_NAME'
+ ' FROM ALL_INDEXES A, ALL_IND_COLUMNS B'
+ ' WHERE A.OWNER=B.INDEX_OWNER AND A.INDEX_NAME=B.INDEX_NAME'
+ ' AND A.TABLE_OWNER=B.TABLE_OWNER AND A.TABLE_NAME=B.TABLE_NAME'
+ ' AND A.UNIQUENESS=''UNIQUE'' AND A.GENERATED=''Y'''
+ ' AND A.INDEX_NAME LIKE ''SYS_%'''
+ CreateExtraWhere
+ ' ORDER BY A.INDEX_NAME, B.COLUMN_POSITION';
Result := CopyToVirtualResultSet(
GetConnection.CreateStatement.ExecuteQuery(SQL),
ConstructVirtualResultSet(PrimaryKeyColumnsDynArray));
end;
This query is not returns all other keys (unique indices) - created by user for user tables due to business logic.
My different for this function is based on ALL_IND_COLUMNS and ALL_CONSTRAINTS virtual relationships.
Code: Select all
function TZOracleDatabaseMetadata.UncachedGetPrimaryKeys(const Catalog: string;
const Schema: string; const Table: string): IZResultSet;
var
SQL: string;
OwnerCondition,TableCondition: String;
function CreateExtraWhere: String;
begin
Result := '';
If OwnerCondition <> '' then
Result := OwnerCondition;
If TableCondition <> '' then
If Result <> '' then
Result := Result + ' AND ' + TableCondition
Else
Result := TableCondition;
If Result <> '' then
Result := ' AND ' + Result;
end;
begin
OwnerCondition := ConstructNameCondition(Schema,'AC.OWNER');
TableCondition := ConstructNameCondition(Table,'AC.TABLE_NAME');
SQL:='SELECT NULL AS TABLE_CAT,AC.OWNER AS TABLE_SCHEM,AC.TABLE_NAME,'
+ 'B.COLUMN_NAME,B.COLUMN_POSITION AS KEY_SEQ,AC.INDEX_NAME AS PK_NAME '
+ 'FROM ALL_IND_COLUMNS B,ALL_CONSTRAINTS AC '
+ 'WHERE AC.INDEX_NAME=B.INDEX_NAME '
+ CreateExtraWhere
+ ' ORDER BY AC.CONSTRAINT_TYPE,B.INDEX_NAME,B.COLUMN_POSITION ';
SQL:='SELECT * FROM('+SQL+')WHERE PK_NAME=(SELECT PK_NAME FROM('+SQL
+')WHERE ROWNUM=1)';
Result := CopyToVirtualResultSet(
GetConnection.CreateStatement.ExecuteQuery(SQL),
ConstructVirtualResultSet(PrimaryKeyColumnsDynArray));
Please test this changes and apply in versions 7.1 - 7.3
Alternative changes in http://zeoslib.sourceforge.net/viewtopi ... 38&t=13368 detect any index without priority primary keys.