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 7 by tony, Sun Aug 5 18:28:19 2012 UTC vs.
Revision 80 by tony, Mon Jan 1 11:31:07 2018 UTC

# Line 23 | Line 23
23   *  Contributor(s): ______________________________________.
24   *
25   *)
26
26   unit ibdeletesqleditor;
27  
28   {$mode objfpc}{$H+}
# Line 31 | Line 30 | unit ibdeletesqleditor;
30   interface
31  
32   uses
33 <  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
34 <  StdCtrls, IBSystemTables, IBDatabase;
33 >  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
34 >    ibselectsqleditor, IBDatabase, IBCustomDataset;
35  
36   type
37  
38    { TIBDeleteSQLEditorForm }
39  
40 <  TIBDeleteSQLEditorForm = class(TForm)
42 <    Button1: TButton;
43 <    Button2: TButton;
44 <    GenerateBtn: TButton;
45 <    TestBtn: TButton;
46 <    IBTransaction1: TIBTransaction;
47 <    Label1: TLabel;
48 <    Label3: TLabel;
49 <    Label4: TLabel;
50 <    PrimaryKeyList: TListBox;
51 <    QuoteFields: TCheckBox;
52 <    SQLText: TMemo;
53 <    TableNamesCombo: TComboBox;
40 >  TIBDeleteSQLEditorForm = class(TIBSelectSQLEditorForm)
41      procedure GenerateBtnClick(Sender: TObject);
55    procedure TestBtnClick(Sender: TObject);
56    procedure FormShow(Sender: TObject);
57    procedure PrimaryKeyListDblClick(Sender: TObject);
58    procedure TableNamesComboCloseUp(Sender: TObject);
42    private
43 <    { private declarations }
61 <    FIBSystemTables: TIBSystemTables;
43 >
44    public
45 <    { public declarations }
46 <    constructor Create(TheOwner: TComponent); override;
47 <    destructor Destroy; override;
48 <    procedure SetDatabase(Database: TIBDatabase);
67 <  end;
45 >
46 >  end;
47 >
48 > function EditSQL(DataSet: TIBCustomDataSet; SelectSQL: TStrings): boolean;
49  
50   var
51    IBDeleteSQLEditorForm: TIBDeleteSQLEditorForm;
52  
72 function EditSQL(Database: TIBDatabase; SelectSQL: TStrings): boolean;
73
53   implementation
54  
55   {$R *.lfm}
56  
57 < function EditSQL(Database: TIBDatabase; SelectSQL: TStrings): boolean;
57 > function EditSQL(DataSet: TIBCustomDataSet; SelectSQL: TStrings): boolean;
58   begin
59    Result := false;
60 <  if assigned(Database) then
60 >  if assigned(DataSet) and assigned(DataSet.Database) then
61      try
62 <      Database.Connected := true;
62 >      DataSet.Database.Connected := true;
63      except on E: Exception do
64        ShowMessage(E.Message)
65      end;
66  
67    with TIBDeleteSQLEditorForm.Create(Application) do
68    try
69 <    SetDatabase(Database);
70 <    SQLText.Lines.Assign(SelectSQL);
69 >    if assigned(DataSet) then
70 >    begin
71 >        IBSQLEditFrame1.Database := DataSet.Database;
72 >        GenerateParams.Checked := DataSet.GenerateParamNames;
73 >    end;
74 >    with IBSQLEditFrame1 do
75 >    begin
76 >      IncludePrimaryKeys := true;
77 >      IncludeReadOnlyFields := false;
78 >      ExecuteOnlyProcs := true;
79 >      SQLText.Lines.Assign(SelectSQL);
80 >    end;
81      Result := ShowModal = mrOK;
82      if Result then
83 <     SelectSQL.Assign(SQLText.Lines)
83 >    begin
84 >     SelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
85 >     if assigned(DataSet) then
86 >          DataSet.GenerateParamNames := GenerateParams.Checked
87 >    end;
88    finally
89      Free
90    end;
# Line 99 | Line 92 | end;
92  
93   { TIBDeleteSQLEditorForm }
94  
102 procedure TIBDeleteSQLEditorForm.FormShow(Sender: TObject);
103 var TableName: string;
104 begin
105  GenerateBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
106  TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
107  TableNamesCombo.Items.Clear;
108  try
109  FIBSystemTables.GetTableNames(TableNamesCombo.Items);
110  if TableNamesCombo.Items.Count > 0 then
111  begin
112    TableNamesCombo.ItemIndex := 0;
113    if Trim(SQLText.Text) <> '' then
114    begin
115      FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
116      TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName)
117    end;
118    FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
119  end;
120  except {ignore} end;
121 end;
122
123 procedure TIBDeleteSQLEditorForm.PrimaryKeyListDblClick(Sender: TObject);
124 begin
125  SQLText.SelText := PrimaryKeyList.Items[PrimaryKeyList.ItemIndex];
126  SQLText.SetFocus
127 end;
128
95   procedure TIBDeleteSQLEditorForm.GenerateBtnClick(Sender: TObject);
96   begin
97 <  FIBSystemTables.GenerateDeleteSQL(TableNamesCombo.Text,QuoteFields.Checked,SQLText.Lines)
98 < end;
99 <
100 < procedure TIBDeleteSQLEditorForm.TestBtnClick(Sender: TObject);
135 < begin
136 <  FIBSystemTables.TestSQL(SQLText.Lines.Text)
137 < end;
138 <
139 < procedure TIBDeleteSQLEditorForm.TableNamesComboCloseUp(Sender: TObject);
140 < begin
141 <  FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
142 < end;
143 <
144 < constructor TIBDeleteSQLEditorForm.Create(TheOwner: TComponent);
145 < begin
146 <  inherited Create(TheOwner);
147 <  FIBSystemTables := TIBSystemTables.Create;
148 < end;
149 <
150 < destructor TIBDeleteSQLEditorForm.Destroy;
151 < begin
152 <  if assigned(FIBSystemTables) then FIBSystemTables.Free;
153 <  inherited Destroy;
154 < end;
155 <
156 < procedure TIBDeleteSQLEditorForm.SetDatabase(Database: TIBDatabase);
157 < begin
158 <  IBTransaction1.DefaultDatabase := Database;
159 <  FIBSystemTables.SelectDatabase(Database,IBTransaction1)
97 >  if PageControl.ActivePage = ExecutePage then
98 >    IBSQLEditFrame1.GenerateExecuteSQL(QuoteFields.Checked)
99 >  else
100 >    IBSQLEditFrame1.GenerateDeleteSQL(QuoteFields.Checked);
101   end;
102  
103   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines