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

Comparing:
ibx/trunk/design/ibsqleditor.pas (file contents), Revision 7 by tony, Sun Aug 5 18:28:19 2012 UTC vs.
ibx/branches/journaling/design/ibsqleditor.pas (file contents), Revision 362 by tony, Tue Dec 7 13:27:39 2021 UTC

# Line 23 | Line 23
23   *  Contributor(s): ______________________________________.
24   *
25   *)
26 < unit IBSQLEditor;
26 >
27 > unit ibsqleditor;
28  
29   {$mode objfpc}{$H+}
30  
31   interface
32  
33   uses
34 <  Classes, SysUtils, FileUtil,  Forms, Controls, Graphics, Dialogs,
35 <  StdCtrls, ExtCtrls, ComCtrls, IBSystemTables, IBSQL, IBDatabase;
34 >  Classes, SysUtils, FileUtil, SynEdit, LResources, Forms, Controls, Graphics,
35 >  Dialogs, StdCtrls, ComCtrls, ibinsertsqleditor, IBSQLEditFrame,
36 >  IBDatabase, IBSQL, IB, db;
37  
38   type
39  
40    { TIBSQLEditorForm }
41  
42 <  TIBSQLEditorForm = class(TForm)
41 <    Button1: TButton;
42 <    Button2: TButton;
43 <    GenerateBtn: TButton;
44 <    IBTransaction1: TIBTransaction;
45 <    Label5: TLabel;
46 <    SelectProcedure: TLabel;
47 <    TestBtn: TButton;
42 >  TIBSQLEditorForm = class(TIBInsertSQLEditorForm)
43      IncludePrimaryKeys: TCheckBox;
44 <    Label1: TLabel;
45 <    Label10: TLabel;
51 <    Label11: TLabel;
52 <    Label12: TLabel;
53 <    Label14: TLabel;
54 <    Label15: TLabel;
55 <    Label16: TLabel;
56 <    Label17: TLabel;
57 <    Label18: TLabel;
58 <    Label2: TLabel;
59 <    Label3: TLabel;
60 <    Label4: TLabel;
61 <    Label8: TLabel;
62 <    Label9: TLabel;
63 <    SelectFieldsList: TListBox;
64 <    ProcOutputList: TListBox;
65 <    SelectPrimaryKeys: TListBox;
66 <    InsertFieldsList: TListBox;
67 <    ModifyFieldsList: TListBox;
68 <    ModifyPrimaryKeys: TListBox;
69 <    DeletePrimaryKeys: TListBox;
70 <    ProcInputList: TListBox;
71 <    PageControl: TPageControl;
72 <    QuoteFields: TCheckBox;
73 <    SQLText: TMemo;
74 <    SelectPage: TTabSheet;
75 <    InsertPage: TTabSheet;
76 <    ModifyPage: TTabSheet;
77 <    DeletePage: TTabSheet;
78 <    ExecutePage: TTabSheet;
79 <    SelectTableNames: TComboBox;
80 <    InsertTableNames: TComboBox;
81 <    ModifyTableNames: TComboBox;
82 <    DeleteTableNames: TComboBox;
83 <    ProcedureNames: TComboBox;
84 <    procedure GenerateBtnClick(Sender: TObject);
85 <    procedure TestBtnClick(Sender: TObject);
86 <    procedure DeletePageShow(Sender: TObject);
87 <    procedure DeleteTableNamesCloseUp(Sender: TObject);
88 <    procedure ExecutePageShow(Sender: TObject);
44 >    SelectProcedure: TLabel;
45 >    TabControl1: TTabControl;
46      procedure FormShow(Sender: TObject);
47 <    procedure IncludePrimaryKeysClick(Sender: TObject);
48 <    procedure InsertPageShow(Sender: TObject);
49 <    procedure Label13Click(Sender: TObject);
93 <    procedure ModifyPageShow(Sender: TObject);
94 <    procedure ModifyTableNamesCloseUp(Sender: TObject);
95 <    procedure ProcedureNamesCloseUp(Sender: TObject);
96 <    procedure SelectFieldsListDblClick(Sender: TObject);
97 <    procedure SelectPageShow(Sender: TObject);
98 <    procedure SelectTableNamesCloseUp(Sender: TObject);
99 <    procedure InsertTableNamesCloseUp(Sender: TObject);
47 >    procedure GenerateBtnClick(Sender: TObject);
48 >    procedure TabControl1Change(Sender: TObject);
49 >    procedure UserProceduresAfterScroll(DataSet: TDataSet);
50    private
51 <    { private declarations }
52 <    FTableName: string;
53 <    FIBSystemTables: TIBSystemTables;
104 <    FExecuteOnly: boolean;
51 >    procedure SetupFlags;
52 >  protected
53 >    procedure SetSQLStatementType(aType: TIBSQLStatementTypes); override;
54    public
55 <    { public declarations }
107 <    constructor Create(TheOwner: TComponent); override;
108 <    destructor Destroy; override;
109 <    procedure SetDatabase(Database: TIBDatabase);
55 >
56    end;
57  
58 + function EditSQL(aIBSQL: TIBSQL): boolean;
59 +
60   var
61    IBSQLEditorForm: TIBSQLEditorForm;
62  
115 function EditIBSQL(DataSet: TIBSQL): boolean;
116
63   implementation
64  
65   {$R *.lfm}
66  
67 < uses InterfaceBase;
122 <
123 < function EditIBSQL(DataSet: TIBSQL): boolean;
67 > function EditSQL(aIBSQL: TIBSQL): boolean;
68   begin
69    Result := false;
70 <  if assigned(DataSet.Database)  then
70 >  if assigned(aIBSQL) and assigned(aIBSQL.Database) then
71      try
72 <      DataSet.Database.Connected := true;
72 >      aIBSQL.Database.Connected := true;
73      except on E: Exception do
74        ShowMessage(E.Message)
75      end;
76  
77    with TIBSQLEditorForm.Create(Application) do
78    try
79 <    SetDatabase(DataSet.Database);
80 <    SQLText.Lines.Assign(DataSet.SQL);
79 >    if assigned(aIBSQL) then
80 >    begin
81 >        IBSQLEditFrame1.Database := aIBSQL.Database;
82 >        GenerateParams.Checked := aIBSQL.GenerateParamNames;
83 >    end;
84 >    with IBSQLEditFrame1 do
85 >    begin
86 >      IncludeReadOnlyFields := false;
87 >      ExecuteOnlyProcs := true;
88 >      SelectProcs := true;
89 >      SQLText.Lines.Assign(aIBSQL.SQL);
90 >    end;
91 >    IncludePrimaryKeys.Checked := false;
92      Result := ShowModal = mrOK;
93      if Result then
94 <      DataSet.SQL.Assign(SQLText.Lines)
94 >    begin
95 >     aIBSQL.SQL.Assign(IBSQLEditFrame1.SQLText.Lines);
96 >     if assigned(aIBSQL) then
97 >          aIBSQL.GenerateParamNames := GenerateParams.Checked
98 >    end;
99    finally
100      Free
101    end;
143
102   end;
103  
104   { TIBSQLEditorForm }
105  
106 < procedure TIBSQLEditorForm.FormShow(Sender: TObject);
149 < var IsProcedureName: boolean;
150 < begin
151 <  if WidgetSet.LCLPlatform = lpGtk2 then
152 <    PageControl.TabPosition := tpLeft
153 <  else
154 <  PageControl.TabPosition := tpTop;
155 <  GenerateBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
156 <  TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
157 <  if Trim(SQLText.Text) <> '' then
158 <  begin
159 <    case FIBSystemTables.GetStatementType(SQLText.Text,IsProcedureName) of
160 <    SQLSelect:
161 <      if IsProcedureName then
162 <        PageControl.ActivePage := ExecutePage
163 <      else
164 <        PageControl.ActivePage := SelectPage;
165 <    SQLInsert:  PageControl.ActivePage := InsertPage;
166 <    SQLUpdate:  PageControl.ActivePage := ModifyPage;
167 <    SQLDelete:  PageControl.ActivePage := DeletePage;
168 <    SQLExecProcedure: PageControl.ActivePage := ExecutePage;
169 <    else
170 <      PageControl.ActivePage := SelectPage;
171 <    end;
172 <    FIBSystemTables.GetTableAndColumns(SQLText.Text,FTableName,nil)
173 <  end;
174 < end;
175 <
176 < procedure TIBSQLEditorForm.IncludePrimaryKeysClick(Sender: TObject);
177 < begin
178 <  FIBSystemTables.GetFieldNames(ModifyTableNames.Text,ModifyFieldsList.Items,IncludePrimaryKeys.checked);
179 <  FIBSystemTables.GetPrimaryKeys(ModifyTableNames.Text,ModifyPrimaryKeys.Items);
180 < end;
181 <
182 < procedure TIBSQLEditorForm.DeletePageShow(Sender: TObject);
183 < var TableName: string;
106 > procedure TIBSQLEditorForm.TabControl1Change(Sender: TObject);
107   begin
108 <  FIBSystemTables.GetTableNames(DeleteTableNames.Items);
109 <  if Trim(SQLText.Text) = '' then
110 <  begin
188 <    if FTableName <> '' then
189 <      DeleteTableNames.ItemIndex := DeleteTableNames.Items.IndexOf(FTableName)
190 <    else
191 <    if DeleteTableNames.Items.Count > 0 then
192 <      DeleteTableNames.ItemIndex := 0
193 <  end
108 >  case TabControl1.TabIndex of
109 >  4:
110 >    PageControl.ActivePage := ExecutePage;
111    else
112 <  begin
196 <    FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
197 <    DeleteTableNames.ItemIndex := DeleteTableNames.Items.IndexOf(TableName);
198 <  end;
199 <  FIBSystemTables.GetPrimaryKeys(DeleteTableNames.Text,DeletePrimaryKeys.Items);
200 <
201 < end;
202 <
203 < procedure TIBSQLEditorForm.GenerateBtnClick(Sender: TObject);
204 < var FieldNames: TStrings;
205 < begin
206 <  FieldNames := nil;
207 <  if PageControl.ActivePage = SelectPage then
208 <  begin
209 <    FieldNames := FIBSystemTables.GetFieldNames(SelectFieldsList);
210 <    FIBSystemTables.GenerateSelectSQL(SelectTableNames.Text,QuoteFields.Checked,FieldNames,SQLText.Lines);
211 <  end
212 <  else
213 <  if PageControl.ActivePage = InsertPage then
214 <  begin
215 <    FieldNames := FIBSystemTables.GetFieldNames(InsertFieldsList);
216 <    FIBSystemTables.GenerateInsertSQL(InsertTableNames.Text,QuoteFields.Checked,FieldNames,SQLText.Lines);
217 <  end
218 <  else
219 <  if PageControl.ActivePage = ModifyPage then
220 <  begin
221 <    FieldNames := FIBSystemTables.GetFieldNames(ModifyFieldsList);
222 <    FIBSystemTables.GenerateModifySQL(ModifyTableNames.Text,QuoteFields.Checked,FieldNames,SQLText.Lines);
223 <  end
224 <  else
225 <  if PageControl.ActivePage = DeletePage then
226 <     FIBSystemTables.GenerateDeleteSQL(DeleteTableNames.Text,QuoteFields.Checked,SQLText.Lines)
227 <  else
228 <  if PageControl.ActivePage = ExecutePage then
229 <     FIBSystemTables.GenerateExecuteSQL(ProcedureNames.Text,QuoteFields.Checked, FExecuteOnly,
230 <             ProcInputList.Items,ProcOutputList.Items,SQLText.Lines);
231 <
232 <  if FieldNames <> nil then
233 <    FieldNames.Free
234 < end;
235 <
236 < procedure TIBSQLEditorForm.TestBtnClick(Sender: TObject);
237 < begin
238 <  FIBSystemTables.TestSQL(SQLText.Text);
239 < end;
240 <
241 < procedure TIBSQLEditorForm.DeleteTableNamesCloseUp(Sender: TObject);
242 < begin
243 <  FTableName := DeleteTableNames.Text;
244 <  FIBSystemTables.GetPrimaryKeys(DeleteTableNames.Text,DeletePrimaryKeys.Items);
245 < end;
246 <
247 < procedure TIBSQLEditorForm.ExecutePageShow(Sender: TObject);
248 < var ProcName: string;
249 <    IsProcedureName: boolean;
250 < begin
251 <  FIBSystemTables.GetProcedureNames(ProcedureNames.Items);
252 <  if ProcedureNames.Items.Count > 0 then
253 <  begin
254 <    if (FIBSystemTables.GetStatementType(SQLText.Text,IsProcedureName) = SQLExecProcedure) or IsProcedureName then
255 <    begin
256 <      FIBSystemTables.GetTableAndColumns(SQLText.Text,ProcName,nil);
257 <      ProcedureNames.ItemIndex := ProcedureNames.Items.IndexOf(ProcName)
258 <    end
259 <    else
260 <      ProcedureNames.ItemIndex := 0;
112 >    PageControl.ActivePage := SelectPage;
113    end;
114 <  FIBSystemTables.GetProcParams(ProcedureNames.Text,FExecuteOnly,ProcInputList.Items,ProcOutputList.Items);
263 <  SelectProcedure.Visible :=  not FExecuteOnly;
114 >  SetupFlags;
115   end;
116  
117 < procedure TIBSQLEditorForm.InsertPageShow(Sender: TObject);
267 < var TableName: string;
117 > procedure TIBSQLEditorForm.UserProceduresAfterScroll(DataSet: TDataSet);
118   begin
119 <  FIBSystemTables.GetTableNames(InsertTableNames.Items);
120 <  if Trim(SQLText.Text) = '' then
121 <  begin
122 <    if FTableName <> '' then
273 <      InsertTableNames.ItemIndex := InsertTableNames.Items.IndexOf(FTableName)
119 >    SelectProcedure.Visible := (DataSet.FieldByName('RDB$PROCEDURE_TYPE').AsInteger = 1)
120 >      and (Dataset.FieldByName('RDB$PROCEDURE_OUTPUTS').AsInteger > 0);
121 >    if SelectProcedure.Visible then
122 >      OutputProcGrid.Columns[0].Width := 30
123      else
124 <    if InsertTableNames.Items.Count > 0 then
276 <      InsertTableNames.ItemIndex := 0
277 <  end
278 <  else
279 <  begin
280 <    FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
281 <    InsertTableNames.ItemIndex := InsertTableNames.Items.IndexOf(TableName);
282 <  end;
283 <  FIBSystemTables.GetFieldNames(InsertTableNames.Text,InsertFieldsList.Items);
284 <
124 >      OutputProcGrid.Columns[0].Width := 0;
125   end;
126  
127 < procedure TIBSQLEditorForm.Label13Click(Sender: TObject);
127 > procedure TIBSQLEditorForm.FormShow(Sender: TObject);
128   begin
129 <  FIBSystemTables.GetFieldNames(ModifyTableNames.Text,ModifyFieldsList.Items,IncludePrimaryKeys.checked);
130 <  FIBSystemTables.GetPrimaryKeys(ModifyTableNames.Text,ModifyPrimaryKeys.Items);
129 >  inherited;
130 >  SetupFlags;
131   end;
132  
133 < procedure TIBSQLEditorForm.ModifyPageShow(Sender: TObject);
294 < var TableName: string;
133 > procedure TIBSQLEditorForm.GenerateBtnClick(Sender: TObject);
134   begin
135 <   FIBSystemTables.GetTableNames(ModifyTableNames.Items);
136 <  if Trim(SQLText.Text) = '' then
137 <  begin
138 <    if FTableName <> '' then
139 <      ModifyTableNames.ItemIndex := ModifyTableNames.Items.IndexOf(FTableName)
140 <    else
141 <    if ModifyTableNames.Items.Count > 0 then
142 <      ModifyTableNames.ItemIndex := 0;
143 <  end
144 <  else
145 <  begin
307 <    FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
308 <    ModifyTableNames.ItemIndex := ModifyTableNames.Items.IndexOf(TableName);
135 >  case TabControl1.TabIndex of
136 >  0:
137 >    IBSQLEditFrame1.GenerateSelectSQL(QuoteFields.Checked,true);
138 >  1:
139 >    IBSQLEditFrame1.GenerateInsertSQL(QuoteFields.Checked);
140 >  2:
141 >    IBSQLEditFrame1.GenerateModifySQL(QuoteFields.Checked,IncludePrimaryKeys.Checked);
142 >  3:
143 >    IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked);
144 >  4:
145 >    IBSQLEditFrame1.GenerateExecuteSQL(QuoteFields.Checked);
146    end;
310  FIBSystemTables.GetFieldNames(ModifyTableNames.Text,ModifyFieldsList.Items,IncludePrimaryKeys.checked,false);
311  FIBSystemTables.GetPrimaryKeys(ModifyTableNames.Text,ModifyPrimaryKeys.Items);
312 end;
313
314 procedure TIBSQLEditorForm.ModifyTableNamesCloseUp(Sender: TObject);
315 begin
316  FTableName := ModifyTableNames.Text;
317  FIBSystemTables.GetFieldNames(ModifyTableNames.Text,ModifyFieldsList.Items,IncludePrimaryKeys.checked,false);
318  FIBSystemTables.GetPrimaryKeys(ModifyTableNames.Text,ModifyPrimaryKeys.Items);
319 end;
320
321 procedure TIBSQLEditorForm.ProcedureNamesCloseUp(Sender: TObject);
322 begin
323    FIBSystemTables.GetProcParams(ProcedureNames.Text,FExecuteOnly,ProcInputList.Items,ProcOutputList.Items);
324    SelectProcedure.Visible := not FExecuteOnly
147   end;
148  
149 < procedure TIBSQLEditorForm.SelectFieldsListDblClick(Sender: TObject);
150 < begin
151 <  SQLText.SelText:= (Sender as TListBox).Items[(Sender as TListBox).ItemIndex];
152 < end;
153 <
154 < procedure TIBSQLEditorForm.SelectPageShow(Sender: TObject);
155 < var TableName: string;
156 < begin
157 <  FIBSystemTables.GetTableNames(SelectTableNames.Items);
158 <  if Trim(SQLText.Text) = '' then
159 <  begin
160 <    if FTableName <> '' then
161 <      SelectTableNames.ItemIndex := SelectTableNames.Items.IndexOf(FTableName)
162 <    else
163 <    if SelectTableNames.Items.Count > 0 then
164 <      SelectTableNames.ItemIndex := 0;
165 <  end
149 > procedure TIBSQLEditorForm.SetupFlags;
150 > begin
151 >  IncludePrimaryKeys.Visible := TabControl1.TabIndex = 2;
152 >  FieldNamesGrid.Visible := TabControl1.TabIndex <> 3;
153 >  Label2.Visible := TabControl1.TabIndex <> 3;
154 >  IdentityGrid.Visible := TabControl1.TabIndex <> 3;
155 >  Label6.Visible := TabControl1.TabIndex <> 3;
156 >  ReadOnlyGrid.Visible := TabControl1.TabIndex <> 3;
157 >  Label5.Visible := TabControl1.TabIndex <> 3;
158 >  SelectSelectAll.Visible := TabControl1.TabIndex <> 3;
159 > end;
160 >
161 > procedure TIBSQLEditorForm.SetSQLStatementType(aType: TIBSQLStatementTypes);
162 > begin
163 >  inherited SetSQLStatementType(aType);
164 >  case aType of
165 >  SQLSelect:
166 >    TabControl1.TabIndex := 0;
167 >  SQLInsert:
168 >    TabControl1.TabIndex := 1;
169 >  SQLUpdate:
170 >    TabControl1.TabIndex := 2;
171 >  SQLDelete:
172 >    TabControl1.TabIndex := 3;
173    else
174 <  begin
346 <    FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
347 <    SelectTableNames.ItemIndex := SelectTableNames.Items.IndexOf(TableName);
174 >    TabControl1.TabIndex := 4;
175    end;
349  FIBSystemTables.GetFieldNames(SelectTableNames.Text,SelectFieldsList.Items);
350  FIBSystemTables.GetPrimaryKeys(SelectTableNames.Text,SelectPrimaryKeys.Items);
351 end;
352
353 procedure TIBSQLEditorForm.SelectTableNamesCloseUp(Sender: TObject);
354 begin
355  FTableName := SelectTableNames.Text;
356  try
357  FIBSystemTables.GetFieldNames(SelectTableNames.Text,SelectFieldsList.Items);
358  FIBSystemTables.GetPrimaryKeys(SelectTableNames.Text,SelectPrimaryKeys.Items);
359  except {ignore}  end;
360 end;
361
362 procedure TIBSQLEditorForm.InsertTableNamesCloseUp(Sender: TObject);
363 begin
364  FTableName := InsertTableNames.Text;
365  FIBSystemTables.GetFieldNames(InsertTableNames.Text,InsertFieldsList.Items);
366 end;
367
368 constructor TIBSQLEditorForm.Create(TheOwner: TComponent);
369 begin
370  inherited Create(TheOwner);
371  FIBSystemTables := TIBSystemTables.Create;
372 end;
373
374 destructor TIBSQLEditorForm.Destroy;
375 begin
376  if assigned(FIBSystemTables) then FIBSystemTables.Free;
377  inherited Destroy;
378 end;
379
380 procedure TIBSQLEditorForm.SetDatabase(Database: TIBDatabase);
381 begin
382  IBTransaction1.DefaultDatabase := Database;
383  FIBSystemTables.SelectDatabase(Database,IBTransaction1)
176   end;
177  
178   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines