TUniMetadata and database structure.
Hi!
Now I can get tables, columns, columns types and indexes.
tables
- procedure
- var
- FUniMetaData: TUniMetaData;
- begin
- FUniMetaData := TUniMetaData.Create(nil);
- try
- FUniMetaData.Connection := FConnection;
- FUniMetaData.MetaDataKind := 'Tables';
- FUniMetaData.Open;
- while not FUniMetaData.Eof do
- begin
- ... := FUniMetaData.FieldByName('TABLE_NAME').AsString;
- FMetaQuery.Next;
- end;
- finally
- FMetaQuery.DisposeOf;
- end;
- end;
columns, types
- procedure
- var
- FUniMetaData: TUniMetaData;
- begin
- FUniMetaData:= TUniMetaData.Create(nil);
- try
- FUniMetaData.Connection := FConnection;
- FUniMetaData.Restrictions.Values['TABLE_NAME'] := FTable;
- FUniMetaData.MetaDataKind := 'Columns';
- FUniMetaData.Open;
- while not FUniMetaData.Eof do
- begin
- ... := FUniMetaData.FieldByName('COLUMN_NAME').AsString;
- ... := FUniMetaData.FieldByName('DATA_TYPE').AsString;
- ... := FUniMetaData.FieldByName('DATA_LENGTH').AsInteger;
- FUniMetaData.Next;
- end;
- finally
- FUniMetaData.DisposeOf;
- end;
- end;
indexes
- procedure
- var
- FUniMetaData: TUniMetaData;
- begin
- FUniMetaData:= TUniMetaData.Create(nil);
- try
- FUniMetaData.Connection := FConnection;
- FUniMetaData.Restrictions.Values['TABLE_NAME'] := FTable;
- FUniMetaData.MetaDataKind := 'Indexes';
- FUniMetaData.Open;
- while not FUniMetaData.Eof do
- begin
- ... := FUniMetaData.FieldByName('INDEX_NAME').AsString;
- FUniMetaData.Next;
- end;
- finally
- FUniMetaData.DisposeOf;
- end;
- end;
IndexColumns
- procedure
- var
- FUniMetaData: TUniMetaData;
- index: TUIndex;
- s: string;
- begin
- FUniMetaData:= TUniMetaData.Create(nil);
- try
- FUniMetaData.Connection := AConnection;
- FUniMetaData.Restrictions.Values['TABLE_NAME'] := ATable;
- FUniMetaData.Restrictions.Values['INDEX_NAME'] := AIndex;
- FUniMetaData.MetaDataKind := 'IndexColumns';
- FUniMetaData.Open;
- while not FUniMetaData.Eof do
- begin
- ... := FUniMetaData.FieldByName('COLUMN_NAME').AsString;
- FUniMetaData.Next;
- end;
- finally
- FUniMetaData.DisposeOf;
- end;
- end;
But I need to get also foreign keys and their composition.
How can I do this for MySql and MS Access?