1 |
(* |
2 |
* IBX For Lazarus (Firebird Express) |
3 |
* |
4 |
* The contents of this file are subject to the Initial Developer's |
5 |
* Public License Version 1.0 (the "License"); you may not use this |
6 |
* file except in compliance with the License. You may obtain a copy |
7 |
* of the License here: |
8 |
* |
9 |
* http://www.firebirdsql.org/index.php?op=doc&id=idpl |
10 |
* |
11 |
* Software distributed under the License is distributed on an "AS |
12 |
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
13 |
* implied. See the License for the specific language governing rights |
14 |
* and limitations under the License. |
15 |
* |
16 |
* The Initial Developer of the Original Code is Tony Whyman. |
17 |
* |
18 |
* The Original Code is (C) 2014 Tony Whyman, MWA Software |
19 |
* (http://www.mwasoftware.co.uk). |
20 |
* |
21 |
* All Rights Reserved. |
22 |
* |
23 |
* Contributor(s): ______________________________________. |
24 |
* |
25 |
*) |
26 |
unit IBXUpgradeDatabaseDlg; |
27 |
|
28 |
{$mode objfpc}{$H+} |
29 |
|
30 |
interface |
31 |
|
32 |
uses |
33 |
Classes, SysUtils, FileUtil, Forms, Controls, Dialogs, StdCtrls, |
34 |
ComCtrls, ExtCtrls, IBDatabase, ibxscript, IBHeader; |
35 |
|
36 |
type |
37 |
{ TUpgradeDatabaseDlg } |
38 |
|
39 |
TUpgradeDatabaseDlg = class(TForm) |
40 |
UpdateTransaction: TIBTransaction; |
41 |
IBXScript: TIBXScript; |
42 |
Label1: TLabel; |
43 |
Panel1: TPanel; |
44 |
ProgressBar1: TProgressBar; |
45 |
FDatabase: TIBDatabase; |
46 |
Status: TLabel; |
47 |
Timer1: TTimer; |
48 |
procedure FormShow(Sender: TObject); |
49 |
procedure HandleCompletionEvent(Sender: TObject); |
50 |
procedure IBXScriptLogProc(Sender: TObject; Msg: string); |
51 |
procedure IBXScriptProgressEvent(Sender: TObject; Reset: boolean; |
52 |
value: integer); |
53 |
private |
54 |
FOnDoUpgrade: TNotifyEvent; |
55 |
{ private declarations } |
56 |
FUpgradeLog: TStrings; |
57 |
procedure DoUpdate(Data: PtrInt); |
58 |
public |
59 |
{ public declarations } |
60 |
SuccessfulCompletion: boolean; |
61 |
constructor Create(theOwner: TComponent); override; |
62 |
destructor Destroy; override; |
63 |
procedure Add2Log(Msg: string); |
64 |
property OnDoUpgrade: TNotifyEvent read FOnDoUpgrade write FOnDoUpgrade; |
65 |
end; |
66 |
|
67 |
|
68 |
|
69 |
var |
70 |
UpgradeDatabaseDlg: TUpgradeDatabaseDlg; |
71 |
|
72 |
|
73 |
implementation |
74 |
|
75 |
{$R *.lfm} |
76 |
|
77 |
uses IBXViewLogDig; |
78 |
|
79 |
{ TUpgradeDatabaseDlg } |
80 |
|
81 |
procedure TUpgradeDatabaseDlg.FormShow(Sender: TObject); |
82 |
begin |
83 |
ProgressBar1.Position := 0; |
84 |
Status.Caption := ''; |
85 |
FUpgradeLog.Clear; |
86 |
Application.QueueAsyncCall(@DoUpdate,0); |
87 |
end; |
88 |
|
89 |
procedure TUpgradeDatabaseDlg.HandleCompletionEvent(Sender: TObject); |
90 |
begin |
91 |
Timer1.Enabled := false; |
92 |
if not SuccessfulCompletion then |
93 |
begin |
94 |
ShowViewLogDlg(FUpgradeLog); |
95 |
ModalResult := mrCancel |
96 |
end |
97 |
else |
98 |
ModalResult := mrOK; |
99 |
end; |
100 |
|
101 |
procedure TUpgradeDatabaseDlg.IBXScriptLogProc(Sender: TObject; Msg: string); |
102 |
begin |
103 |
Add2Log(Msg); |
104 |
end; |
105 |
|
106 |
procedure TUpgradeDatabaseDlg.IBXScriptProgressEvent(Sender: TObject; |
107 |
Reset: boolean; value: integer); |
108 |
begin |
109 |
if Reset then |
110 |
begin |
111 |
with ProgressBar1 do |
112 |
begin |
113 |
Position := 0; |
114 |
Max := value; |
115 |
end; |
116 |
end; |
117 |
ProgressBar1.StepIt; |
118 |
Application.ProcessMessages; |
119 |
end; |
120 |
|
121 |
procedure TUpgradeDatabaseDlg.Add2Log(Msg: string); |
122 |
begin |
123 |
FUpgradeLog.Add(Msg); |
124 |
end; |
125 |
|
126 |
procedure TUpgradeDatabaseDlg.DoUpdate(Data: PtrInt); |
127 |
|
128 |
begin |
129 |
SuccessfulCompletion := true; |
130 |
try |
131 |
if assigned(OnDoUpgrade) then |
132 |
OnDoUpgrade(self); |
133 |
except on E:Exception do |
134 |
begin |
135 |
SuccessfulCompletion := false; |
136 |
Add2Log(E.Message); |
137 |
end; |
138 |
end; |
139 |
Timer1.Enabled := true; |
140 |
end; |
141 |
|
142 |
|
143 |
constructor TUpgradeDatabaseDlg.Create(theOwner: TComponent); |
144 |
begin |
145 |
inherited Create(theOwner); |
146 |
FUpgradeLog := TStringList.Create; |
147 |
end; |
148 |
|
149 |
destructor TUpgradeDatabaseDlg.Destroy; |
150 |
begin |
151 |
if assigned(FUpgradeLog) then |
152 |
FUpgradeLog.Free; |
153 |
inherited Destroy; |
154 |
end; |
155 |
|
156 |
end. |
157 |
|