ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/iblocaldb/gui/IBLocalDBSupport.pas
Revision: 345
Committed: Mon Aug 23 14:22:29 2021 UTC (2 years, 8 months ago) by tony
Content type: text/x-pascal
File size: 5338 byte(s)
Log Message:
Merged into public release

File Contents

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