mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 11:09:42 +02:00
+ Implemented GetTableNames, GetProcedureNames and GetFieldNames for TSQLConnection
+ Some fixes for TIBConnection.GetSchemaInfoSQL git-svn-id: trunk@1064 -
This commit is contained in:
parent
bb70f2f5cc
commit
423a63200d
@ -758,7 +758,9 @@ begin
|
||||
'from '+
|
||||
'rdb$relations '+
|
||||
'where '+
|
||||
'(rdb$system_flag = 0 or rdb$system_flag is null)'; // and rdb$view_blr is null
|
||||
'(rdb$system_flag = 0 or rdb$system_flag is null) ' + // and rdb$view_blr is null
|
||||
'order by rdb$relation_name';
|
||||
|
||||
stSysTables : s := 'select '+
|
||||
'rdb$relation_id as recno, '+
|
||||
'''' + DatabaseName + ''' as catalog_name, '+
|
||||
@ -768,7 +770,9 @@ begin
|
||||
'from '+
|
||||
'rdb$relations '+
|
||||
'where '+
|
||||
'(rdb$system_flag > 0)'; // and rdb$view_blr is null
|
||||
'(rdb$system_flag > 0) ' + // and rdb$view_blr is null
|
||||
'order by rdb$relation_name';
|
||||
|
||||
stProcedures : s := 'select '+
|
||||
'rdb$procedure_id as recno, '+
|
||||
'''' + DatabaseName + ''' as catalog_name, '+
|
||||
@ -782,11 +786,11 @@ begin
|
||||
'WHERE '+
|
||||
'(rdb$system_flag = 0 or rdb$system_flag is null)';
|
||||
stColumns : s := 'select '+
|
||||
'rdb$procedure_id as recno, '+
|
||||
'rdb$field_id as recno, '+
|
||||
'''' + DatabaseName + ''' as catalog_name, '+
|
||||
''''' as schema_name, '+
|
||||
'rdb$relation_name as table_name, '+
|
||||
'rdb$field_name as column name, '+
|
||||
'rdb$field_name as column_name, '+
|
||||
'rdb$field_position as column_position, '+
|
||||
'0 as column_type, '+
|
||||
'0 as column_datatype, '+
|
||||
@ -799,7 +803,8 @@ begin
|
||||
'from '+
|
||||
'rdb$relation_fields '+
|
||||
'WHERE '+
|
||||
'(rdb$system_flag = 0 or rdb$system_flag is null)';
|
||||
'(rdb$system_flag = 0 or rdb$system_flag is null) and (rdb$relation_name = ''' + Uppercase(SchemaObjectName) + ''') ' +
|
||||
'order by rdb$field_name';
|
||||
else
|
||||
DatabaseError(SMetadataUnavailable)
|
||||
end; {case}
|
||||
|
@ -70,6 +70,7 @@ type
|
||||
FRole : String;
|
||||
|
||||
procedure SetTransaction(Value : TSQLTransaction);
|
||||
procedure GetDBInfo(const SchemaType : TSchemaType; const SchemaObjectName, ReturnField : string; List: TStrings);
|
||||
protected
|
||||
FConnOptions : TConnOptions;
|
||||
|
||||
@ -106,6 +107,9 @@ type
|
||||
property ConnOptions: TConnOptions read FConnOptions;
|
||||
procedure ExecuteDirect(SQL : String); overload; virtual;
|
||||
procedure ExecuteDirect(SQL : String; Transaction : TSQLTransaction); overload; virtual;
|
||||
procedure GetTableNames(List : TStrings; SystemTables : Boolean = false); virtual;
|
||||
procedure GetProcedureNames(List : TStrings); virtual;
|
||||
procedure GetFieldNames(const TableName : string; List : TStrings); virtual;
|
||||
published
|
||||
property Password : string read FPassword write FPassword;
|
||||
property Transaction : TSQLTransaction read FTransaction write SetTransaction;
|
||||
@ -340,6 +344,49 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSQLConnection.GetDBInfo(const SchemaType : TSchemaType; const SchemaObjectName, ReturnField : string; List: TStrings);
|
||||
|
||||
var qry : TSQLQuery;
|
||||
|
||||
begin
|
||||
if not assigned(Transaction) then
|
||||
DatabaseError(SErrConnTransactionnSet);
|
||||
|
||||
qry := tsqlquery.Create(nil);
|
||||
qry.transaction := Transaction;
|
||||
qry.database := Self;
|
||||
with qry do
|
||||
begin
|
||||
ParseSQL := False;
|
||||
SetSchemaInfo(SchemaType,SchemaObjectName,'');
|
||||
open;
|
||||
List.Clear;
|
||||
while not eof do
|
||||
begin
|
||||
List.Append(fieldbyname(ReturnField).asstring);
|
||||
Next;
|
||||
end;
|
||||
end;
|
||||
qry.free;
|
||||
end;
|
||||
|
||||
|
||||
procedure TSQLConnection.GetTableNames(List: TStrings; SystemTables: Boolean);
|
||||
begin
|
||||
if not systemtables then GetDBInfo(stTables,'','table_name',List)
|
||||
else GetDBInfo(stSysTables,'','table_name',List);
|
||||
end;
|
||||
|
||||
procedure TSQLConnection.GetProcedureNames(List: TStrings);
|
||||
begin
|
||||
GetDBInfo(stProcedures,'','proc_name',List);
|
||||
end;
|
||||
|
||||
procedure TSQLConnection.GetFieldNames(const TableName: string; List: TStrings);
|
||||
begin
|
||||
GetDBInfo(stColumns,TableName,'column_name',List);
|
||||
end;
|
||||
|
||||
function TSQLConnection.GetAsSQLText(Field : TField) : string;
|
||||
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user