-
Notifications
You must be signed in to change notification settings - Fork 0
/
pafDatabase.pas
76 lines (63 loc) · 4 KB
/
pafDatabase.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
unit pafDatabase;
interface
uses
IBX.IBDatabase,
IBX.ib,
gVariables;
function fCreateIBDatabase(var varIBDatabase: TIBDatabase; varDatabaseParams:RDatabaseParams):RResult;
implementation
uses
Vcl.Dialogs, System.SysUtils, vcl.forms;
//******************************************************************************
//èíèöèàëèçèðóåì TIBDatabase
//******************************************************************************
function fCreateIBDatabase(var varIBDatabase: TIBDatabase; varDatabaseParams:RDatabaseParams):RResult;
begin
try
if varIBDatabase <> nil then
varIBDatabase.Destroy; //åñëè îáúåêò óæå åñòü òî ñàìîóíè÷òîæåíèå
varIBDatabase := TIBDatabase.Create(application); //âûäåëÿåì ïàìÿòü
varIBDatabase.LoginPrompt := false; //óêàçûâàåì ÷òî íå áóäåì çàïðàøèâàòü ïàðîëü ïðè ïîäêëþ÷åíèè
varIBDatabase.SQLDialect := 3;
varIBDatabase.Params.Clear;
varIBDatabase.Params.Add('LC_CTYPE=WIN1251');
varIBDatabase.Params.Add('USER_NAME=' + varDatabaseParams.Login);
varIBDatabase.Params.Add('PASSWORD=' + varDatabaseParams.Password);
varIBDatabase.DatabaseName := varDatabaseParams.IP + ':' + varDatabaseParams.Path;
if varDatabaseParams.create then varIBDatabase.CreateDatabase; //ñîçäàåì ÁÄ
varIBDatabase.Connected := true; //ïîäêëþ÷åíèå ê ÁÄ
result.status:=true; //åñëè âñå âûïîëíèëîñü õîðîøî , òî âîçâðàùàåì ðåçóëüòàò
except //åñëè âî âðåìÿ ñîçäàíèÿ îáúåêòà ïðîèçîøëà îøèáêà
on e:EIBError do
ShowMessage( inttostr(e.IBErrorCode ));
{e.Message + ' ' + e.ClassName}
//inttostr(e.IBErrorCode)
{ begin
result.status := false; //óêàçûâàåì ÷òî ïðîèçîøëà îøèáêà âî âðåìÿ ñîçäàèíÿ îáúÿêòà
result.errMessage := e.Message; //ñèñòåìíîå ñîîáùåíèå îá îøèáêå
result.errClass := e.ClassName; //ñèñòåìíûé êëàññ îøèáêè
if pos('Error while trying to create file', e.Message)<> 0 then //åñëè ÁÄ íå ñîçäàåòñÿ
begin
result.varMessage := '(pafDatabase#fCreateIBDatabase)' + #10#13 + 'IBDatabase can not create Database ';
result.varClassErr := 'CreateDatabaseErr'; //óêàçûâàåì ÷òî îøèáêà ïðè ïîïûòêå ñîçàäíèè ÁÄ
result.varButton := [tcbCancel] ; //óêàçûâàåì êàêèå êíîïêè ìû áóäåì ïîêàçûâàòü
result.varTaskIcon := tdiError; //óêàçûâàåì òèï èêîíêè
end;
if pos('Your user name and password are not defined', e.Message)<> 0 then //åñëè íå âåðíûé ëîãèí èëè ïàðîëü
begin
result.varMessage := '(pafDatabase#fCreateIBDatabase)' + #10#13 + 'IBDatabase incorrect login or password ';
result.varClassErr := 'LoginPasswordErr'; //óêàçûâàåì ÷òî îøèáêà ëîãèíà èëè ïàðîëÿ
result.varButton := [tcbCancel] ; //óêàçûâàåì êàêèå êíîïêè ìû áóäåì ïîêàçûâàòü
result.varTaskIcon := tdiError; //óêàçûâàåì òèï èêîíêè
end;
if pos('Error while trying to open file', e.Message)<> 0 then //åñëè áàçû íåòó
begin
result.varMessage := '(pafDatabase#fCreateIBDatabase)' + #10#13 + 'IBDatabase can not connect because database not exist' + #10#13 + 'Create a database?';
result.varClassErr := 'OpenDatabaseErr'; //óêàçûâàåì ÷òî áàçû íåò
result.varButton := [tcbYes, tcbCancel] ; //óêàçûâàåì êàêèå êíîïêè ìû áóäåì ïîêàçûâàòü
result.varTaskIcon := tdiError; //óêàçûâàåì òèï èêîíêè
end;
end; }
end;
end;
end.