Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit DataPumpNEW;
- interface
- uses
- Winapi.Windows, Winapi.Messages,
- System.SysUtils, System.Variants, System.Classes
- , Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs
- , Data.DB, Data.Win.ADODB
- , IniFiles
- {$IFDEF DEBUG}
- , Clipbrd
- {$ENDIF}
- , DataPumpLookup
- ;
- type
- TLookupItem = class;
- TLookupTable = class;
- TLookupTables = class;
- TRecordProp = class;
- TRecord = class;
- TRecords = class;
- TConnection = class;
- TConnections = class;
- TEntityProp = class;
- TEntity = class;
- TEntities = class;
- TSchemaLink = class;
- TSchemaLinks = class;
- TSchema = class;
- TSchemas = class;
- TDataPump = class;
- TPerspective = (psNone, psSource, psDestination);
- TFieldLinkType = (flText, flInt, flFloat, flBool);
- TFieldLinkTypes = set of TFieldLinkType;
- TConnectedEvent = procedure(Sender: TObject; const Perspective: TPerspective;
- const Connected: Boolean) of object;
- //Individual property value referenced with a unique ID
- TLookupItem = class(TPersistent)
- private
- FOwner: TLookupTable;
- FID: Integer;
- FValue: String;
- procedure SetID(const Value: Integer);
- procedure SetValue(const Value: String);
- public
- constructor Create(AOwner: TLookupTable);
- destructor Destroy; override;
- published
- property ID: Integer read FID;
- property Value: String read FValue write SetValue;
- end;
- //List of property values of a certain lookup type
- TLookupTable = class(TPersistent)
- private
- FOwner: TLookupTables;
- FItems: TList;
- FLastID: Integer;
- FCaseSensitive: Boolean;
- FName: String;
- procedure SetCaseSensitive(const Value: Boolean);
- function NewID: Integer;
- procedure SetName(const Value: String);
- function GetItem(const Index: Integer): TLookupItem;
- public
- constructor Create(AOwner: TLookupTables);
- destructor Destroy; override;
- function Add: TLookupItem; overload;
- function Add(const Value: String): TLookupItem; overload;
- procedure Delete(const Index: Integer);
- procedure Clear;
- function Count: Integer;
- function Lookup(const Value: String;
- const CanCreate: Boolean = False): Integer;
- property Items[const Index: Integer]: TLookupItem read GetItem; default;
- published
- property Name: String read FName write SetName;
- property CaseSensitive: Boolean
- read FCaseSensitive write SetCaseSensitive;
- end;
- //Group of lookup tables
- TLookupTables = class(TPersistent)
- private
- FOwner: TRecords;
- FItems: TList;
- function GetItem(Index: Integer): TLookupTable;
- public
- constructor Create(AOwner: TRecords);
- destructor Destroy; override;
- function Add: TLookupTable;
- procedure Delete(const Index: Integer);
- procedure Clear;
- function Count: Integer;
- function TableByName(const Name: String): TLookupTable;
- procedure Load;
- property Items[Index: Integer]: TLookupTable read GetItem; default;
- end;
- //Individual property of a specific record
- TRecordProp = class(TPersistent)
- private
- FOwner: TRecord;
- FName: String;
- FValue: String;
- FPropType: TFieldLinkType;
- FLookup: String;
- function Encode(const Value: String): String;
- function Decode(const Value: String): String;
- function GetAsBoolean: Boolean;
- function GetAsFloat: Double;
- function GetAsInteger: Integer;
- function GetAsString: String;
- procedure SetAsBoolean(const Value: Boolean);
- procedure SetAsFloat(const Value: Double);
- procedure SetAsInteger(const Value: Integer);
- procedure SetAsString(const Value: String);
- procedure SetName(const Value: String);
- procedure SetPropType(const Value: TFieldLinkType);
- procedure SetLookup(const Value: String);
- public
- constructor Create(AOwner: TRecord);
- destructor Destroy; override;
- property AsString: String read GetAsString write SetAsString;
- property AsInteger: Integer read GetAsInteger write SetAsInteger;
- property AsFloat: Double read GetAsFloat write SetAsFloat;
- property AsBoolean: Boolean read GetAsBoolean write SetAsBoolean;
- published
- property Name: String read FName write SetName;
- property Lookup: String read FLookup write SetLookup;
- property PropType: TFieldLinkType read FPropType write SetPropType;
- end;
- //Individual unique record from a data source
- TRecord = class(TPersistent)
- private
- FOwner: TRecords;
- FProps: TList;
- FID: Integer;
- FCaption: String;
- procedure SetCaption(const Value: String);
- procedure SetID(const Value: Integer);
- function GetName(const Index: Integer): String;
- function GetPropByName(const Name: String): TRecordProp;
- public
- constructor Create(AOwner: TRecords);
- destructor Destroy; override;
- procedure Clear;
- function Count: Integer;
- procedure Delete(const Index: Integer);
- procedure Assign(Source: TPersistent); override;
- function IndexOfProp(const Name: String): Integer;
- function ReadString(const Name: String): String;
- function ReadInteger(const Name: String): Integer;
- function ReadFloat(const Name: String): Double;
- function ReadBoolean(const Name: String): Boolean;
- procedure WriteString(const Name, Value: String);
- procedure WriteInteger(const Name: String; const Value: Integer);
- procedure WriteFloat(const Name: String; const Value: Double);
- procedure WriteBoolean(const Name: String; const Value: Boolean);
- property Names[const Index: Integer]: String read GetName;
- property PropByName[const Name: String]: TRecordProp
- read GetPropByName;
- property AsString[const Name: String]: String
- read ReadString write WriteString;
- property AsInteger[const Name: String]: Integer
- read ReadInteger write WriteInteger;
- property AsFloat[const Name: String]: Double
- read ReadFloat write WriteFloat;
- property AsBoolean[const Name: String]: Boolean
- read ReadBoolean write WriteBoolean;
- published
- property ID: Integer read FID write SetID;
- property Caption: String read FCaption write SetCaption;
- end;
- //Group of records from a data source
- TRecords = class(TPersistent)
- private
- FOwner: TDataPump;
- FItems: TList;
- FLookup: TLookupTables;
- function GetRecord(Index: Integer): TRecord;
- public
- constructor Create(AOwner: TDataPump);
- destructor Destroy; override;
- function Add: TRecord;
- procedure Delete(const Index: Integer);
- procedure Clear;
- function Count: Integer;
- function IndexOf(const ID: Integer): Integer; overload;
- function IndexOf(const Caption: String): Integer; overload;
- function IndexOf(ARecord: TRecord): Integer; overload;
- property Records[Index: Integer]: TRecord read GetRecord; default;
- end;
- //Individual possible database connection
- TConnection = class(TPersistent)
- private
- FOwner: TConnections;
- FConnection: TADOConnection;
- FActive: Boolean;
- FCaption: String;
- FConnectionString: String;
- FOnConnect: TConnectedEvent;
- procedure DoOnConnect(const Connected: Boolean);
- procedure DBConnect(Sender: TObject);
- procedure DBDisconnect(Sender: TObject);
- procedure SetActive(const Value: Boolean);
- procedure SetConnectionString(const Value: String);
- procedure SetCaption(const Value: String);
- public
- constructor Create(AOwner: TConnections);
- destructor Destroy; override;
- procedure Connect;
- procedure Disconnect;
- function Perspective: TPerspective;
- function NewQuery: TADOQuery;
- function ExecSQL(const SQL: String): Integer;
- function Connected: Boolean;
- published
- property Active: Boolean read FActive write SetActive;
- property Caption: String read FCaption write SetCaption;
- property ConnectionString: String read FConnectionString write SetConnectionString;
- property OnConnect: TConnectedEvent read FOnConnect write FOnConnect;
- end;
- //Group of database connections
- TConnections = class(TPersistent)
- private
- FOwner: TDataPump;
- FItems: TList;
- procedure DBConnection(Sender: TObject; const Perspective: TPerspective;
- const Connected: Boolean);
- function GetConnection(Index: Integer): TConnection;
- public
- constructor Create(AOwner: TDataPump);
- destructor Destroy; override;
- function Owner: TDataPump;
- function Count: Integer;
- procedure Clear;
- procedure Delete(const Index: Integer);
- function Add: TConnection;
- function IndexOf(Source: TConnection): Integer;
- property Items[Index: Integer]: TConnection read GetConnection; default;
- end;
- //Individual possible property of a particular entity
- TEntityProp = class(TPersistent)
- private
- FOwner: TEntity;
- FName: String;
- FIsPrimaryKey: Boolean;
- FIsIdentity: Boolean;
- FIsReadOnly: Boolean;
- FSize: Integer;
- FLinkType: TFieldLinkType;
- FLookupName: String;
- procedure SetIsIdentity(const Value: Boolean);
- procedure SetIsPrimaryKey(const Value: Boolean);
- procedure SetIsReadOnly(const Value: Boolean);
- procedure SetName(const Value: String);
- procedure SetSize(const Value: Integer);
- procedure SetLinkType(const Value: TFieldLinkType);
- procedure SetLookupName(const Value: String);
- public
- constructor Create(AOwner: TEntity);
- destructor Destroy; override;
- published
- property Name: String read FName write SetName;
- property Size: Integer read FSize write SetSize;
- property LinkType: TFieldLinkType read FLinkType write SetLinkType;
- property LookupName: String read FLookupName write SetLookupName;
- property IsPrimaryKey: Boolean
- read FIsPrimaryKey write SetIsPrimaryKey;
- property IsIdentity: Boolean
- read FIsIdentity write SetIsIdentity;
- property IsReadOnly: Boolean
- read FIsReadOnly write SetIsReadOnly;
- end;
- //Mapping for ommonly shared type of data source
- TEntity = class(TPersistent)
- private
- FOwner: TEntities;
- FProps: TList;
- FFilename: String;
- FName: String;
- FCaption: String;
- FDescription: String;
- procedure SetCaption(const Value: String);
- procedure SetDescription(const Value: String);
- procedure SetFilename(const Value: String);
- procedure SetName(const Value: String);
- function GetProp(Index: Integer): TEntityProp;
- public
- constructor Create(AOwner: TEntities);
- destructor Destroy; override;
- function PathAndFilename: String;
- procedure LoadFromFile;
- procedure SaveToFile;
- procedure Clear;
- function Count: Integer;
- procedure Delete(const Index: Integer);
- property Props[Index: Integer]: TEntityProp read GetProp; default;
- published
- property Name: String read FName write SetName;
- property Caption: String read FCaption write SetCaption;
- property Description: String read FDescription write SetDescription;
- property Filename: String read FFilename write SetFilename;
- end;
- //Group of entity mappings
- TEntities = class(TPersistent)
- private
- FOwner: TDataPump;
- FItems: TList;
- function GetItem(Index: Integer): TEntity;
- public
- constructor Create(AOwner: TDataPump);
- destructor Destroy; override;
- function Owner: TDataPump;
- function Count: Integer;
- procedure Clear;
- procedure Delete(const Index: Integer);
- function Add: TEntity;
- function IndexOf(Source: TEntity): Integer;
- property Items[Index: Integer]: TEntity read GetItem; default;
- end;
- //Individual field of a database's schema for a particular entity
- TSchemaLink = class(TPersistent)
- private
- FOwner: TSchemaLinks;
- FName: String;
- FLookup: Boolean;
- FLookupTable: String;
- FFieldName: String;
- FLookupID: String;
- FLookupCaption: String;
- FIsPrimaryKey: Boolean;
- FIsIdentity: Boolean;
- FIsReadOnly: Boolean;
- FAlias: String;
- procedure SetFieldName(const Value: String);
- procedure SetLookup(const Value: Boolean);
- procedure SetLookupCaption(const Value: String);
- procedure SetLookupID(const Value: String);
- procedure SetLookupTable(const Value: String);
- procedure SetName(const Value: String);
- procedure SetIsIdentity(const Value: Boolean);
- procedure SetIsPrimaryKey(const Value: Boolean);
- procedure SetIsReadOnly(const Value: Boolean);
- procedure SetAlias(const Value: String);
- public
- constructor Create(AOwner: TSchemaLinks);
- destructor Destroy; override;
- published
- property Name: String read FName write SetName;
- property Alias: String read FAlias write SetAlias;
- property FieldName: String read FFieldName write SetFieldName;
- property Lookup: Boolean read FLookup write SetLookup;
- property LookupTable: String read FLookupTable write SetLookupTable;
- property LookupID: String read FLookupID write SetLookupID;
- property LookupCaption: String read FLookupCaption write SetLookupCaption;
- property IsPrimaryKey: Boolean
- read FIsPrimaryKey write SetIsPrimaryKey;
- property IsIdentity: Boolean
- read FIsIdentity write SetIsIdentity;
- property IsReadOnly: Boolean
- read FIsReadOnly write SetIsReadOnly;
- end;
- //Group of field links for a Schema
- TSchemaLinks = class(TPersistent)
- private
- FOwner: TSchema;
- FItems: TList;
- function GetItem(Index: Integer): TSchemaLink;
- public
- constructor Create(AOwner: TSchema);
- destructor Destroy; override;
- function Owner: TSchema;
- function Count: Integer;
- procedure Clear;
- procedure Delete(const Index: Integer);
- function Add: TSchemaLink;
- function IndexOf(Source: TSchemaLink): Integer;
- property Items[Index: Integer]: TSchemaLink read GetItem; default;
- end;
- //Mapping of a particular database to a particular entity
- TSchema = class(TPersistent)
- private
- FOwner: TSchemas;
- FLinks: TSchemaLinks;
- FEntity: String;
- FJoins: TStringList;
- FMatch: TStringList;
- FTableName: String;
- FAlias: String;
- FIDField: String;
- FCaptionField: String;
- FFilename: String;
- FUpdateSQL: String;
- FCheckSQL: String;
- FInsertSQL: String;
- procedure SetLinks(const Value: TSchemaLinks);
- procedure SetEntity(const Value: String);
- function GetJoins: TStrings;
- procedure SetJoins(const Value: TStrings);
- procedure Clear;
- function GetMatch: TStrings;
- procedure SetMatch(const Value: TStrings);
- procedure SetAlias(const Value: String);
- procedure SetCaptionField(const Value: String);
- procedure SetIDField(const Value: String);
- procedure SetTableName(const Value: String);
- procedure SetFilename(const Value: String);
- procedure SetCheckSQL(const Value: String);
- procedure SetInsertSQL(const Value: String);
- procedure SetUpdateSQL(const Value: String);
- public
- constructor Create(AOwner: TSchemas);
- destructor Destroy; override;
- function PathAndFilename: String;
- procedure LoadFromFile;
- procedure SaveToFile;
- published
- property Filename: String read FFilename write SetFilename;
- property Links: TSchemaLinks read FLinks write SetLinks;
- property Entity: String read FEntity write SetEntity;
- property Joins: TStrings read GetJoins write SetJoins;
- property Match: TStrings read GetMatch write SetMatch;
- property TableName: String read FTableName write SetTableName;
- property Alias: String read FAlias write SetAlias;
- property IDField: String read FIDField write SetIDField;
- property CaptionField: String read FCaptionField write SetCaptionField;
- property InsertSQL: String read FInsertSQL write SetInsertSQL;
- property UpdateSQL: String read FUpdateSQL write SetUpdateSQL;
- property CheckSQL: String read FCheckSQL write SetCheckSQL;
- end;
- //Group of schemas
- TSchemas = class(TPersistent)
- private
- FOwner: TDataPump;
- FItems: TList;
- public
- constructor Create(AOwner: TDataPump);
- destructor Destroy; override;
- function Owner: TDataPump;
- function Count: Integer;
- procedure Clear;
- procedure Delete(const Index: Integer);
- function Add: TSchema;
- function IndexOf(Source: TSchema): Integer;
- end;
- //Primary component - pumps data from source database to destination
- TDataPump = class(TComponent)
- private
- FConnections: TConnections;
- FEntities: TEntities;
- FSchemas: TSchemas;
- FRecords: TRecords;
- FRootDir: String;
- FActive: Boolean;
- FDBSourceIndex: Integer;
- FDBDestIndex: Integer;
- FWhereSQL: TStringList;
- FOnConnect: TConnectedEvent;
- FEntityIndex: Integer;
- procedure SetConnections(const Value: TConnections);
- procedure SetEntities(const Value: TEntities);
- procedure SetRootDir(const Value: String);
- procedure SetActive(const Value: Boolean);
- procedure SetDBDestIndex(const Value: Integer);
- procedure SetDBSourceIndex(const Value: Integer);
- function GetWhereSQL: TStrings;
- procedure SetWhereSQL(const Value: TStrings);
- function CanConnect: Boolean;
- function Connected: Boolean;
- function GetRootDir: String;
- procedure SetEntityIndex(const Value: Integer);
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Connect;
- procedure Disconnect;
- function Source: TConnection;
- function Dest: TConnection;
- function Entity: TEntity;
- published
- property Active: Boolean read FActive write SetActive;
- property Connections: TConnections read FConnections write SetConnections;
- property Entities: TEntities read FEntities write SetEntities;
- property RootDir: String read GetRootDir write SetRootDir;
- property DBSourceIndex: Integer read FDBSourceIndex write SetDBSourceIndex;
- property DBDestIndex: Integer read FDBDestIndex write SetDBDestIndex;
- property EntityIndex: Integer read FEntityIndex write SetEntityIndex;
- property WhereSQL: TStrings read GetWhereSQL write SetWhereSQL;
- property OnConnect: TConnectedEvent read FOnConnect write FOnConnect;
- end;
- procedure ClipCopy(const S: String);
- implementation
- procedure ClipCopy(const S: String);
- begin
- {$IFDEF DEBUG}
- Clipboard.AsText:= S;
- {$ENDIF}
- end;
- procedure EraseINI(AIniFile: TIniFile);
- var
- L: TStringList;
- X: Integer;
- begin
- if Assigned(AIniFile) then begin
- L:= TStringList.Create;
- try
- AIniFile.ReadSections(L);
- for X := 0 to L.Count - 1 do
- AIniFile.EraseSection(L[X]);
- finally
- L.Free;
- end;
- end;
- end;
- { TLookupItem }
- constructor TLookupItem.Create(AOwner: TLookupTable);
- begin
- FID:= 0;
- FValue:= '';
- end;
- destructor TLookupItem.Destroy;
- begin
- inherited;
- end;
- procedure TLookupItem.SetID(const Value: Integer);
- begin
- FID := Value;
- end;
- procedure TLookupItem.SetValue(const Value: String);
- begin
- FValue := Value;
- end;
- { TLookupTable }
- constructor TLookupTable.Create(AOwner: TLookupTables);
- begin
- FOwner:= AOwner;
- FItems:= TList.Create;
- FLastID:= 0;
- CaseSensitive:= False;
- end;
- destructor TLookupTable.Destroy;
- begin
- Clear;
- FItems.Free;
- inherited;
- end;
- function TLookupTable.GetItem(const Index: Integer): TLookupItem;
- begin
- Result:= TLookupItem(FItems[Index]);
- end;
- procedure TLookupTable.Delete(const Index: Integer);
- begin
- TLookupItem(FItems[Index]).Free;
- FItems.Delete(Index);
- end;
- procedure TLookupTable.Clear;
- begin
- while Count > 0 do
- Delete(0);
- end;
- function TLookupTable.Count: Integer;
- begin
- Result:= FItems.Count;
- end;
- function TLookupTable.Lookup(const Value: String;
- const CanCreate: Boolean): Integer;
- var
- X: Integer;
- I: TLookupItem;
- V1, V2: String;
- begin
- Result:= 0;
- for X := 0 to FItems.Count - 1 do begin
- I:= TLookupItem(FItems[X]);
- if CaseSensitive then begin
- V1:= LowerCase(Value);
- V2:= LowerCase(I.FValue);
- end else begin
- V1:= Value;
- V2:= I.FValue;
- end;
- if V1 = V2 then begin
- Result:= X;
- Break;
- end;
- end;
- if Result = 0 then begin
- if CanCreate then begin
- Result:= Add(Value).ID;
- end;
- end;
- end;
- procedure TLookupTable.SetCaseSensitive(const Value: Boolean);
- begin
- FCaseSensitive := Value;
- end;
- procedure TLookupTable.SetName(const Value: String);
- begin
- FName := Value;
- end;
- function TLookupTable.NewID: Integer;
- begin
- Inc(FLastID);
- Result:= FLastID;
- end;
- function TLookupTable.Add: TLookupItem;
- begin
- Result:= TLookupItem.Create(Self);
- FItems.Add(Result);
- Result.FID:= NewID;
- end;
- function TLookupTable.Add(const Value: String): TLookupItem;
- begin
- end;
- { TLookupTables }
- constructor TLookupTables.Create(AOwner: TRecords);
- begin
- FOwner:= AOwner;
- FItems:= TList.Create;
- end;
- destructor TLookupTables.Destroy;
- begin
- Clear;
- FItems.Free;
- inherited;
- end;
- function TLookupTables.GetItem(Index: Integer): TLookupTable;
- begin
- Result:= TLookupTable(FItems[Index]);
- end;
- procedure TLookupTables.Load;
- var
- X, Y: Integer;
- T: TLookupTable;
- I: TLookupItem;
- E: TEntity;
- P: TEntityProp;
- begin
- Clear;
- E:= FOwner.FOwner.Entity;
- for X := 0 to E.Count - 1 do begin
- P:= E[X];
- if P.LookupName <> '' then begin
- T:= TableByName(P.LookupName);
- if not Assigned(T) then begin
- T:= Self.Add;
- T.Name:= P.LookupName;
- end;
- end;
- end;
- for X := 0 to Count - 1 do begin
- T:= Items[X];
- end;
- end;
- function TLookupTables.Add: TLookupTable;
- begin
- Result:= TLookupTable.Create(Self);
- FItems.Add(Result);
- end;
- procedure TLookupTables.Clear;
- begin
- while Count > 0 do
- Delete(0);
- end;
- function TLookupTables.Count: Integer;
- begin
- Result:= FItems.Count;
- end;
- procedure TLookupTables.Delete(const Index: Integer);
- begin
- TLookupTable(FItems[Index]).Free;
- FItems.Delete(Index);
- end;
- function TLookupTables.TableByName(const Name: String): TLookupTable;
- var
- X: Integer;
- T: TLookupTable;
- begin
- Result:= nil;
- for X := 0 to Count - 1 do begin
- T:= TLookupTable(FItems[X]);
- if UpperCase(T.Name) = UpperCase(Name) then begin
- Result:= T;
- Break;
- end;
- end;
- end;
- { TRecordProp }
- constructor TRecordProp.Create(AOwner: TRecord);
- begin
- end;
- destructor TRecordProp.Destroy;
- begin
- inherited;
- end;
- function TRecordProp.Encode(const Value: String): String;
- begin
- Result:= StringReplace(Value, '<', '<', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '>', '>', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '&', '&', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '''', ''', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '"', '"', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, #10, '&lb10;', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, #13, '&lb13;', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '=', '&equ;', [rfReplaceAll,rfIgnoreCase]);
- end;
- function TRecordProp.Decode(const Value: String): String;
- begin
- Result:= StringReplace(Value, '<', '<', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '>', '>', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '&', '&', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, ''', '''', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '"', '"', [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '&lb10;', #10, [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '&lb13;', #13, [rfReplaceAll,rfIgnoreCase]);
- Result:= StringReplace(Result, '&equ;', '=', [rfReplaceAll,rfIgnoreCase]);
- end;
- procedure TRecordProp.SetLookup(const Value: String);
- begin
- FLookup := Value;
- end;
- function TRecordProp.GetAsString: String;
- var
- T: TLookupTable;
- I: Integer;
- begin
- if FLookup <> '' then begin
- T:= FOwner.FOwner.FLookup.TableByName(FLookup);
- end else begin
- Result:= Decode(FValue);
- end;
- end;
- procedure TRecordProp.SetAsString(const Value: String);
- begin
- FValue:= Encode(Value);
- end;
- function TRecordProp.GetAsInteger: Integer;
- begin
- Result:= StrToIntDef(AsString, 0);
- end;
- procedure TRecordProp.SetAsInteger(const Value: Integer);
- begin
- AsString:= IntToStr(Value);
- end;
- function TRecordProp.GetAsFloat: Double;
- begin
- Result:= StrToFloatDef(AsString, 0);
- end;
- procedure TRecordProp.SetAsFloat(const Value: Double);
- begin
- AsString:= FloatToStr(Value);
- end;
- function TRecordProp.GetAsBoolean: Boolean;
- var
- V: String;
- begin
- V:= UpperCase(AsString);
- Result:= (V = 'Y') or (V = 'YES') or (V = 'T') or (V = 'TRUE') or (V = '1');
- end;
- procedure TRecordProp.SetAsBoolean(const Value: Boolean);
- begin
- if Value then
- AsString:= '1'
- else
- AsString:= '0';
- end;
- procedure TRecordProp.SetName(const Value: String);
- begin
- FName := Value;
- end;
- procedure TRecordProp.SetPropType(const Value: TFieldLinkType);
- begin
- FPropType := Value;
- end;
- { TRecord }
- constructor TRecord.Create(AOwner: TRecords);
- begin
- FOwner:= AOwner;
- FProps:= TList.Create;
- end;
- destructor TRecord.Destroy;
- begin
- Clear;
- FProps.Free;
- inherited;
- end;
- procedure TRecord.Assign(Source: TPersistent);
- begin
- if Source is TRecord then begin
- FProps.Assign((Source as TRecord).FProps);
- end else begin
- raise Exception.Create('Source must be of type "TRecord"');
- end;
- end;
- procedure TRecord.Clear;
- begin
- while Count > 0 do
- Delete(0);
- end;
- function TRecord.Count: Integer;
- begin
- Result:= FProps.Count;
- end;
- procedure TRecord.Delete(const Index: Integer);
- begin
- TRecordProp(FProps[Index]).Free;
- FProps.Delete(Index);
- end;
- function TRecord.GetName(const Index: Integer): String;
- begin
- Result:= TRecordProp(FProps[Index]).Name;
- end;
- function TRecord.IndexOfProp(const Name: String): Integer;
- var
- X: Integer;
- begin
- Result:= -1;
- for X := 0 to Count - 1 do begin
- if LowerCase(Name) = LowerCase(TRecordProp(FProps[X]).Name) then begin
- Result:= X;
- Break;
- end;
- end;
- end;
- function TRecord.GetPropByName(const Name: String): TRecordProp;
- var
- I: Integer;
- begin
- I:= IndexOfProp(Name);
- if I = -1 then begin
- Result:= TRecordProp.Create(Self);
- FProps.Add(Result);
- Result.FName:= Name;
- end else begin
- Result:= TRecordProp(FProps[IndexOfProp(Name)]);
- end;
- end;
- procedure TRecord.SetCaption(const Value: String);
- begin
- FCaption := Value;
- end;
- procedure TRecord.SetID(const Value: Integer);
- begin
- FID := Value;
- end;
- function TRecord.ReadString(const Name: String): String;
- begin
- Result:= PropByName[Name].AsString;
- end;
- procedure TRecord.WriteString(const Name, Value: String);
- begin
- PropByName[Name].AsString:= Value;
- end;
- function TRecord.ReadInteger(const Name: String): Integer;
- begin
- Result:= PropByName[Name].AsInteger;
- end;
- procedure TRecord.WriteInteger(const Name: String; const Value: Integer);
- begin
- PropByName[Name].AsInteger:= Value;
- end;
- function TRecord.ReadFloat(const Name: String): Double;
- begin
- Result:= PropByName[Name].AsFloat;
- end;
- procedure TRecord.WriteFloat(const Name: String; const Value: Double);
- begin
- PropByName[Name].AsFloat:= Value;
- end;
- function TRecord.ReadBoolean(const Name: String): Boolean;
- begin
- Result:= PropByName[Name].AsBoolean;
- end;
- procedure TRecord.WriteBoolean(const Name: String; const Value: Boolean);
- begin
- PropByName[Name].AsBoolean:= Value;
- end;
- { TRecords }
- constructor TRecords.Create(AOwner: TDataPump);
- begin
- FOwner:= AOwner;
- FLookup:= TLookupTables.Create(Self);
- FItems:= TList.Create;
- end;
- destructor TRecords.Destroy;
- begin
- Clear;
- FItems.Free;
- FLookup.Free;
- inherited;
- end;
- function TRecords.GetRecord(Index: Integer): TRecord;
- begin
- Result:= TRecord(FItems[Index]);
- end;
- function TRecords.Add: TRecord;
- begin
- Result:= TRecord.Create(Self);
- FItems.Add(Result);
- end;
- procedure TRecords.Clear;
- begin
- while Count > 0 do
- Delete(0);
- end;
- function TRecords.Count: Integer;
- begin
- Result:= FItems.Count;
- end;
- procedure TRecords.Delete(const Index: Integer);
- begin
- TRecord(FItems[Index]).Free;
- FItems.Delete(Index);
- end;
- function TRecords.IndexOf(const Caption: String): Integer;
- var
- X: Integer;
- begin
- Result:= -1;
- for X := 0 to FItems.Count - 1 do begin
- if LowerCase(TRecord(FItems[X]).Caption) = LowerCase(Caption) then begin
- Result:= X;
- Break;
- end;
- end;
- end;
- function TRecords.IndexOf(const ID: Integer): Integer;
- var
- X: Integer;
- begin
- Result:= -1;
- for X := 0 to FItems.Count - 1 do begin
- if TRecord(FItems[X]).ID = ID then begin
- Result:= X;
- Break;
- end;
- end;
- end;
- function TRecords.IndexOf(ARecord: TRecord): Integer;
- begin
- Result:= FItems.IndexOf(ARecord);
- end;
- { TConnection }
- function TConnection.Connected: Boolean;
- begin
- Result:= FConnection.Connected;
- end;
- constructor TConnection.Create(AOwner: TConnections);
- begin
- FOwner:= AOwner;
- FConnection:= TADOConnection.Create(nil);
- FConnection.LoginPrompt:= False;
- FConnection.AfterConnect:= DBConnect;
- FConnection.AfterDisconnect:= DBDisconnect;
- end;
- destructor TConnection.Destroy;
- begin
- Disconnect;
- FConnection.Free;
- inherited;
- end;
- procedure TConnection.DBConnect(Sender: TObject);
- begin
- DoOnConnect(True);
- end;
- procedure TConnection.DBDisconnect(Sender: TObject);
- begin
- DoOnConnect(False);
- end;
- procedure TConnection.Connect;
- begin
- if not FActive then begin
- FActive:= True;
- FConnection.ConnectionString:= FConnectionString;
- FConnection.Connected:= True;
- end;
- end;
- procedure TConnection.Disconnect;
- begin
- if FActive then begin
- FActive:= False;
- FConnection.Connected:= False;
- end;
- end;
- procedure TConnection.DoOnConnect(const Connected: Boolean);
- begin
- if assigned(FOnConnect) then
- FOnConnect(Self, Perspective, Connected);
- end;
- function TConnection.ExecSQL(const SQL: String): Integer;
- var
- Q: TADOQuery;
- begin
- Q:= NewQuery;
- try
- Q.SQL.Text:= SQL;
- Result:= Q.ExecSQL;
- finally
- Q.Free;
- end;
- end;
- function TConnection.NewQuery: TADOQuery;
- begin
- Result:= TADOQuery.Create(nil);
- Result.Connection:= FConnection;
- end;
- function TConnection.Perspective: TPerspective;
- begin
- if (Self = FOwner.FOwner.Dest) then
- Result:= psSource
- else if (Self = FOwner.FOwner.Source) then
- Result:= psDestination
- else
- Result:= psNone;
- end;
- procedure TConnection.SetActive(const Value: Boolean);
- begin
- if Value then begin
- Connect;
- end else begin
- Disconnect;
- end;
- end;
- procedure TConnection.SetCaption(const Value: String);
- begin
- FCaption := Value;
- end;
- procedure TConnection.SetConnectionString(const Value: String);
- begin
- FConnectionString:= Value;
- end;
- { TConnections }
- constructor TConnections.Create(AOwner: TDataPump);
- begin
- FOwner:= AOwner;
- FItems:= TList.Create;
- end;
- destructor TConnections.Destroy;
- begin
- Clear;
- FItems.Free;
- inherited;
- end;
- function TConnections.GetConnection(Index: Integer): TConnection;
- begin
- Result:= TConnection(FItems[Index]);
- end;
- procedure TConnections.DBConnection(Sender: TObject;
- const Perspective: TPerspective; const Connected: Boolean);
- begin
- if assigned(FOwner.OnConnect) then
- FOwner.OnConnect(FOwner, Perspective, Connected);
- end;
- function TConnections.Add: TConnection;
- begin
- Result:= TConnection.Create(Self);
- Result.OnConnect:= DBConnection;
- FItems.Add(Result);
- end;
- procedure TConnections.Clear;
- begin
- while Count > 0 do
- Delete(0);
- end;
- function TConnections.Count: Integer;
- begin
- Result:= FItems.Count;
- end;
- procedure TConnections.Delete(const Index: Integer);
- begin
- TConnection(FItems[Index]).Free;
- FItems.Delete(Index);
- end;
- function TConnections.IndexOf(Source: TConnection): Integer;
- begin
- Result:= FItems.IndexOf(Source);
- end;
- function TConnections.Owner: TDataPump;
- begin
- Result:= FOwner;
- end;
- { TEntityProp }
- constructor TEntityProp.Create(AOwner: TEntity);
- begin
- FOwner:= AOwner;
- FName:= '';
- FSize:= 0;
- end;
- destructor TEntityProp.Destroy;
- begin
- inherited;
- end;
- procedure TEntityProp.SetIsIdentity(const Value: Boolean);
- begin
- FIsIdentity := Value;
- end;
- procedure TEntityProp.SetIsPrimaryKey(const Value: Boolean);
- begin
- FIsPrimaryKey := Value;
- end;
- procedure TEntityProp.SetIsReadOnly(const Value: Boolean);
- begin
- FIsReadOnly := Value;
- end;
- procedure TEntityProp.SetLinkType(const Value: TFieldLinkType);
- begin
- FLinkType := Value;
- end;
- procedure TEntityProp.SetLookupName(const Value: String);
- begin
- FLookupName := Value;
- end;
- procedure TEntityProp.SetName(const Value: String);
- begin
- FName := Value;
- end;
- procedure TEntityProp.SetSize(const Value: Integer);
- begin
- FSize := Value;
- end;
- { TEntity }
- constructor TEntity.Create(AOwner: TEntities);
- begin
- FOwner:= AOwner;
- FProps:= TList.Create;
- end;
- procedure TEntity.Delete(const Index: Integer);
- begin
- TEntityProp(FProps[Index]).Free;
- FProps.Delete(Index);
- end;
- destructor TEntity.Destroy;
- begin
- Clear;
- FProps.Free;
- inherited;
- end;
- procedure TEntity.Clear;
- begin
- while Count > 0 do
- Delete(0);
- end;
- function TEntity.Count: Integer;
- begin
- Result:= FProps.Count;
- end;
- function TEntity.GetProp(Index: Integer): TEntityProp;
- begin
- Result:= TEntityProp(FProps[Index]);
- end;
- function TEntity.PathAndFilename: String;
- begin
- Result:= FOwner.FOwner.RootDir + 'Entities\'+FFilename;
- end;
- procedure TEntity.LoadFromFile;
- var
- I: TIniFile;
- L: TStringList;
- X: Integer;
- SN: String;
- P: TEntityProp;
- T: String; //Temp
- function IsPropSection(const SectionName: String): Boolean;
- var
- S: String;
- begin
- S:= LowerCase(SectionName);
- Result:= (S <> 'table:settings');
- end;
- begin
- I:= TIniFile.Create(PathAndFilename);
- try
- FName:= I.ReadString('table', 'name', '');
- FCaption:= I.ReadString('table', 'caption', '');
- FDescription:= I.ReadString('table', 'description', '');
- L:= TStringList.Create;
- try
- I.ReadSections(L);
- for X := 0 to L.Count - 1 do begin
- SN:= LowerCase(L[X]);
- if IsPropSection(SN) then begin
- P:= TEntityProp.Create(Self);
- P.FName:= SN;
- P.FSize:= I.ReadInteger(SN, 'size', 0);
- P.FIsPrimaryKey:= I.ReadBool(SN, 'pk', False);
- P.FIsIdentity:= I.ReadBool(SN, 'id', False);
- P.FIsReadOnly:= I.ReadBool(SN, 'ro', False);
- T:= LowerCase(I.ReadString(SN, 'type', 'string'));
- if T = 'string' then begin
- P.FLinkType:= flText;
- end else
- if T = 'integer' then begin
- P.FLinkType:= flInt;
- end else
- if T = 'float' then begin
- P.FLinkType:= flFloat;
- end else
- if T = 'boolean' then begin
- P.FLinkType:= flBool;
- end else begin
- P.FLinkType:= flText;
- end;
- end;
- end;
- finally
- L.Free;
- end;
- finally
- I.Free;
- end;
- end;
- procedure TEntity.SaveToFile;
- var
- I: TIniFile;
- begin
- I:= TIniFile.Create(PathAndFilename);
- try
- I.WriteString('table', 'name', FName);
- I.WriteString('table', 'caption', FCaption);
- I.WriteString('table', 'description', FDescription);
- finally
- I.Free;
- end;
- end;
- procedure TEntity.SetCaption(const Value: String);
- begin
- FCaption := Value;
- end;
- procedure TEntity.SetDescription(const Value: String);
- begin
- FDescription := Value;
- end;
- procedure TEntity.SetFilename(const Value: String);
- begin
- FFilename := Value;
- end;
- procedure TEntity.SetName(const Value: String);
- begin
- FName := Value;
- end;
- { TEntities }
- constructor TEntities.Create(AOwner: TDataPump);
- begin
- FOwner:= AOwner;
- FItems:= TList.Create;
- end;
- destructor TEntities.Destroy;
- begin
- Clear;
- FItems.Free;
- inherited;
- end;
- function TEntities.GetItem(Index: Integer): TEntity;
- begin
- Result:= TEntity(FItems[Index]);
- end;
- function TEntities.Add: TEntity;
- begin
- Result:= TEntity.Create(Self);
- FItems.Add(Result);
- end;
- procedure TEntities.Clear;
- begin
- while Count > 0 do
- Delete(0);
- end;
- function TEntities.Count: Integer;
- begin
- Result:= FItems.Count;
- end;
- procedure TEntities.Delete(const Index: Integer);
- begin
- TEntity(FItems[Index]).Free;
- FItems.Delete(Index);
- end;
- function TEntities.IndexOf(Source: TEntity): Integer;
- begin
- Result:= FItems.IndexOf(Source);
- end;
- function TEntities.Owner: TDataPump;
- begin
- Result:= FOwner;
- end;
- { TSchemaLink }
- constructor TSchemaLink.Create(AOwner: TSchemaLinks);
- begin
- FOwner:= AOwner;
- end;
- destructor TSchemaLink.Destroy;
- begin
- inherited;
- end;
- procedure TSchemaLink.SetAlias(const Value: String);
- begin
- FAlias := Value;
- end;
- procedure TSchemaLink.SetFieldName(const Value: String);
- begin
- FFieldName := Value;
- end;
- procedure TSchemaLink.SetIsIdentity(const Value: Boolean);
- begin
- FIsIdentity := Value;
- end;
- procedure TSchemaLink.SetIsPrimaryKey(const Value: Boolean);
- begin
- FIsPrimaryKey := Value;
- end;
- procedure TSchemaLink.SetIsReadOnly(const Value: Boolean);
- begin
- FIsReadOnly := Value;
- end;
- procedure TSchemaLink.SetLookup(const Value: Boolean);
- begin
- FLookup := Value;
- end;
- procedure TSchemaLink.SetLookupCaption(const Value: String);
- begin
- FLookupCaption := Value;
- end;
- procedure TSchemaLink.SetLookupID(const Value: String);
- begin
- FLookupID := Value;
- end;
- procedure TSchemaLink.SetLookupTable(const Value: String);
- begin
- FLookupTable := Value;
- end;
- procedure TSchemaLink.SetName(const Value: String);
- begin
- FName := Value;
- end;
- { TSchemaLinks }
- constructor TSchemaLinks.Create(AOwner: TSchema);
- begin
- FOwner:= AOwner;
- FItems:= TList.Create;
- end;
- destructor TSchemaLinks.Destroy;
- begin
- Clear;
- FItems.Free;
- inherited;
- end;
- function TSchemaLinks.GetItem(Index: Integer): TSchemaLink;
- begin
- Result:= TSchemaLink(FItems[Index]);
- end;
- function TSchemaLinks.Add: TSchemaLink;
- begin
- Result:= TSchemaLink.Create(Self);
- FItems.Add(Result);
- end;
- procedure TSchemaLinks.Clear;
- begin
- while Count > 0 do
- Delete(0);
- end;
- function TSchemaLinks.Count: Integer;
- begin
- Result:= FItems.Count;
- end;
- procedure TSchemaLinks.Delete(const Index: Integer);
- begin
- TSchemaLink(FItems[Index]).Free;
- FItems.Delete(Index);
- end;
- function TSchemaLinks.IndexOf(Source: TSchemaLink): Integer;
- begin
- Result:= FItems.IndexOf(Source);
- end;
- function TSchemaLinks.Owner: TSchema;
- begin
- Result:= FOwner;
- end;
- { TSchema }
- constructor TSchema.Create(AOwner: TSchemas);
- begin
- FOwner:= AOwner;
- FLinks:= TSchemaLinks.Create(Self);
- FJoins:= TStringList.Create;
- FMatch:= TStringList.Create;
- end;
- destructor TSchema.Destroy;
- begin
- FMatch.Free;
- FJoins.Free;
- Clear;
- FLinks.Free;
- inherited;
- end;
- procedure TSchema.Clear;
- begin
- FJoins.Clear;
- FLinks.Clear;
- end;
- function TSchema.GetJoins: TStrings;
- begin
- Result:= TStrings(FJoins);
- end;
- function TSchema.GetMatch: TStrings;
- begin
- Result:= TStrings(FMatch);
- end;
- function TSchema.PathAndFilename: String;
- begin
- Result:= IncludeTrailingBackslash(FOwner.FOwner.FRootDir)+FFilename;
- end;
- procedure TSchema.LoadFromFile;
- var
- I: TIniFile;
- L: TStringList;
- X: Integer;
- Link: TSchemaLink;
- SN: String;
- function IsFieldSection(const FieldName: String): Boolean;
- begin
- Result:= not ((Pos('<', FieldName) = 1) and (Pos('>', FieldName) > 1))
- end;
- begin
- Clear;
- I:= TIniFile.Create(PathAndFilename);
- try
- L:= TStringList.Create;
- try
- FTableName:= I.ReadString('<table>', 'tbl', '');
- FAlias:= I.ReadString('<table>', 'alias', '');
- FIDField:= I.ReadString('<table>', 'id', '');
- FCaptionField:= I.ReadString('<table>', 'caption', '');
- I.ReadSection('<match>', L);
- for X := 0 to L.Count - 1 do
- FMatch.Append(L.Values[L.Names[X]]);
- I.ReadSection('<joins>', L);
- for X := 0 to L.Count - 1 do
- FJoins.Append(L.Values[L.Names[X]]);
- I.ReadSections(L);
- for X := 0 to L.Count - 1 do begin
- SN:= L[X];
- if IsFieldSection(SN) then begin
- Link:= FLinks.Add;
- Link.FFieldName:= I.ReadString(SN, 'fld', '');
- Link.FName:= I.ReadString(SN, 'nam', '');
- Link.FAlias:= I.ReadString(SN, 'alias', '');
- Link.FLookupTable:= I.ReadString(SN, 'tbl', '');
- Link.FLookup:= Link.FLookupTable <> '';
- Link.FLookupID:= I.ReadString(SN, 'lnk', '');
- Link.FLookupCaption:= I.ReadString(SN, 'val', '');
- Link.FIsPrimaryKey:= I.ReadBool(SN, 'pk', False);
- Link.FIsIdentity:= I.ReadBool(SN, 'id', False);
- Link.FIsReadOnly:= I.ReadBool(SN, 'ro', Link.FIsIdentity);
- end;
- end;
- finally
- L.Free;
- end;
- finally
- I.Free;
- end;
- end;
- procedure TSchema.SaveToFile;
- var
- I: TIniFile;
- X: Integer;
- Link: TSchemaLink;
- begin
- I:= TIniFile.Create(PathAndFilename);
- try
- EraseINI(I);
- I.WriteString('<table>', 'tbl', FTableName);
- I.WriteString('<table>', 'alias', FAlias);
- I.WriteString('<table>', 'id', FIDField);
- I.WriteString('<table>', 'caption', FCaptionField);
- for X := 0 to FMatch.Count - 1 do
- I.WriteString('<match>', IntToStr(X), FMatch[X]);
- for X := 0 to FJoins.Count - 1 do
- I.WriteString('<joins>', IntToStr(X), FJoins[X]);
- for X := 0 to FLinks.Count - 1 do begin
- Link:= Links[X];
- I.WriteString(IntToStr(X), 'fld', Link.FFieldName);
- I.WriteString(IntToStr(X), 'nam', Link.FName);
- I.WriteString(IntToStr(X), 'alias', Link.FAlias);
- //I.WriteString(IntToStr(X), 'typ', Link);
- end;
- finally
- I.Free;
- end;
- end;
- procedure TSchema.SetAlias(const Value: String);
- begin
- FAlias := Value;
- end;
- procedure TSchema.SetCaptionField(const Value: String);
- begin
- FCaptionField := Value;
- end;
- procedure TSchema.SetCheckSQL(const Value: String);
- begin
- FCheckSQL := Value;
- end;
- procedure TSchema.SetEntity(const Value: String);
- begin
- FEntity := Value;
- end;
- procedure TSchema.SetFilename(const Value: String);
- begin
- FFilename := Value;
- end;
- procedure TSchema.SetIDField(const Value: String);
- begin
- FIDField := Value;
- end;
- procedure TSchema.SetInsertSQL(const Value: String);
- begin
- FInsertSQL := Value;
- end;
- procedure TSchema.SetJoins(const Value: TStrings);
- begin
- FJoins.Assign(Value);
- end;
- procedure TSchema.SetLinks(const Value: TSchemaLinks);
- begin
- FLinks.Assign(Value);
- end;
- procedure TSchema.SetMatch(const Value: TStrings);
- begin
- FMatch.Assign(Value);
- end;
- procedure TSchema.SetTableName(const Value: String);
- begin
- FTableName := Value;
- end;
- procedure TSchema.SetUpdateSQL(const Value: String);
- begin
- FUpdateSQL := Value;
- end;
- { TSchemas }
- constructor TSchemas.Create(AOwner: TDataPump);
- begin
- FOwner:= AOwner;
- FItems:= TList.Create;
- end;
- destructor TSchemas.Destroy;
- begin
- Clear;
- FItems.Free;
- inherited;
- end;
- function TSchemas.Add: TSchema;
- begin
- Result:= TSchema.Create(Self);
- FItems.Add(Result);
- end;
- procedure TSchemas.Clear;
- begin
- while Count > 0 do
- Delete(0);
- end;
- function TSchemas.Count: Integer;
- begin
- Result:= FItems.Count;
- end;
- procedure TSchemas.Delete(const Index: Integer);
- begin
- TSchema(FItems[Index]).Free;
- FItems.Delete(Index);
- end;
- function TSchemas.IndexOf(Source: TSchema): Integer;
- begin
- Result:= FItems.IndexOf(Source);
- end;
- function TSchemas.Owner: TDataPump;
- begin
- Result:= FOwner;
- end;
- { TDataPump }
- constructor TDataPump.Create(AOwner: TComponent);
- begin
- inherited;
- FConnections:= TConnections.Create(Self);
- FEntities:= TEntities.Create(Self);
- FSchemas:= TSchemas.Create(Self);
- FRecords:= TRecords.Create(Self);
- FWhereSQL:= TStringList.Create;
- end;
- destructor TDataPump.Destroy;
- begin
- FWhereSQL.Free;
- FRecords.Free;
- FSchemas.Free;
- FEntities.Free;
- FConnections.Free;
- RootDir:= ExtractFilePath(Application.ExeName);
- inherited;
- end;
- function TDataPump.CanConnect: Boolean;
- begin
- Result:=
- (FConnections.Count > 1) and
- (FDBSourceIndex >= 0) and
- (FDBDestIndex >= 0) and
- (FDBSourceIndex < FConnections.Count) and
- (FDBDestIndex < FConnections.Count) and
- (FDBSourceIndex <> FDBDestIndex);
- end;
- function TDataPump.Connected: Boolean;
- begin
- Result:= (CanConnect);
- if Result then
- Result:= (Source.Connected) and (Dest.Connected);
- end;
- procedure TDataPump.Connect;
- begin
- if not FActive then begin
- if CanConnect then begin
- FActive:= True;
- try
- Source.Connect;
- Dest.Connect;
- except
- on e: exception do begin
- Source.Disconnect;
- Dest.Disconnect;
- end;
- end;
- end else begin
- raise Exception.Create('Unable to connect with current configuration.');
- end;
- end;
- end;
- procedure TDataPump.Disconnect;
- begin
- if FActive then begin
- if CanConnect then begin
- FActive:= False;
- Source.Disconnect;
- Dest.Disconnect;
- end;
- end;
- end;
- function TDataPump.Entity: TEntity;
- begin
- Result:= FEntities[FEntityIndex];
- end;
- function TDataPump.GetRootDir: String;
- begin
- Result:= IncludeTrailingBackslash(FRootDir);
- end;
- function TDataPump.GetWhereSQL: TStrings;
- begin
- Result:= TStrings(FWhereSQL);
- end;
- procedure TDataPump.SetActive(const Value: Boolean);
- begin
- if Value then begin
- Connect;
- end else begin
- Disconnect;
- end;
- end;
- procedure TDataPump.SetConnections(const Value: TConnections);
- begin
- FConnections.Assign(Value);
- end;
- procedure TDataPump.SetDBDestIndex(const Value: Integer);
- begin
- FDBDestIndex := Value;
- end;
- procedure TDataPump.SetDBSourceIndex(const Value: Integer);
- begin
- FDBSourceIndex := Value;
- end;
- procedure TDataPump.SetEntities(const Value: TEntities);
- begin
- FEntities.Assign(Value);
- end;
- procedure TDataPump.SetEntityIndex(const Value: Integer);
- begin
- FEntityIndex := Value;
- end;
- procedure TDataPump.SetRootDir(const Value: String);
- begin
- FRootDir := IncludeTrailingBackslash(Value);
- end;
- procedure TDataPump.SetWhereSQL(const Value: TStrings);
- begin
- FWhereSQL.Assign(Value);
- end;
- function TDataPump.Source: TConnection;
- begin
- Result:= FConnections[FDBSourceIndex];
- end;
- function TDataPump.Dest: TConnection;
- begin
- Result:= FConnections[FDBDestIndex];
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment