|
@@ -164,8 +164,6 @@ type
|
|
{ private declarations }
|
|
{ private declarations }
|
|
FDBIndex: Integer; // Index of selected registered database
|
|
FDBIndex: Integer; // Index of selected registered database
|
|
FRegRec: TRegisteredDatabase;
|
|
FRegRec: TRegisteredDatabase;
|
|
- FResultControls: array of TObject;
|
|
|
|
- FParentResultControls: array of TObject;
|
|
|
|
FOptions: set of TSynSearchOption;
|
|
FOptions: set of TSynSearchOption;
|
|
FIBConnection: TIBConnection;
|
|
FIBConnection: TIBConnection;
|
|
FSQLTrans: TSQLTransaction;
|
|
FSQLTrans: TSQLTransaction;
|
|
@@ -190,7 +188,8 @@ type
|
|
procedure ExecuteQuery;
|
|
procedure ExecuteQuery;
|
|
function GetNewTabNum: string;
|
|
function GetNewTabNum: string;
|
|
procedure FinishCellEditing(DataSet: TDataSet);
|
|
procedure FinishCellEditing(DataSet: TDataSet);
|
|
- function GetRecordSet(TabIndex: Integer): TSQLQuery;
|
|
|
|
|
|
+ // Gets sql query on current result tabsheet
|
|
|
|
+ function GetRecordSet: TSQLQuery;
|
|
// Gets both querytype and whether SQL is DML or DDL
|
|
// Gets both querytype and whether SQL is DML or DDL
|
|
// Investigates QueryList[LookAtIndex] to find out
|
|
// Investigates QueryList[LookAtIndex] to find out
|
|
function GetQuerySQLType(QueryList: TStringList; var LookAtIndex: Integer;
|
|
function GetQuerySQLType(QueryList: TStringList; var LookAtIndex: Integer;
|
|
@@ -405,20 +404,31 @@ procedure TfmQueryWindow.ApplyClick(Sender: TObject);
|
|
var
|
|
var
|
|
i, x: Integer;
|
|
i, x: Integer;
|
|
aTableName: string;
|
|
aTableName: string;
|
|
- aQuery: TSQLQuery;
|
|
|
|
|
|
+ UpdateQuery: TSQLQuery;
|
|
PKIndexName: string;
|
|
PKIndexName: string;
|
|
ConstraintName: string;
|
|
ConstraintName: string;
|
|
KeyList, FieldsList: TStringList;
|
|
KeyList, FieldsList: TStringList;
|
|
WhereClause: string;
|
|
WhereClause: string;
|
|
RecordSet: TSQLQuery;
|
|
RecordSet: TSQLQuery;
|
|
TabIndex: Integer;
|
|
TabIndex: Integer;
|
|
- //todo: review this and use regular FPC databound controls? autogenerated updatesql etc
|
|
|
|
|
|
+ //todo: review this and perhaps use regular FPC databound controls? autogenerated updatesql etc
|
|
FieldsSQL: string;
|
|
FieldsSQL: string;
|
|
begin
|
|
begin
|
|
try
|
|
try
|
|
TabIndex:= pgOutputPageCtl.TabIndex;
|
|
TabIndex:= pgOutputPageCtl.TabIndex;
|
|
- aTableName:= GetTableName(GetCurrentSQLText);
|
|
|
|
- RecordSet:= GetRecordSet(TabIndex);
|
|
|
|
|
|
+ RecordSet:= nil;
|
|
|
|
+ RecordSet:= GetRecordSet;
|
|
|
|
+ aTableName:= GetTableName(RecordSet.SQL.Text);
|
|
|
|
+
|
|
|
|
+ // Better safe than sorry
|
|
|
|
+ if not(Assigned(RecordSet)) then
|
|
|
|
+ begin
|
|
|
|
+ ShowMessage('Error getting query from tabsheet.');
|
|
|
|
+ {$IFDEF DEBUG}
|
|
|
|
+ SendDebug('ApplyClick: GetRecordSet call returned nil recordset');
|
|
|
|
+ {$ENDIF}
|
|
|
|
+ exit;
|
|
|
|
+ end;
|
|
|
|
|
|
// Get primary key name
|
|
// Get primary key name
|
|
PKIndexName:= fmMain.GetPrimaryKeyIndexName(FDBIndex, ATableName, ConstraintName);
|
|
PKIndexName:= fmMain.GetPrimaryKeyIndexName(FDBIndex, ATableName, ConstraintName);
|
|
@@ -426,13 +436,13 @@ begin
|
|
begin
|
|
begin
|
|
KeyList:= TStringList.Create;
|
|
KeyList:= TStringList.Create;
|
|
Fieldslist:= TStringList.Create;
|
|
Fieldslist:= TStringList.Create;
|
|
- aQuery:= TSQLQuery.Create(nil);
|
|
|
|
|
|
+ UpdateQuery:= TSQLQuery.Create(nil);
|
|
try
|
|
try
|
|
- aQuery.DataBase:= FIBConnection;
|
|
|
|
- aQuery.Transaction:= FSQLTrans;
|
|
|
|
|
|
+ UpdateQuery.DataBase:= FIBConnection;
|
|
|
|
+ UpdateQuery.Transaction:= FSQLTrans;
|
|
|
|
|
|
// Get primary key fields
|
|
// Get primary key fields
|
|
- fmMain.GetIndexFields(ATableName, PKIndexName, aQuery, KeyList);
|
|
|
|
|
|
+ fmMain.GetIndexFields(ATableName, PKIndexName, UpdateQuery, KeyList);
|
|
fmMain.GetFields(FDBIndex, ATableName, FieldsList);
|
|
fmMain.GetFields(FDBIndex, ATableName, FieldsList);
|
|
WhereClause:= 'where ';
|
|
WhereClause:= 'where ';
|
|
|
|
|
|
@@ -442,7 +452,7 @@ begin
|
|
begin
|
|
begin
|
|
FieldsSQL:= '';
|
|
FieldsSQL:= '';
|
|
RecordSet.RecNo:= FModifiedRecords[TabIndex][i];
|
|
RecordSet.RecNo:= FModifiedRecords[TabIndex][i];
|
|
- for x:= 0 to RecordSet.Fields.Count - 1 do
|
|
|
|
|
|
+ for x:= 0 to RecordSet.FieldCount - 1 do
|
|
begin
|
|
begin
|
|
if (FieldsList.IndexOf(RecordSet.Fields[x].FieldName) <> -1) and // Field exist in origional table
|
|
if (FieldsList.IndexOf(RecordSet.Fields[x].FieldName) <> -1) and // Field exist in origional table
|
|
(RecordSet.Fields[x].NewValue <> RecordSet.Fields[x].OldValue) then // field data has been modified
|
|
(RecordSet.Fields[x].NewValue <> RecordSet.Fields[x].OldValue) then // field data has been modified
|
|
@@ -467,8 +477,8 @@ begin
|
|
// Update current record
|
|
// Update current record
|
|
if FieldsSQL <> '' then
|
|
if FieldsSQL <> '' then
|
|
begin
|
|
begin
|
|
- aQuery.Close;
|
|
|
|
- aQuery.SQL.Text:= 'update ' + aTableName + ' set ' + FieldsSQL;
|
|
|
|
|
|
+ UpdateQuery.Close;
|
|
|
|
+ UpdateQuery.SQL.Text:= 'update ' + aTableName + ' set ' + FieldsSQL;
|
|
|
|
|
|
WhereClause:= 'where ';
|
|
WhereClause:= 'where ';
|
|
// where clause
|
|
// where clause
|
|
@@ -489,8 +499,8 @@ begin
|
|
WhereClause += ' and ';
|
|
WhereClause += ' and ';
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
- aQuery.SQL.Add(WhereClause);
|
|
|
|
- aQuery.ExecSQL;
|
|
|
|
|
|
+ UpdateQuery.SQL.Add(WhereClause);
|
|
|
|
+ UpdateQuery.ExecSQL;
|
|
(Sender as TBitBtn).Visible:= False;
|
|
(Sender as TBitBtn).Visible:= False;
|
|
|
|
|
|
// Auto commit
|
|
// Auto commit
|
|
@@ -507,7 +517,7 @@ begin
|
|
finally
|
|
finally
|
|
FieldsList.Free;
|
|
FieldsList.Free;
|
|
KeyList.Free;
|
|
KeyList.Free;
|
|
- aQuery.Free;
|
|
|
|
|
|
+ UpdateQuery.Free;
|
|
end;
|
|
end;
|
|
end
|
|
end
|
|
else
|
|
else
|
|
@@ -540,7 +550,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
// Found the hosting panel; this should have the Apply button
|
|
// Found the hosting panel; this should have the Apply button
|
|
- // as well as the navigator etc
|
|
|
|
|
|
+ // as well as the commit button and the tdbnavigator
|
|
if assigned(ParentPanel) then
|
|
if assigned(ParentPanel) then
|
|
begin
|
|
begin
|
|
for i:= 0 to ParentPanel.ControlCount-1 do
|
|
for i:= 0 to ParentPanel.ControlCount-1 do
|
|
@@ -562,13 +572,35 @@ end;
|
|
procedure TfmQueryWindow.EnableCommitButton;
|
|
procedure TfmQueryWindow.EnableCommitButton;
|
|
var
|
|
var
|
|
i: Integer;
|
|
i: Integer;
|
|
|
|
+ Ctl: TControl;
|
|
|
|
+ ParentPanel: TPanel;
|
|
begin
|
|
begin
|
|
- for i:= 0 to High(FResultControls) do
|
|
|
|
- if (FResultControls[i] is TBitBtn) and ((FResultControls[i] as TBitBtn).Tag = PageControl1.TabIndex)
|
|
|
|
- and ((FResultControls[i] as TBitBtn).Caption = 'Commit') then
|
|
|
|
|
|
+ //todo: priority high test whether this works
|
|
|
|
+ // The page has a panel that contains the button
|
|
|
|
+ ParentPanel:=nil;
|
|
|
|
+ for i:= 0 to pgOutputPageCtl.ActivePage.ControlCount-1 do
|
|
begin
|
|
begin
|
|
- (FResultControls[i] as TBitBtn).Visible:= True;
|
|
|
|
- Break;
|
|
|
|
|
|
+ Ctl:=pgOutputPageCtl.ActivePage.Controls[i];
|
|
|
|
+ if Ctl is TPanel then
|
|
|
|
+ begin
|
|
|
|
+ ParentPanel:= TPanel(Ctl); //found
|
|
|
|
+ break;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ // Found the hosting panel; this should have the Apply, Commit button
|
|
|
|
+ // as well as the navigator
|
|
|
|
+ if assigned(ParentPanel) then
|
|
|
|
+ begin
|
|
|
|
+ for i:= 0 to ParentPanel.ControlCount-1 do
|
|
|
|
+ begin
|
|
|
|
+ Ctl:=ParentPanel.Controls[i];
|
|
|
|
+ if (Ctl is TBitBtn) and
|
|
|
|
+ ((Ctl as TBitBtn).Caption = 'Commit') then
|
|
|
|
+ begin
|
|
|
|
+ (Ctl as TBitBtn).Visible:= true;
|
|
|
|
+ Break;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -592,7 +624,6 @@ begin
|
|
end;
|
|
end;
|
|
if Pos(';', Result) > 0 then
|
|
if Pos(';', Result) > 0 then
|
|
Delete(Result, Pos(';', Result), 1);
|
|
Delete(Result, Pos(';', Result), 1);
|
|
-
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -601,12 +632,15 @@ end;
|
|
function TfmQueryWindow.GetCurrentSQLText: string;
|
|
function TfmQueryWindow.GetCurrentSQLText: string;
|
|
var
|
|
var
|
|
i: Integer;
|
|
i: Integer;
|
|
|
|
+ Ctl: TControl;
|
|
begin
|
|
begin
|
|
- for i:= 0 to High(FResultControls) do
|
|
|
|
|
|
+ // Tabsheet has grid as well as panel
|
|
|
|
+ for i:= 0 to pgOutputPageCtl.ActivePage.ControlCount-1 do
|
|
begin
|
|
begin
|
|
- if (FResultControls[i] is TDBGrid) and ((FResultControls[i] as TDBGrid).Tag = PageControl1.TabIndex) then
|
|
|
|
|
|
+ Ctl:=pgOutputPageCtl.ActivePage.Controls[i];
|
|
|
|
+ if (Ctl is TDBGrid) then
|
|
begin
|
|
begin
|
|
- Result:= ((FResultControls[i] as TDBGrid).DataSource.DataSet as TSQLQuery).SQL.Text;
|
|
|
|
|
|
+ Result:= (TDBGrid(Ctl).DataSource.DataSet as TSQLQuery).SQL.Text;
|
|
Break;
|
|
Break;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -642,16 +676,19 @@ end;
|
|
|
|
|
|
{ GetRecordSet: return result recordset of a page tab }
|
|
{ GetRecordSet: return result recordset of a page tab }
|
|
|
|
|
|
-function TfmQueryWindow.GetRecordSet(TabIndex: Integer): TSQLQuery;
|
|
|
|
|
|
+function TfmQueryWindow.GetRecordSet: TSQLQuery;
|
|
var
|
|
var
|
|
i: Integer;
|
|
i: Integer;
|
|
|
|
+ Ctl: TControl;
|
|
begin
|
|
begin
|
|
- for i:= 0 to High(FResultControls) do
|
|
|
|
|
|
+ // Tabsheet has grid as well as panel - let's use that to get the dataset
|
|
|
|
+ //todo: high priority perhaps better go directly to Tsqlquery object?
|
|
|
|
+ for i:= 0 to pgOutputPageCtl.ActivePage.ControlCount-1 do
|
|
begin
|
|
begin
|
|
- if (FResultControls[i] is TSQLQuery) and
|
|
|
|
- ((FResultControls[i] as TSQLQuery).Tag = TabIndex) then
|
|
|
|
|
|
+ Ctl:=pgOutputPageCtl.ActivePage.Controls[i];
|
|
|
|
+ if (Ctl is TDBGrid) then
|
|
begin
|
|
begin
|
|
- Result:= FResultControls[i] as TSQLQuery;
|
|
|
|
|
|
+ Result:= (TDBGrid(Ctl).DataSource.DataSet as TSQLQuery);
|
|
Break;
|
|
Break;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -2096,29 +2133,43 @@ var
|
|
i: Integer;
|
|
i: Integer;
|
|
begin
|
|
begin
|
|
TabSheet:= nil;
|
|
TabSheet:= nil;
|
|
|
|
+
|
|
// Get DataSet's TTabsheet
|
|
// Get DataSet's TTabsheet
|
|
|
|
+ //todo: high
|
|
|
|
+ //showmessage('todo: priority high same approach as apply button');
|
|
|
|
+ {
|
|
for i:= 0 to High(FResultControls) do
|
|
for i:= 0 to High(FResultControls) do
|
|
- if (FResultControls[i] <> nil) and
|
|
|
|
- (DataSet = FResultControls[i]) then
|
|
|
|
begin
|
|
begin
|
|
- TabSheet:= FParentResultControls[i] as TTabSheet;
|
|
|
|
- Break;
|
|
|
|
|
|
+ if (FResultControls[i] <> nil) and
|
|
|
|
+ (DataSet = FResultControls[i]) then
|
|
|
|
+ begin
|
|
|
|
+ TabSheet:= FParentResultControls[i] as TTabSheet;
|
|
|
|
+ Break;
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
-
|
|
|
|
-
|
|
|
|
- // Search for status bar inside current query result TabSheet
|
|
|
|
|
|
+ }
|
|
|
|
+ // Search for status bar inside current query result TTabSheet
|
|
if TabSheet <> nil then
|
|
if TabSheet <> nil then
|
|
- for i:= 0 to High(FResultControls) do
|
|
|
|
- if FResultControls[i] <> nil then
|
|
|
|
- if (FParentResultControls[i] <> nil) and ((FParentResultControls[i] as TTabSheet) = TabSheet)
|
|
|
|
- and (FResultControls[i] is TStatusBar) then
|
|
|
|
|
|
+ begin
|
|
|
|
+ //todo: high
|
|
|
|
+ //showmessage('todo: priority high same approach as apply button');
|
|
|
|
+ {
|
|
|
|
+ for i:= 0 to High(FResultControls) do
|
|
begin
|
|
begin
|
|
- // Display current record and number of total records in status bar
|
|
|
|
- (FResultControls[i] as TStatusBar).SimpleText:= IntToStr(DataSet.RecordCount) +
|
|
|
|
- ' records fetched. At record # ' + IntToStr(DataSet.RecNo);
|
|
|
|
- break;
|
|
|
|
|
|
+ if FResultControls[i] <> nil then
|
|
|
|
+ begin
|
|
|
|
+ if (FParentResultControls[i] <> nil) and ((FParentResultControls[i] as TTabSheet) = TabSheet)
|
|
|
|
+ and (FResultControls[i] is TStatusBar) then
|
|
|
|
+ begin
|
|
|
|
+ // Display current record and number of total records in status bar
|
|
|
|
+ (FResultControls[i] as TStatusBar).SimpleText:= IntToStr(DataSet.RecordCount) +
|
|
|
|
+ ' records fetched. At record # ' + IntToStr(DataSet.RecNo);
|
|
|
|
+ break;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ }
|
|
end;
|
|
end;
|
|
-
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|