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 33 by tony, Sat Jul 18 12:30:52 2015 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 <    GenerateParams: TCheckBox;
44 <    GenerateBtn: TButton;
45 <    IBTransaction1: TIBTransaction;
46 <    Label5: TLabel;
47 <    SelectProcedure: TLabel;
48 <    TestBtn: TButton;
42 >  TIBSQLEditorForm = class(TIBInsertSQLEditorForm)
43      IncludePrimaryKeys: TCheckBox;
44 <    Label1: TLabel;
45 <    Label10: TLabel;
52 <    Label11: TLabel;
53 <    Label12: TLabel;
54 <    Label14: TLabel;
55 <    Label15: TLabel;
56 <    Label16: TLabel;
57 <    Label17: TLabel;
58 <    Label18: TLabel;
59 <    Label2: TLabel;
60 <    Label3: TLabel;
61 <    Label4: TLabel;
62 <    Label8: TLabel;
63 <    Label9: TLabel;
64 <    SelectFieldsList: TListBox;
65 <    ProcOutputList: TListBox;
66 <    SelectPrimaryKeys: TListBox;
67 <    InsertFieldsList: TListBox;
68 <    ModifyFieldsList: TListBox;
69 <    ModifyPrimaryKeys: TListBox;
70 <    DeletePrimaryKeys: TListBox;
71 <    ProcInputList: TListBox;
72 <    PageControl: TPageControl;
73 <    QuoteFields: TCheckBox;
74 <    SQLText: TMemo;
75 <    SelectPage: TTabSheet;
76 <    InsertPage: TTabSheet;
77 <    ModifyPage: TTabSheet;
78 <    DeletePage: TTabSheet;
79 <    ExecutePage: TTabSheet;
80 <    SelectTableNames: TComboBox;
81 <    InsertTableNames: TComboBox;
82 <    ModifyTableNames: TComboBox;
83 <    DeleteTableNames: TComboBox;
84 <    ProcedureNames: TComboBox;
85 <    procedure GenerateBtnClick(Sender: TObject);
86 <    procedure TestBtnClick(Sender: TObject);
87 <    procedure DeletePageShow(Sender: TObject);
88 <    procedure DeleteTableNamesCloseUp(Sender: TObject);
89 <    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);
94 <    procedure ModifyPageShow(Sender: TObject);
95 <    procedure ModifyTableNamesCloseUp(Sender: TObject);
96 <    procedure ProcedureNamesCloseUp(Sender: TObject);
97 <    procedure SelectFieldsListDblClick(Sender: TObject);
98 <    procedure SelectPageShow(Sender: TObject);
99 <    procedure SelectTableNamesCloseUp(Sender: TObject);
100 <    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;
105 <    FExecuteOnly: boolean;
51 >    procedure SetupFlags;
52 >  protected
53 >    procedure SetSQLStatementType(aType: TIBSQLStatementTypes); override;
54    public
55 <    { public declarations }
108 <    constructor Create(TheOwner: TComponent); override;
109 <    destructor Destroy; override;
110 <    procedure SetDatabase(Database: TIBDatabase);
55 >
56    end;
57  
58 + function EditSQL(aIBSQL: TIBSQL): boolean;
59 +
60   var
61    IBSQLEditorForm: TIBSQLEditorForm;
62  
116 function EditIBSQL(DataSet: TIBSQL): boolean;
117
63   implementation
64  
65   {$R *.lfm}
66  
67 < uses InterfaceBase;
123 <
124 < 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);
81 <    GenerateParams.Checked := DataSet.GenerateParamNames;
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 <      begin
95 <            DataSet.SQL.Assign(SQLText.Lines);
96 <            DataSet.GenerateParamNames := GenerateParams.Checked
97 <      end;
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;
148
102   end;
103  
104   { TIBSQLEditorForm }
105  
106 < procedure TIBSQLEditorForm.FormShow(Sender: TObject);
154 < var IsProcedureName: boolean;
106 > procedure TIBSQLEditorForm.TabControl1Change(Sender: TObject);
107   begin
108 <  if WidgetSet.LCLPlatform = lpGtk2 then
109 <    PageControl.TabPosition := tpLeft
108 >  case TabControl1.TabIndex of
109 >  4:
110 >    PageControl.ActivePage := ExecutePage;
111    else
112 <  PageControl.TabPosition := tpTop;
160 <  GenerateBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
161 <  TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
162 <  if Trim(SQLText.Text) <> '' then
163 <  begin
164 <    case FIBSystemTables.GetStatementType(SQLText.Text,IsProcedureName) of
165 <    SQLSelect:
166 <      if IsProcedureName then
167 <        PageControl.ActivePage := ExecutePage
168 <      else
169 <        PageControl.ActivePage := SelectPage;
170 <    SQLInsert:  PageControl.ActivePage := InsertPage;
171 <    SQLUpdate:  PageControl.ActivePage := ModifyPage;
172 <    SQLDelete:  PageControl.ActivePage := DeletePage;
173 <    SQLExecProcedure: PageControl.ActivePage := ExecutePage;
174 <    else
175 <      PageControl.ActivePage := SelectPage;
176 <    end;
177 <    FIBSystemTables.GetTableAndColumns(SQLText.Text,FTableName,nil)
112 >    PageControl.ActivePage := SelectPage;
113    end;
114 +  SetupFlags;
115   end;
116  
117 < procedure TIBSQLEditorForm.IncludePrimaryKeysClick(Sender: TObject);
182 < begin
183 <  FIBSystemTables.GetFieldNames(ModifyTableNames.Text,ModifyFieldsList.Items,IncludePrimaryKeys.checked);
184 <  FIBSystemTables.GetPrimaryKeys(ModifyTableNames.Text,ModifyPrimaryKeys.Items);
185 < end;
186 <
187 < procedure TIBSQLEditorForm.DeletePageShow(Sender: TObject);
188 < var TableName: string;
117 > procedure TIBSQLEditorForm.UserProceduresAfterScroll(DataSet: TDataSet);
118   begin
119 <  FIBSystemTables.GetTableNames(DeleteTableNames.Items);
120 <  if Trim(SQLText.Text) = '' then
121 <  begin
122 <    if FTableName <> '' then
194 <      DeleteTableNames.ItemIndex := DeleteTableNames.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 DeleteTableNames.Items.Count > 0 then
197 <      DeleteTableNames.ItemIndex := 0
198 <  end
199 <  else
200 <  begin
201 <    FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
202 <    DeleteTableNames.ItemIndex := DeleteTableNames.Items.IndexOf(TableName);
203 <  end;
204 <  FIBSystemTables.GetPrimaryKeys(DeleteTableNames.Text,DeletePrimaryKeys.Items);
205 <
124 >      OutputProcGrid.Columns[0].Width := 0;
125   end;
126  
127 < procedure TIBSQLEditorForm.GenerateBtnClick(Sender: TObject);
209 < var FieldNames: TStrings;
210 < begin
211 <  FieldNames := nil;
212 <  if PageControl.ActivePage = SelectPage then
213 <  begin
214 <    FieldNames := FIBSystemTables.GetFieldNames(SelectFieldsList);
215 <    FIBSystemTables.GenerateSelectSQL(SelectTableNames.Text,QuoteFields.Checked,FieldNames,SQLText.Lines);
216 <  end
217 <  else
218 <  if PageControl.ActivePage = InsertPage then
219 <  begin
220 <    FieldNames := FIBSystemTables.GetFieldNames(InsertFieldsList);
221 <    FIBSystemTables.GenerateInsertSQL(InsertTableNames.Text,QuoteFields.Checked,FieldNames,SQLText.Lines);
222 <  end
223 <  else
224 <  if PageControl.ActivePage = ModifyPage then
225 <  begin
226 <    FieldNames := FIBSystemTables.GetFieldNames(ModifyFieldsList);
227 <    FIBSystemTables.GenerateModifySQL(ModifyTableNames.Text,QuoteFields.Checked,FieldNames,SQLText.Lines);
228 <  end
229 <  else
230 <  if PageControl.ActivePage = DeletePage then
231 <     FIBSystemTables.GenerateDeleteSQL(DeleteTableNames.Text,QuoteFields.Checked,SQLText.Lines)
232 <  else
233 <  if PageControl.ActivePage = ExecutePage then
234 <     FIBSystemTables.GenerateExecuteSQL(ProcedureNames.Text,QuoteFields.Checked, FExecuteOnly,
235 <             ProcInputList.Items,ProcOutputList.Items,SQLText.Lines);
236 <
237 <  if FieldNames <> nil then
238 <    FieldNames.Free
239 < end;
240 <
241 < procedure TIBSQLEditorForm.TestBtnClick(Sender: TObject);
242 < begin
243 <  FIBSystemTables.TestSQL(SQLText.Text,GenerateParams.Checked);
244 < end;
245 <
246 < procedure TIBSQLEditorForm.DeleteTableNamesCloseUp(Sender: TObject);
247 < begin
248 <  FTableName := DeleteTableNames.Text;
249 <  FIBSystemTables.GetPrimaryKeys(DeleteTableNames.Text,DeletePrimaryKeys.Items);
250 < end;
251 <
252 < procedure TIBSQLEditorForm.ExecutePageShow(Sender: TObject);
253 < var ProcName: string;
254 <    IsProcedureName: boolean;
255 < begin
256 <  FIBSystemTables.GetProcedureNames(ProcedureNames.Items);
257 <  if ProcedureNames.Items.Count > 0 then
258 <  begin
259 <    if (FIBSystemTables.GetStatementType(SQLText.Text,IsProcedureName) = SQLExecProcedure) or IsProcedureName then
260 <    begin
261 <      FIBSystemTables.GetTableAndColumns(SQLText.Text,ProcName,nil);
262 <      ProcedureNames.ItemIndex := ProcedureNames.Items.IndexOf(ProcName)
263 <    end
264 <    else
265 <      ProcedureNames.ItemIndex := 0;
266 <  end;
267 <  FIBSystemTables.GetProcParams(ProcedureNames.Text,FExecuteOnly,ProcInputList.Items,ProcOutputList.Items);
268 <  SelectProcedure.Visible :=  not FExecuteOnly;
269 < end;
270 <
271 < procedure TIBSQLEditorForm.InsertPageShow(Sender: TObject);
272 < var TableName: string;
273 < begin
274 <  FIBSystemTables.GetTableNames(InsertTableNames.Items);
275 <  if Trim(SQLText.Text) = '' then
276 <  begin
277 <    if FTableName <> '' then
278 <      InsertTableNames.ItemIndex := InsertTableNames.Items.IndexOf(FTableName)
279 <    else
280 <    if InsertTableNames.Items.Count > 0 then
281 <      InsertTableNames.ItemIndex := 0
282 <  end
283 <  else
284 <  begin
285 <    FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
286 <    InsertTableNames.ItemIndex := InsertTableNames.Items.IndexOf(TableName);
287 <  end;
288 <  FIBSystemTables.GetFieldNames(InsertTableNames.Text,InsertFieldsList.Items);
289 <
290 < end;
291 <
292 < 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);
299 < 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
312 <    FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
313 <    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;
315  FIBSystemTables.GetFieldNames(ModifyTableNames.Text,ModifyFieldsList.Items,IncludePrimaryKeys.checked,false);
316  FIBSystemTables.GetPrimaryKeys(ModifyTableNames.Text,ModifyPrimaryKeys.Items);
317 end;
318
319 procedure TIBSQLEditorForm.ModifyTableNamesCloseUp(Sender: TObject);
320 begin
321  FTableName := ModifyTableNames.Text;
322  FIBSystemTables.GetFieldNames(ModifyTableNames.Text,ModifyFieldsList.Items,IncludePrimaryKeys.checked,false);
323  FIBSystemTables.GetPrimaryKeys(ModifyTableNames.Text,ModifyPrimaryKeys.Items);
324 end;
325
326 procedure TIBSQLEditorForm.ProcedureNamesCloseUp(Sender: TObject);
327 begin
328    FIBSystemTables.GetProcParams(ProcedureNames.Text,FExecuteOnly,ProcInputList.Items,ProcOutputList.Items);
329    SelectProcedure.Visible := not FExecuteOnly
330 end;
331
332 procedure TIBSQLEditorForm.SelectFieldsListDblClick(Sender: TObject);
333 begin
334  SQLText.SelText:= (Sender as TListBox).Items[(Sender as TListBox).ItemIndex];
147   end;
148  
149 < procedure TIBSQLEditorForm.SelectPageShow(Sender: TObject);
150 < var TableName: string;
151 < begin
152 <  FIBSystemTables.GetTableNames(SelectTableNames.Items);
153 <  if Trim(SQLText.Text) = '' then
154 <  begin
155 <    if FTableName <> '' then
156 <      SelectTableNames.ItemIndex := SelectTableNames.Items.IndexOf(FTableName)
157 <    else
158 <    if SelectTableNames.Items.Count > 0 then
159 <      SelectTableNames.ItemIndex := 0;
160 <  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
351 <    FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
352 <    SelectTableNames.ItemIndex := SelectTableNames.Items.IndexOf(TableName);
174 >    TabControl1.TabIndex := 4;
175    end;
354  FIBSystemTables.GetFieldNames(SelectTableNames.Text,SelectFieldsList.Items);
355  FIBSystemTables.GetPrimaryKeys(SelectTableNames.Text,SelectPrimaryKeys.Items);
356 end;
357
358 procedure TIBSQLEditorForm.SelectTableNamesCloseUp(Sender: TObject);
359 begin
360  FTableName := SelectTableNames.Text;
361  try
362  FIBSystemTables.GetFieldNames(SelectTableNames.Text,SelectFieldsList.Items);
363  FIBSystemTables.GetPrimaryKeys(SelectTableNames.Text,SelectPrimaryKeys.Items);
364  except {ignore}  end;
365 end;
366
367 procedure TIBSQLEditorForm.InsertTableNamesCloseUp(Sender: TObject);
368 begin
369  FTableName := InsertTableNames.Text;
370  FIBSystemTables.GetFieldNames(InsertTableNames.Text,InsertFieldsList.Items);
371 end;
372
373 constructor TIBSQLEditorForm.Create(TheOwner: TComponent);
374 begin
375  inherited Create(TheOwner);
376  FIBSystemTables := TIBSystemTables.Create;
377 end;
378
379 destructor TIBSQLEditorForm.Destroy;
380 begin
381  if assigned(FIBSystemTables) then FIBSystemTables.Free;
382  inherited Destroy;
383 end;
384
385 procedure TIBSQLEditorForm.SetDatabase(Database: TIBDatabase);
386 begin
387  IBTransaction1.DefaultDatabase := Database;
388  FIBSystemTables.SelectDatabase(Database,IBTransaction1)
176   end;
177  
178   end.
179 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines