ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/design/ibdeletesqleditor.pas
(Generate patch)

Comparing ibx/trunk/design/ibdeletesqleditor.pas (file contents):
Revision 5 by tony, Fri Feb 18 16:26:16 2011 UTC vs.
Revision 21 by tony, Thu Feb 26 10:33:34 2015 UTC

# Line 1 | Line 1
1 < unit ibdeletesqleditor;
2 <
3 < {$mode objfpc}{$H+}
4 <
5 < interface
6 <
7 < uses
8 <  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
9 <  StdCtrls, IBSystemTables, IBDatabase;
10 <
11 < type
12 <
13 <  { TIBDeleteSQLEditorForm }
14 <
15 <  TIBDeleteSQLEditorForm = class(TForm)
16 <    Button1: TButton;
17 <    Button2: TButton;
18 <    Button3: TButton;
19 <    Button4: TButton;
20 <    Label1: TLabel;
21 <    Label3: TLabel;
22 <    Label4: TLabel;
23 <    PrimaryKeyList: TListBox;
24 <    QuoteFields: TCheckBox;
25 <    SQLText: TMemo;
26 <    TableNamesCombo: TComboBox;
27 <    procedure Button3Click(Sender: TObject);
28 <    procedure Button4Click(Sender: TObject);
29 <    procedure FormShow(Sender: TObject);
30 <    procedure PrimaryKeyListDblClick(Sender: TObject);
31 <    procedure TableNamesComboCloseUp(Sender: TObject);
32 <  private
33 <    { private declarations }
34 <    FIBSystemTables: TIBSystemTables;
35 <  public
36 <    { public declarations }
37 <    constructor Create(TheOwner: TComponent); override;
38 <    destructor Destroy; override;
39 <    procedure SetDatabase(Database: TIBDatabase; Transaction: TIBTransaction);
40 <  end;
41 <
42 < var
43 <  IBDeleteSQLEditorForm: TIBDeleteSQLEditorForm;
44 <
45 < function EditSQL(Database: TIBDatabase; Transaction: TIBTransaction; SelectSQL: TStrings): boolean;
46 <
47 < implementation
48 <
49 < function EditSQL(Database: TIBDatabase; Transaction: TIBTransaction; SelectSQL: TStrings): boolean;
50 < begin
51 <  Result := false;
52 <  if assigned(Database) then
53 <  begin
54 <    if not assigned(Transaction) then
55 <    begin
56 <      if not assigned(Database.DefaultTransaction)then
57 <      begin
58 <        ShowMessage('No Default Transaction!');
59 <        Exit
60 <      end;
61 <      Transaction := Database.DefaultTransaction
62 <    end;
63 <
64 <    Database.Connected := true;
65 <  end;
66 <
67 <  with TIBDeleteSQLEditorForm.Create(Application) do
68 <  try
69 <    SetDatabase(Database,Transaction);
70 <    SQLText.Lines.Assign(SelectSQL);
71 <    Result := ShowModal = mrOK;
72 <    if Result then
73 <     SelectSQL.Assign(SQLText.Lines)
74 <  finally
75 <    Free
76 <  end;
77 < end;
78 <
79 < { TIBDeleteSQLEditorForm }
80 <
81 < procedure TIBDeleteSQLEditorForm.FormShow(Sender: TObject);
82 < begin
83 <  TableNamesCombo.Items.Clear;
84 <  FIBSystemTables.GetTableNames(TableNamesCombo.Items);
85 <  if TableNamesCombo.Items.Count > 0 then
86 <  begin
87 <    TableNamesCombo.ItemIndex := 0;
88 <    FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
89 <  end;
90 < end;
91 <
92 < procedure TIBDeleteSQLEditorForm.PrimaryKeyListDblClick(Sender: TObject);
93 < begin
94 <  SQLText.SelText := PrimaryKeyList.Items[PrimaryKeyList.ItemIndex];
95 <  SQLText.SetFocus
96 < end;
97 <
98 < procedure TIBDeleteSQLEditorForm.Button3Click(Sender: TObject);
99 < begin
100 <  FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,SQLText.Lines)
101 < end;
102 <
103 < procedure TIBDeleteSQLEditorForm.Button4Click(Sender: TObject);
104 < begin
105 <  FIBSystemTables.TestSQL(SQLText.Lines.Text)
106 < end;
107 <
108 < procedure TIBDeleteSQLEditorForm.TableNamesComboCloseUp(Sender: TObject);
109 < begin
110 <  FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
111 < end;
112 <
113 < constructor TIBDeleteSQLEditorForm.Create(TheOwner: TComponent);
114 < begin
115 <  inherited Create(TheOwner);
116 <  FIBSystemTables := TIBSystemTables.Create;
117 < end;
118 <
119 < destructor TIBDeleteSQLEditorForm.Destroy;
120 < begin
121 <  if assigned(FIBSystemTables) then FIBSystemTables.Free;
122 <  inherited Destroy;
123 < end;
124 <
125 < procedure TIBDeleteSQLEditorForm.SetDatabase(Database: TIBDatabase; Transaction: TIBTransaction);
126 < begin
127 <  FIBSystemTables.SelectDatabase(Database,Transaction)
128 < end;
129 <
130 < initialization
131 <  {$I ibdeletesqleditor.lrs}
132 <
133 < end.
134 <
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) 2011 Tony Whyman, MWA Software
19 > *  (http://www.mwasoftware.co.uk).
20 > *
21 > *  All Rights Reserved.
22 > *
23 > *  Contributor(s): ______________________________________.
24 > *
25 > *)
26 >
27 > unit ibdeletesqleditor;
28 >
29 > {$mode objfpc}{$H+}
30 >
31 > interface
32 >
33 > uses
34 >  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
35 >  StdCtrls, ComCtrls, IBSystemTables, IBDatabase, IBCustomDataSet;
36 >
37 > type
38 >
39 >  { TIBDeleteSQLEditorForm }
40 >
41 >  TIBDeleteSQLEditorForm = class(TForm)
42 >    Button1: TButton;
43 >    Button2: TButton;
44 >    ExecuteOnlyIndicator: TLabel;
45 >    GenerateBtn: TButton;
46 >    GenerateParams: TCheckBox;
47 >    Label1: TLabel;
48 >    Label16: TLabel;
49 >    Label17: TLabel;
50 >    Label18: TLabel;
51 >    Label4: TLabel;
52 >    PageControl: TPageControl;
53 >    PrimaryKeyList: TListBox;
54 >    ProcedureNames: TComboBox;
55 >    ProcInputList: TListBox;
56 >    ProcOutputList: TListBox;
57 >    TableNamesCombo: TComboBox;
58 >    DeletePage: TTabSheet;
59 >    ExecutePage: TTabSheet;
60 >    TestBtn: TButton;
61 >    IBTransaction1: TIBTransaction;
62 >    Label3: TLabel;
63 >    QuoteFields: TCheckBox;
64 >    SQLText: TMemo;
65 >    procedure DeletePageShow(Sender: TObject);
66 >    procedure ExecutePageShow(Sender: TObject);
67 >    procedure GenerateBtnClick(Sender: TObject);
68 >    procedure ProcedureNamesCloseUp(Sender: TObject);
69 >    procedure TestBtnClick(Sender: TObject);
70 >    procedure FormShow(Sender: TObject);
71 >    procedure PrimaryKeyListDblClick(Sender: TObject);
72 >    procedure TableNamesComboCloseUp(Sender: TObject);
73 >  private
74 >    { private declarations }
75 >    FIBSystemTables: TIBSystemTables;
76 >  public
77 >    { public declarations }
78 >    constructor Create(TheOwner: TComponent); override;
79 >    destructor Destroy; override;
80 >    procedure SetDatabase(Database: TIBDatabase);
81 >  end;
82 >
83 > var
84 >  IBDeleteSQLEditorForm: TIBDeleteSQLEditorForm;
85 >
86 > function EditSQL(DataSet: TIBCustomDataSet; SelectSQL: TStrings): boolean;
87 >
88 > implementation
89 >
90 > uses IBSQL;
91 >
92 > {$R *.lfm}
93 >
94 > function EditSQL(DataSet: TIBCustomDataSet; SelectSQL: TStrings): boolean;
95 > begin
96 >  Result := false;
97 >  if assigned(DataSet) and assigned(DataSet.Database) then
98 >    try
99 >      DataSet.Database.Connected := true;
100 >    except on E: Exception do
101 >      ShowMessage(E.Message)
102 >    end;
103 >
104 >  with TIBDeleteSQLEditorForm.Create(Application) do
105 >  try
106 >    if assigned(DataSet) then
107 >    begin
108 >        SetDatabase(DataSet.Database);
109 >        GenerateParams.Checked := DataSet.GenerateParamNames;
110 >    end;
111 >    SQLText.Lines.Assign(SelectSQL);
112 >    Result := ShowModal = mrOK;
113 >    if Result then
114 >    begin
115 >     SelectSQL.Assign(SQLText.Lines);
116 >     if assigned(DataSet) then
117 >          DataSet.GenerateParamNames := GenerateParams.Checked
118 >    end;
119 >  finally
120 >    Free
121 >  end;
122 > end;
123 >
124 > { TIBDeleteSQLEditorForm }
125 >
126 > procedure TIBDeleteSQLEditorForm.FormShow(Sender: TObject);
127 > var IsProcedureName: boolean;
128 >    SQLType: TIBSQLTypes;
129 > begin
130 >  GenerateBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
131 >  TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
132 >  if Trim(SQLText.Text) <> '' then
133 >  begin
134 >    try
135 >      SQLType := FIBSystemTables.GetStatementType(SQLText.Text,IsProcedureName);
136 >    except  end;
137 >    if SQLType = SQLExecProcedure then
138 >      PageControl.ActivePage := ExecutePage
139 >    else
140 >      PageControl.ActivePage := DeletePage;
141 >  end
142 >  else
143 >    PageControl.ActivePage := DeletePage;
144 > end;
145 >
146 > procedure TIBDeleteSQLEditorForm.PrimaryKeyListDblClick(Sender: TObject);
147 > begin
148 >  SQLText.SelText := PrimaryKeyList.Items[PrimaryKeyList.ItemIndex];
149 >  SQLText.SetFocus
150 > end;
151 >
152 > procedure TIBDeleteSQLEditorForm.GenerateBtnClick(Sender: TObject);
153 > begin
154 >  if PageControl.ActivePage = ExecutePage then
155 >    FIBSystemTables.GenerateExecuteSQL(ProcedureNames.Text,QuoteFields.Checked,true,
156 >          ProcInputList.Items,ProcOutputList.Items,SQLText.Lines)
157 >  else
158 >    FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,SQLText.Lines)
159 > end;
160 >
161 > procedure TIBDeleteSQLEditorForm.ProcedureNamesCloseUp(Sender: TObject);
162 > var ExecuteOnly: boolean;
163 > begin
164 >  FIBSystemTables.GetProcParams(ProcedureNames.Text,ExecuteOnly,ProcInputList.Items,ProcOutputList.Items);
165 >  ExecuteOnlyIndicator.Visible := ExecuteOnly;
166 > end;
167 >
168 > procedure TIBDeleteSQLEditorForm.DeletePageShow(Sender: TObject);
169 > var TableName: string;
170 > begin
171 >  TableNamesCombo.Items.Clear;
172 >  try
173 >  FIBSystemTables.GetTableNames(TableNamesCombo.Items);
174 >  if TableNamesCombo.Items.Count > 0 then
175 >  begin
176 >    TableNamesCombo.ItemIndex := 0;
177 >    if Trim(SQLText.Text) <> '' then
178 >    begin
179 >      FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
180 >      TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName)
181 >    end;
182 >    FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
183 >  end;
184 >  except {ignore} end;
185 > end;
186 >
187 > procedure TIBDeleteSQLEditorForm.ExecutePageShow(Sender: TObject);
188 > var ProcName: string;
189 >    IsProcedureName: boolean;
190 > begin
191 >  FIBSystemTables.GetProcedureNames(ProcedureNames.Items,false);
192 >  if ProcedureNames.Items.Count > 0 then
193 >  begin
194 >    if (FIBSystemTables.GetStatementType(SQLText.Text,IsProcedureName) = SQLExecProcedure) or IsProcedureName then
195 >    begin
196 >      FIBSystemTables.GetTableAndColumns(SQLText.Text,ProcName,nil);
197 >      ProcedureNames.ItemIndex := ProcedureNames.Items.IndexOf(ProcName)
198 >    end
199 >    else
200 >      ProcedureNames.ItemIndex := 0;
201 >  end;
202 >  ProcedureNamesCloseUp(nil);
203 > end;
204 >
205 > procedure TIBDeleteSQLEditorForm.TestBtnClick(Sender: TObject);
206 > begin
207 >  FIBSystemTables.TestSQL(SQLText.Lines.Text,GenerateParams.Checked)
208 > end;
209 >
210 > procedure TIBDeleteSQLEditorForm.TableNamesComboCloseUp(Sender: TObject);
211 > begin
212 >  FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
213 > end;
214 >
215 > constructor TIBDeleteSQLEditorForm.Create(TheOwner: TComponent);
216 > begin
217 >  inherited Create(TheOwner);
218 >  FIBSystemTables := TIBSystemTables.Create;
219 > end;
220 >
221 > destructor TIBDeleteSQLEditorForm.Destroy;
222 > begin
223 >  if assigned(FIBSystemTables) then FIBSystemTables.Free;
224 >  inherited Destroy;
225 > end;
226 >
227 > procedure TIBDeleteSQLEditorForm.SetDatabase(Database: TIBDatabase);
228 > begin
229 >  IBTransaction1.DefaultDatabase := Database;
230 >  FIBSystemTables.SelectDatabase(Database,IBTransaction1)
231 > end;
232 >
233 > end.
234 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines