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

Comparing ibx/trunk/design/ibmodifysqleditor.pas (file contents):
Revision 7 by tony, Sun Aug 5 18:28:19 2012 UTC vs.
Revision 105 by tony, Thu Jan 18 14:37:32 2018 UTC

# Line 31 | Line 31 | unit ibmodifysqleditor;
31   interface
32  
33   uses
34 <  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
35 <  StdCtrls, IBSystemTables, IBDatabase;
34 >  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
35 >  StdCtrls, ComCtrls, ibselectsqleditor, IBSQLEditFrame, IBLookupComboEditBox,
36 >  IBDynamicGrid, IBDatabase, IBCustomDataset;
37  
38   type
39  
40    { TIBModifySQLEditorForm }
41  
42 <  TIBModifySQLEditorForm = class(TForm)
42 <    Button1: TButton;
43 <    Button2: TButton;
44 <    GenerateBtn: TButton;
45 <    TestBtn: TButton;
46 <    IBTransaction1: TIBTransaction;
42 >  TIBModifySQLEditorForm = class(TIBSelectSQLEditorForm)
43      IncludePrimaryKeys: TCheckBox;
44 <    FieldList: TListBox;
45 <    Label1: TLabel;
50 <    Label2: TLabel;
51 <    Label3: TLabel;
52 <    Label4: TLabel;
53 <    PrimaryKeyList: TListBox;
54 <    QuoteFields: TCheckBox;
55 <    SQLText: TMemo;
56 <    TableNamesCombo: TComboBox;
44 >    Label5: TLabel;
45 >    ReadOnlyGrid: TIBDynamicGrid;
46      procedure GenerateBtnClick(Sender: TObject);
47 <    procedure TestBtnClick(Sender: TObject);
59 <    procedure FieldListDblClick(Sender: TObject);
60 <    procedure FormShow(Sender: TObject);
61 <    procedure PrimaryKeyListDblClick(Sender: TObject);
62 <    procedure TableNamesComboCloseUp(Sender: TObject);
47 >    procedure IncludePrimaryKeysChange(Sender: TObject);
48    private
49 <    { private declarations }
50 <    FIBSystemTables: TIBSystemTables;
49 >
50 >  protected
51 >    procedure Loaded; override;
52 >
53    public
54 <    { public declarations }
55 <    constructor Create(TheOwner: TComponent); override;
56 <    destructor Destroy; override;
57 <    procedure SetDatabase(Database: TIBDatabase);
71 <  end;
54 >
55 >  end;
56 >
57 > function EditSQL(DataSet: TIBCustomDataSet;  SelectSQL: TStrings): boolean;
58  
59   var
60    IBModifySQLEditorForm: TIBModifySQLEditorForm;
61  
76 function EditSQL(Database: TIBDatabase;  SelectSQL: TStrings): boolean;
77
62   implementation
63  
64   {$R *.lfm}
65  
66 < function EditSQL(Database: TIBDatabase; SelectSQL: TStrings): boolean;
66 > function EditSQL(DataSet: TIBCustomDataSet; SelectSQL: TStrings): boolean;
67   begin
68    Result := false;
69 <  if assigned(Database) then
69 >  if assigned(DataSet) and assigned(DataSet.Database) then
70      try
71 <      Database.Connected := true;
71 >      DataSet.Database.Connected := true;
72      except on E: Exception do
73        ShowMessage(E.Message)
74      end;
75  
76    with TIBModifySQLEditorForm.Create(Application) do
77    try
78 <    SetDatabase(Database);
79 <    SQLText.Lines.Assign(SelectSQL);
78 >    if assigned(DataSet) then
79 >    begin
80 >        IBSQLEditFrame1.Database := DataSet.Database;
81 >        GenerateParams.Checked := DataSet.GenerateParamNames;
82 >    end;
83 >    with IBSQLEditFrame1 do
84 >    begin
85 >      IncludePrimaryKeys := false;
86 >      IncludeReadOnlyFields := false;
87 >      ExecuteOnlyProcs := true;
88 >      SQLText.Lines.Assign(SelectSQL);
89 >    end;
90 >    IncludePrimaryKeys.Checked := false;
91      Result := ShowModal = mrOK;
92      if Result then
93 <     SelectSQL.Assign(SQLText.Lines)
93 >    begin
94 >     SelectSQL.Assign(IBSQLEditFrame1.SQLText.Lines);
95 >     if assigned(DataSet) then
96 >          DataSet.GenerateParamNames := GenerateParams.Checked
97 >    end;
98    finally
99      Free
100    end;
# Line 103 | Line 102 | end;
102  
103   { TIBModifySQLEditorForm }
104  
105 < procedure TIBModifySQLEditorForm.FormShow(Sender: TObject);
107 < var TableName: string;
108 < begin
109 <  GenerateBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
110 <  TestBtn.Enabled := (IBTransaction1.DefaultDatabase <> nil) and IBTransaction1.DefaultDatabase.Connected;
111 <  TableNamesCombo.Items.Clear;
112 <  try
113 <  FIBSystemTables.GetTableNames(TableNamesCombo.Items);
114 <  if TableNamesCombo.Items.Count > 0 then
115 <  begin
116 <    TableNamesCombo.ItemIndex := 0;
117 <    if Trim(SQLText.Text) <> '' then
118 <    begin
119 <      FIBSystemTables.GetTableAndColumns(SQLText.Text,TableName,nil);
120 <      TableNamesCombo.ItemIndex := TableNamesCombo.Items.IndexOf(TableName)
121 <    end;
122 <    FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false);
123 <    FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
124 <  end;
125 <  except {ignore}  end;
126 < end;
127 <
128 < procedure TIBModifySQLEditorForm.PrimaryKeyListDblClick(Sender: TObject);
105 > procedure TIBModifySQLEditorForm.IncludePrimaryKeysChange(Sender: TObject);
106   begin
107 <  SQLText.SelText := PrimaryKeyList.Items[PrimaryKeyList.ItemIndex];
131 <  SQLText.SetFocus
107 >  IBSQLEditFrame1.IncludePrimaryKeys := IncludePrimaryKeys.Checked;
108   end;
109  
110 < procedure TIBModifySQLEditorForm.FieldListDblClick(Sender: TObject);
110 > procedure TIBModifySQLEditorForm.Loaded;
111   begin
112 <  SQLText.SelText := FieldList.Items[FieldList.ItemIndex];
113 <  SQLText.SetFocus
114 < end;
115 <
116 < procedure TIBModifySQLEditorForm.GenerateBtnClick(Sender: TObject);
141 < var FieldNames: TStrings;
142 < begin
143 <  FieldNames :=  FIBSystemTables.GetFieldNames(FieldList);
144 <  try
145 <    FIBSystemTables.GenerateModifySQL(TableNamesCombo.Text,QuoteFields.Checked,
146 <             FieldNames,SQLText.Lines)
147 <  finally
148 <    FieldNames.Free
112 >  inherited Loaded;
113 >  if IBSQLEditFrame1 <> nil then
114 >  begin
115 >   if ReadOnlyGrid <> nil then
116 >     ReadOnlyGrid.DataSource := IBSQLEditFrame1.ReadOnlyFieldsSource;
117    end;
118   end;
119  
120 < procedure TIBModifySQLEditorForm.TestBtnClick(Sender: TObject);
153 < begin
154 <  FIBSystemTables.TestSQL(SQLText.Lines.Text)
155 < end;
156 <
157 < procedure TIBModifySQLEditorForm.TableNamesComboCloseUp(Sender: TObject);
158 < begin
159 <  FIBSystemTables.GetFieldNames(TableNamesCombo.Text,FieldList.Items,IncludePrimaryKeys.checked,false);
160 <  FIBSystemTables.GetPrimaryKeys(TableNamesCombo.Text,PrimaryKeyList.Items);
161 < end;
162 <
163 < constructor TIBModifySQLEditorForm.Create(TheOwner: TComponent);
164 < begin
165 <  inherited Create(TheOwner);
166 <  FIBSystemTables := TIBSystemTables.Create;
167 < end;
168 <
169 < destructor TIBModifySQLEditorForm.Destroy;
120 > procedure TIBModifySQLEditorForm.GenerateBtnClick(Sender: TObject);
121   begin
122 <  if assigned(FIBSystemTables) then FIBSystemTables.Free;
123 <  inherited Destroy;
122 >  if PageControl.ActivePage = ExecutePage then
123 >    IBSQLEditFrame1.GenerateExecuteSQL(QuoteFields.Checked)
124 >  else
125 >    IBSQLEditFrame1.GenerateModifySQL(QuoteFields.Checked,not IncludePrimaryKeys.Checked);
126   end;
127  
175 procedure TIBModifySQLEditorForm.SetDatabase(Database: TIBDatabase);
176 begin
177  IBTransaction1.DefaultDatabase := Database;
178  FIBSystemTables.SelectDatabase(Database,IBTransaction1)
179 end;
128  
129   end.
130  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines