This repository was archived by the owner on Aug 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfscreatedb.pas
More file actions
155 lines (129 loc) · 3.92 KB
/
fscreatedb.pas
File metadata and controls
155 lines (129 loc) · 3.92 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
(*
fenixsql
author Alessandro Batisti
http://code.google.com/p/fenixsql
http://web.tiscali.it/fblib
File: fscreatedb.pas
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*)
unit fscreatedb;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Forms, Dialogs, StdCtrls,
EditBtn, ExtCtrls, Buttons, FBLExcept;
type
{ TCreateDbForm }
TCreateDbForm = class(TForm)
CreateDbButton: TBitBtn;
CancelButton: TBitBtn;
PageSizeCombo: TComboBox;
DialectCombo: TComboBox;
CharsetCombo: TComboBox;
FileNameEdit: TEditButton;
UserEdit: TEdit;
passwordEdit: TEdit;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
userLabel: TLabel;
passwordLabel: TLabel;
Label3: TLabel;
LSql: TLabel;
Label5: TLabel;
Panel1: TPanel;
sdDb: TSaveDialog;
procedure CreateDbButtonClick(Sender: TObject);
procedure FileNameEditButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
function CheckFileName(const AFileName: string): boolean;
public
{ public declarations }
end;
implementation
{$R *.lfm}
uses
fsdm, fsconfig;
{ TCreateDbForm }
function TCreateDbForm.CheckFileName(const AFileName: string): boolean;
var
Test: string;
begin
Result := False;
if AFileName = '' then
begin
ShowMessage('"DB File Name" cannot be blank');
Exit;
end;
if Length(AFileName) < 5 then
begin
ShowMessage('File Name not valid');
Exit;
end;
Test := UpperCase(ExtractFileExt(AFileName));
if (Test <> '.GDB') and (Test <> '.FDB') then
begin
ShowMessage('File Name not valid');
Exit;
end;
if FileExists(AFileName) then
begin
ShowMessage(AFileName + ' already exists');
Exit;
end;
Result := True;
end;
//------------------------------------------------------------------------------
procedure TCreateDbForm.FormCreate(Sender: TObject);
begin
DialectCombo.ItemIndex := 0; // dialect 3
PageSizeCombo.ItemIndex := 2; // page size 4096
CharsetCombo.ItemIndex := 0;
end;
//------------------------------------------------------------------------------
procedure TCreateDbForm.CreateDbButtonClick(Sender: TObject);
var
FileName: string;
begin
FileName := Trim(FileNameEdit.Text);
try
if CheckFileName(FileName) then
begin
if CharsetCombo.Text = 'NONE' then
MainDataModule.MainDb.CreateDatabase(FileName, UserEdit.Text, passwordEdit.Text,
StrToInt(DialectCombo.Text), StrToInt(PageSizeCombo.Text))
else
MainDataModule.MainDb.CreateDatabase(FileName, UserEdit.Text, passwordEdit.Text,
StrToInt(DialectCombo.Text), StrToInt(PageSizeCombo.Text), CharsetCombo.Text);
ShowMessage('Database' + LineEnding + FileNameEdit.Text + LineEnding + 'Created');
end;
except
on E: EFBLError do
ShowMessage(Format('Error Code : %d', [E.ISC_ErrorCode]) +
LineEnding + Format('SQL Code : %d', [E.SqlCode]) +
LineEnding + E.Message);
end;
end;
//------------------------------------------------------------------------------
procedure TCreateDbForm.FileNameEditButtonClick(Sender: TObject);
begin
with sdDb do
begin
Title := 'Create database file';
DefaultExt := FileExtentionForDialog;
Filter := FileFilterForDialog;
if Execute then
FileNameEdit.Text := FileName;
end;
end;
end.