forked from motaz/turbobird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newconstraint.pas
103 lines (85 loc) · 2.54 KB
/
newconstraint.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
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
unit NewConstraint;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, CheckLst, QueryWindow;
type
{ TfmNewConstraint }
TfmNewConstraint = class(TForm)
bbScript: TBitBtn;
cbUpdateAction: TComboBox;
cbTables: TComboBox;
clxForFields: TCheckListBox;
clxOnFields: TCheckListBox;
edNewName: TEdit;
cbDeleteAction: TComboBox;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
laTable: TLabel;
procedure bbScriptClick(Sender: TObject);
procedure cbTablesChange(Sender: TObject);
private
{ private declarations }
public
DatabaseIndex: Integer;
QWindow: TfmQueryWindow;
{ public declarations }
end;
var
fmNewConstraint: TfmNewConstraint;
implementation
uses main;
{ TfmNewConstraint }
procedure TfmNewConstraint.cbTablesChange(Sender: TObject);
var
FieldsList: TStringList;
begin
// Get foreign table fields
FieldsList:= TStringList.Create;
try
fmMain.GetFields(DatabaseIndex, cbTables.Text, FieldsList);
clxForFields.Clear;
clxForFields.Items.AddStrings(FieldsList);
finally
FieldsList.Free;
end;
fmMain.SQLQuery1.Close;
end;
procedure TfmNewConstraint.bbScriptClick(Sender: TObject);
var
CurrFields, ForFields: string;
i: Integer;
begin
CurrFields:= '';
for i:= 0 to clxOnFields.Count - 1 do
if clxOnFields.Checked[i] then
CurrFields:= CurrFields + clxOnFields.Items[i] + ', ';
if CurrFields <> '' then
Delete(CurrFields, Length(CurrFields) - 1, 2);
ForFields:= '';
for i:= 0 to clxForFields.Count - 1 do
if clxForFields.Checked[i] then
ForFields:= ForFields + clxForFields.Items[i] + ', ';
if ForFields <> '' then
Delete(ForFields, Length(ForFields) - 1, 2);
QWindow:= fmMain.ShowQueryWindow(DatabaseIndex, 'new constraint on table : ' + laTable.Caption);
QWindow.meQuery.Lines.Text:= 'alter table ' + laTable.Caption + ' ADD CONSTRAINT ' + edNewName.Text;
QWindow.meQuery.Lines.Add(' foreign key (' + CurrFields + ') ');
QWindow.meQuery.Lines.Add(' references ' + cbTables.Text + ' (' + ForFields + ') ');
if cbUpdateAction.Text <> 'Restrict' then
QWindow.meQuery.Lines.Add(' on update ' + cbUpdateAction.Text + ' ');
if cbDeleteAction.Text <> 'Restrict' then
QWindow.meQuery.Lines.Add(' on delete ' + cbDeleteAction.Text + ' ');
fmMain.Show;
end;
initialization
{$I newconstraint.lrs}
end.