- Recompilación en Delphi10 de todos los paquetes de RO para generar las DCU's en Lib\D10 - Recompilación en Delphi10 de todos los paquetes de DA para generar las DCU's en Lib\D10 git-svn-id: https://192.168.0.254/svn/Componentes.Terceros.RemObjects@9 b6239004-a887-0f4b-9937-50029ccdca16
261 lines
7.5 KiB
ObjectPascal
261 lines
7.5 KiB
ObjectPascal
unit uDAUtils;
|
|
|
|
{----------------------------------------------------------------------------}
|
|
{ Data Abstract Library - Core Library }
|
|
{ }
|
|
{ compiler: Delphi 6 and up, Kylix 3 and up }
|
|
{ platform: Win32, Linux }
|
|
{ }
|
|
{ (c)opyright RemObjects Software. all rights reserved. }
|
|
{ }
|
|
{ Using this code requires a valid license of the Data Abstract }
|
|
{ which can be obtained at http://www.remobjects.com. }
|
|
{----------------------------------------------------------------------------}
|
|
|
|
{$I DataAbstract.inc}
|
|
|
|
interface
|
|
|
|
uses Classes, DB, SysUtils, uDARes;
|
|
|
|
const
|
|
// Directory aliases. DEFINE THEM IN UPPERCASE and do not translate
|
|
alias_System = '%SYSTEM%';
|
|
alias_ModuleDir = '%MODULE%';
|
|
alias_DABinDir = '%DABINDIR%';
|
|
|
|
type
|
|
{ TDAConnectionStringParser
|
|
Simple class that provides all the methods to work with Data Abstract connection strings.
|
|
Connection objects make use of this class in the method ApplyConnectionString. }
|
|
TDAConnectionStringParser = class
|
|
private
|
|
fServer: string;
|
|
fAuxDriver: string;
|
|
fPassword: string;
|
|
fUserID: string;
|
|
fDriverID: string;
|
|
fAuxParams: TStringList;
|
|
fDatabase: string;
|
|
|
|
function GetAuxParamNames(Index: integer): string;
|
|
function GetAuxParamsCount: integer;
|
|
function GetAuxParams(const Name: string): string;
|
|
procedure SetAuxParams(const Name, Value: string);
|
|
function GetAuxParamsString: string;
|
|
|
|
protected
|
|
public
|
|
constructor Create(const aConnectionString: string = '');
|
|
destructor Destroy; override;
|
|
|
|
procedure Clear;
|
|
|
|
class function ExtractDriverID(const aConnectionString: string): string;
|
|
|
|
procedure Parse(const aConnectionString: string);
|
|
function BuildString: string;
|
|
|
|
property DriverID: string read fDriverID write fDriverID;
|
|
property Server: string read fServer write fServer;
|
|
property Database: string read fDatabase write fDatabase;
|
|
property UserID: string read fUserID write fUserID;
|
|
property Password: string read fPassword write fPassword;
|
|
property AuxDriver: string read fAuxDriver write fAuxDriver;
|
|
|
|
property AuxParams[const Name: string]: string read GetAuxParams write SetAuxParams;
|
|
property AuxParamNames[Index: integer]: string read GetAuxParamNames;
|
|
property AuxParamsCount: integer read GetAuxParamsCount;
|
|
property AuxParamsString: string read GetAuxParamsString;
|
|
end;
|
|
|
|
// Misc
|
|
function TranslateFileName(const aFileName: string): string;
|
|
function GetSystemDir: string;
|
|
function GetModulePath: string;
|
|
|
|
{$IFDEF FPC}
|
|
type
|
|
IProviderSupport = interface
|
|
procedure PSExecute;
|
|
function PSGetParams: TParams;
|
|
end;
|
|
{$ENDIF}
|
|
function GetProviderSupport(aDataset: TDataset): IProviderSupport;
|
|
|
|
implementation
|
|
|
|
uses
|
|
{$IFDEF MSWINDOWS}Windows, {$ENDIF}
|
|
TypInfo, uROClasses;
|
|
|
|
// Misc
|
|
|
|
function TranslateFileName(const aFileName: string): string;
|
|
var
|
|
i: integer;
|
|
begin
|
|
result := aFileName;
|
|
i := Pos(alias_System, UpperCase(aFileName));
|
|
if (i > 0) then begin
|
|
Delete(result, i, Length(alias_System));
|
|
Insert(GetSystemDir, result, i);
|
|
end;
|
|
|
|
i := Pos(alias_ModuleDir, UpperCase(aFileName));
|
|
if (i > 0) then begin
|
|
Delete(result, i, Length(alias_ModuleDir));
|
|
Insert(GetModulePath, result, i);
|
|
end;
|
|
end;
|
|
|
|
function GetSystemDir: string;
|
|
var
|
|
osdir: array[0..MAX_PATH] of char;
|
|
begin
|
|
{$IFNDEF KYLIX}
|
|
GetSystemDirectory(osdir, SizeOf(osdir));
|
|
result := ExcludeTrailingPathDelimiter(osdir);
|
|
{$ELSE}
|
|
RaiseError(err_NotSupported);
|
|
{$ENDIF}
|
|
end;
|
|
|
|
function GetModulePath: string;
|
|
var
|
|
filename: array[0..MAX_PATH] of char;
|
|
begin
|
|
FillChar(filename, SizeOf(filename), #0);
|
|
{$IFDEF KYLIX}System.{$ENDIF}GetModuleFileName(hInstance, filename, SizeOf(filename));
|
|
result := ExcludeTrailingPathDelimiter(ExtractFilePath(filename));
|
|
end;
|
|
|
|
function GetProviderSupport(aDataset: TDataset): IProviderSupport;
|
|
begin
|
|
{$IFDEF DELPHI7UP}
|
|
result := aDataset as IProviderSupport;
|
|
{$ELSE}{$IFNDEF FPC}
|
|
result := IProviderSupport(aDataset);
|
|
{$ELSE}
|
|
result:=nil;
|
|
{$ENDIF}{$ENDIF}
|
|
end;
|
|
|
|
{ TDAConnectionStringParser }
|
|
|
|
constructor TDAConnectionStringParser.Create(const aConnectionString: string = '');
|
|
begin
|
|
inherited Create;
|
|
|
|
fAuxParams := TStringList.Create;
|
|
{fAuxParams.Duplicates := dupError;
|
|
fAuxParams.Sorted := TRUE;}
|
|
|
|
if (aConnectionString <> '') then Parse(aConnectionString);
|
|
end;
|
|
|
|
destructor TDAConnectionStringParser.Destroy;
|
|
begin
|
|
fAuxParams.Free;
|
|
|
|
inherited;
|
|
end;
|
|
|
|
procedure TDAConnectionStringParser.Clear;
|
|
begin
|
|
fServer := '';
|
|
fDatabase := '';
|
|
fAuxDriver := '';
|
|
fPassword := '';
|
|
fUserID := '';
|
|
fDriverID := '';
|
|
fAuxParams.Clear;
|
|
end;
|
|
|
|
procedure TDAConnectionStringParser.Parse(const aConnectionString: string);
|
|
var
|
|
pars: IROStrings;
|
|
i: integer;
|
|
str: string;
|
|
begin
|
|
Clear;
|
|
|
|
// ADO?Server=127.0.0.1;UserID=sa;Password=lemmein;AuxDriver=SQLOLEDB.1;Params1=abc;Param2=CDE
|
|
str := Trim(aConnectionString);
|
|
|
|
// Extracts the driver name
|
|
fDriverID := ExtractDriverID(str);
|
|
Delete(str, 1, Pos(ds_Separator, str));
|
|
|
|
// Extracts the rest of the parameters
|
|
pars := ListStringElements(str);
|
|
|
|
fAuxDriver := pars.ExtractValue(ds_AuxDriver);
|
|
fDatabase := pars.ExtractValue(ds_Database);
|
|
fUserID := pars.ExtractValue(ds_UserID);
|
|
fPassword := pars.ExtractValue(ds_Password);
|
|
fServer := pars.ExtractValue(ds_Server);
|
|
|
|
for i := 0 to (pars.Count - 1) do
|
|
AuxParams[pars.Names[i]] := pars.Values[pars.Names[i]];
|
|
end;
|
|
|
|
function TDAConnectionStringParser.GetAuxParamNames(
|
|
Index: integer): string;
|
|
begin
|
|
result := fAuxParams.Names[Index]
|
|
end;
|
|
|
|
function TDAConnectionStringParser.GetAuxParamsCount: integer;
|
|
begin
|
|
result := fAuxParams.Count
|
|
end;
|
|
|
|
function TDAConnectionStringParser.GetAuxParams(
|
|
const Name: string): string;
|
|
begin
|
|
result := fAuxParams.Values[Name]
|
|
end;
|
|
|
|
procedure TDAConnectionStringParser.SetAuxParams(const Name,
|
|
Value: string);
|
|
begin
|
|
fAuxParams.Values[Name] := Value
|
|
end;
|
|
|
|
function TDAConnectionStringParser.BuildString: string;
|
|
var
|
|
i: integer;
|
|
begin
|
|
result := fDriverID + ds_Separator;
|
|
|
|
if (fAuxDriver <> '') then result := result + ds_AuxDriver + '=' + fAuxDriver+';';
|
|
if (fDatabase <> '') then result := result + ds_Database + '=' + fDatabase+';';
|
|
if (fUserID <> '') then result := result + ds_UserID + '=' + fUserID+';';
|
|
if (fPassword <> '') then result := result + ds_Password + '=' + fPassword+';';
|
|
if (fServer <> '') then result := result + ds_Server + '=' + fServer+';';
|
|
|
|
for i := 0 to (fAuxParams.Count - 1) do
|
|
result := result + fAuxParams.Names[i] + '=' + fAuxParams.Values[fAuxParams.Names[i]]+';';
|
|
end;
|
|
|
|
class function TDAConnectionStringParser.ExtractDriverID(
|
|
const aConnectionString: string): string;
|
|
var
|
|
str: string;
|
|
begin
|
|
str := Trim(aConnectionString);
|
|
result := Trim(Copy(str, 1, Pos(ds_Separator, str) - 1));
|
|
end;
|
|
|
|
function TDAConnectionStringParser.GetAuxParamsString: string;
|
|
var
|
|
i: integer;
|
|
begin
|
|
result := '';
|
|
for i := 0 to (AuxParamsCount - 1) do
|
|
result := result + AuxParamNames[i] + '=' + AuxParams[AuxParamNames[i]] +';';
|
|
end;
|
|
|
|
end.
|