ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/iblocaldb/gui/IBLocalDBSupport.pas
Revision: 272
Committed: Mon Feb 4 13:34:37 2019 UTC (5 years, 2 months ago) by tony
Content type: text/x-pascal
File size: 5248 byte(s)
Log Message:
Fixes merged

File Contents

# Content
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 IBLocalDBSupport;
27
28 {$mode objfpc}{$H+}
29
30 interface
31
32 uses
33 Classes, SysUtils, LResources, Forms, Controls, Dialogs, IBXCustomIBLocalDBSupport,
34 IBXServices;
35
36 type
37
38 { TIBLocalDBSupport }
39
40 TIBLocalDBSupport = class(TCustomIBLocalDBSupport)
41 private
42 procedure DoDowngrade(Data: PtrInt);
43 procedure HandleGetDBVersionNo(Sender: TObject; var VersionNo: integer);
44 procedure HandleUpgradeStepCompleted(Sender: TObject);
45 protected
46 function AllowInitialisation: boolean; override;
47 function AllowRestore: boolean; override;
48 function InternalCreateNewDatabase(DBArchive: string): boolean; override;
49 procedure Downgrade(DBArchive: string); override;
50 function RestoreDatabaseFromArchive(aFilename: string): boolean; override;
51 function RunUpgradeDatabase(TargetVersionNo: integer): boolean; override;
52 function SaveDatabaseToArchive(aFilename: string): boolean; override;
53 published
54 property Database;
55 property DatabaseName;
56 property Enabled;
57 property EmptyDBArchive;
58 property FirebirdDirectory;
59 property Options;
60 property RequiredVersionNo;
61 property UpgradeConfFile;
62 property VendorName;
63 property OnGetDatabaseName;
64 property OnGetDBVersionNo;
65 property OnNewDatabaseOpen;
66 property OnGetSharedDataDir;
67 end;
68
69
70 implementation
71
72 uses IBXUpgradeDatabaseDlg, IBXCreateDatabaseDlg, IBXSaveDatabaseDlg,
73 Registry, IBXCreateDatabaseFromSQLDlgUnit;
74
75 resourcestring
76 sDowngradePrompt = 'Database Version %d found but Version %d expected. If you have '+
77 'reinstalled this application after a failed upgrade then '+
78 'it may be possible to restore a saved archive of the database '+
79 'taken immediately before the upgrade. Do you want to do this?';
80
81 sReplaceBackup = 'This action will replace the current database with the backup. '+
82 'All data in the current database will be lost!';
83 sReplaceInitial = 'This action will replace the current database with an initial database. '+
84 'All data in the current database will be lost!';
85
86 { TIBLocalDBSupport }
87
88 procedure TIBLocalDBSupport.DoDowngrade(Data: PtrInt);
89 begin
90 if AppDestroying in Application.Flags then Exit;
91 RestoreDatabase(DownGradeArchive);
92 DowngradeDone;
93 end;
94
95 procedure TIBLocalDBSupport.HandleGetDBVersionNo(Sender: TObject;
96 var VersionNo: integer);
97 begin
98 VersionNo := CurrentDBVersionNo;
99 end;
100
101 procedure TIBLocalDBSupport.HandleUpgradeStepCompleted(Sender: TObject);
102 begin
103 UpdateVersionNo;
104 end;
105
106 function TIBLocalDBSupport.AllowInitialisation: boolean;
107 begin
108 Result := (iblQuiet in Options) or
109 (MessageDlg(sReplaceInitial, mtWarning,[mbOK,mbCancel],0) = mrOK);
110 end;
111
112 function TIBLocalDBSupport.AllowRestore: boolean;
113 begin
114 Result := (iblQuiet in Options) or
115 (MessageDlg(sReplaceBackup,mtWarning,[mbOK,mbCancel],0) = mrOK);
116 end;
117
118 function TIBLocalDBSupport.InternalCreateNewDatabase(DBArchive: string
119 ): boolean;
120 begin
121 if IsGBakFile(DBArchive) then
122 begin
123 Database.Attachment.Disconnect;
124 try
125 Result := IBXCreateDatabaseDlg.RestoreDatabaseFromArchive(RestoreService,DBArchive)
126 finally
127 Database.Attachment.Connect;
128 end;
129 end
130 else
131 Result := IBXCreateDatabaseFromSQLDlgUnit.CreateNewDatabase(Database,DBArchive)
132 end;
133
134 procedure TIBLocalDBSupport.Downgrade(DBArchive: string);
135 begin
136 if (iblQuiet in Options) or
137 (MessageDlg(Format(sDowngradePrompt, [CurrentDBVersionNo,RequiredVersionNo]),
138 mtWarning,[mbYes,mbNo],0) = mrYes) then
139 begin
140 inherited Downgrade(DBArchive);
141 Application.QueueAsyncCall(@DoDowngrade,0);
142 end;
143 end;
144
145 function TIBLocalDBSupport.RestoreDatabaseFromArchive(aFilename: string
146 ): boolean;
147 begin
148 Result := IBXCreateDatabaseDlg.RestoreDatabaseFromArchive(RestoreService,aFileName);
149 end;
150
151 function TIBLocalDBSupport.RunUpgradeDatabase(TargetVersionNo: integer
152 ): boolean;
153 begin
154 Result := IBXUpgradeDatabaseDlg.RunUpgradeDatabase(Database,BackupService,UpgradeConf,
155 ChangeFileExt(ActiveDatabasePathName,''),
156 TargetVersionNo,@HandleGetDBVersionNo, @HandleUpgradeStepCompleted);
157 end;
158
159 function TIBLocalDBSupport.SaveDatabaseToArchive(aFilename: string): boolean;
160 begin
161 Result := IBXSaveDatabaseDlg.SaveDatabaseToArchive(BackupService,aFileName);
162 end;
163
164 end.
165