-
Notifications
You must be signed in to change notification settings - Fork 19
/
fbclone.database.pas
58 lines (47 loc) · 1.36 KB
/
fbclone.database.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
unit fbclone.database;
interface
uses
Windows, UIB, UIBLib;
type
TDatabase = record
LibraryFileName: string;
ConnectionString: string;
Username: string;
Password: string;
procedure Configure(var Database: TUIBDatabase);
end;
procedure MapEnvironment(var D: TDatabase);
implementation
{ TDatabase }
procedure TDatabase.Configure(var Database: TUIBDatabase);
begin
if Self.LibraryFileName <> '' then
Database.LibraryName := Self.LibraryFileName;
Database.DatabaseName := Self.ConnectionString;
Database.UserName := Self.Username;
Database.PassWord := Self.Password;
end;
procedure MapEnvironment(var D: TDatabase);
function ReadEnvironment(const Name: string): string;
var
BufSize: Integer; // buffer size required for value
begin
// Get required buffer size (inc. terminal #0)
BufSize := GetEnvironmentVariable(PChar(Name), nil, 0);
if BufSize > 0 then
begin
// Read env var value into result string
SetLength(Result, BufSize - 1);
GetEnvironmentVariable(PChar(Name), PChar(Result), BufSize);
end
else
// No such environment variable
Result := '';
end;
begin
if D.Username = '' then
D.Username := ReadEnvironment('ISC_USER');
if D.Password = '' then
D.Password := ReadEnvironment('ISC_PASSWORD');
end;
end.