mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-22 15:49:18 +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 '+
|
'from '+
|
||||||
'rdb$relations '+
|
'rdb$relations '+
|
||||||
'where '+
|
'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 '+
|
stSysTables : s := 'select '+
|
||||||
'rdb$relation_id as recno, '+
|
'rdb$relation_id as recno, '+
|
||||||
'''' + DatabaseName + ''' as catalog_name, '+
|
'''' + DatabaseName + ''' as catalog_name, '+
|
||||||
@ -768,7 +770,9 @@ begin
|
|||||||
'from '+
|
'from '+
|
||||||
'rdb$relations '+
|
'rdb$relations '+
|
||||||
'where '+
|
'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 '+
|
stProcedures : s := 'select '+
|
||||||
'rdb$procedure_id as recno, '+
|
'rdb$procedure_id as recno, '+
|
||||||
'''' + DatabaseName + ''' as catalog_name, '+
|
'''' + DatabaseName + ''' as catalog_name, '+
|
||||||
@ -782,11 +786,11 @@ begin
|
|||||||
'WHERE '+
|
'WHERE '+
|
||||||
'(rdb$system_flag = 0 or rdb$system_flag is null)';
|
'(rdb$system_flag = 0 or rdb$system_flag is null)';
|
||||||
stColumns : s := 'select '+
|
stColumns : s := 'select '+
|
||||||
'rdb$procedure_id as recno, '+
|
'rdb$field_id as recno, '+
|
||||||
'''' + DatabaseName + ''' as catalog_name, '+
|
'''' + DatabaseName + ''' as catalog_name, '+
|
||||||
''''' as schema_name, '+
|
''''' as schema_name, '+
|
||||||
'rdb$relation_name as table_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, '+
|
'rdb$field_position as column_position, '+
|
||||||
'0 as column_type, '+
|
'0 as column_type, '+
|
||||||
'0 as column_datatype, '+
|
'0 as column_datatype, '+
|
||||||
@ -799,7 +803,8 @@ begin
|
|||||||
'from '+
|
'from '+
|
||||||
'rdb$relation_fields '+
|
'rdb$relation_fields '+
|
||||||
'WHERE '+
|
'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
|
else
|
||||||
DatabaseError(SMetadataUnavailable)
|
DatabaseError(SMetadataUnavailable)
|
||||||
end; {case}
|
end; {case}
|
||||||
|
@ -70,6 +70,7 @@ type
|
|||||||
FRole : String;
|
FRole : String;
|
||||||
|
|
||||||
procedure SetTransaction(Value : TSQLTransaction);
|
procedure SetTransaction(Value : TSQLTransaction);
|
||||||
|
procedure GetDBInfo(const SchemaType : TSchemaType; const SchemaObjectName, ReturnField : string; List: TStrings);
|
||||||
protected
|
protected
|
||||||
FConnOptions : TConnOptions;
|
FConnOptions : TConnOptions;
|
||||||
|
|
||||||
@ -106,6 +107,9 @@ type
|
|||||||
property ConnOptions: TConnOptions read FConnOptions;
|
property ConnOptions: TConnOptions read FConnOptions;
|
||||||
procedure ExecuteDirect(SQL : String); overload; virtual;
|
procedure ExecuteDirect(SQL : String); overload; virtual;
|
||||||
procedure ExecuteDirect(SQL : String; Transaction : TSQLTransaction); 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
|
published
|
||||||
property Password : string read FPassword write FPassword;
|
property Password : string read FPassword write FPassword;
|
||||||
property Transaction : TSQLTransaction read FTransaction write SetTransaction;
|
property Transaction : TSQLTransaction read FTransaction write SetTransaction;
|
||||||
@ -340,6 +344,49 @@ begin
|
|||||||
end;
|
end;
|
||||||
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;
|
function TSQLConnection.GetAsSQLText(Field : TField) : string;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user