Hi,
I have currently found out, that the TMSConnection.OpenDatasets method does not correctly replace macros - all macros are replaced only with empty string!
Is there some simple workaround?
Thanks, Ludek.
TMSConnection.OpenDatasets & macros
Re: TMSConnection.OpenDatasets & macros
would you mind using such helper method instead?
I replaced adding of the .sql.text with adding of .finalsql... and some underscores to access protected elements...
Code: Select all
type
TCustomMSDatasetHelper = class helper for TCustomMSDataset
private
procedure SetBulkExecuting(value: boolean);
function GetFIRecordSet: TOLEDBRecordSet;
public
procedure _DoBeforeOpenCursor;
procedure _CloseCursor;
property _FBulkExecuting: boolean write SetBulkExecuting;
property _FIRecordset: TOLEDBRecordSet read GetFIRecordset;
end;
TCustomMSConnectionHelper = class helper for TCustomMSConnection
private
function GetFDataset: TCustomMSDataset;
procedure SetFDataset(const Value: TCustomMSDataset);
public
property _FDataset: TCustomMSDataset read GetFDataset write SetFDataset;
end;
{ TCustomMSDatasetHelper }
procedure TCustomMSDatasetHelper.SetBulkExecuting(value: boolean);
begin
FBulkExecuting := value;
end;
procedure TCustomMSDatasetHelper._DoBeforeOpenCursor;
begin
DoBeforeOpenCursor;
end;
function TCustomMSDatasetHelper.GetFIRecordSet: TOLEDBRecordSet;
begin
result := FIRecordSet;
end;
procedure TCustomMSDatasetHelper._CloseCursor;
begin
CloseCursor;
end;
{ TCustomMSConnectionHelper }
function TCustomMSConnectionHelper.GetFDataset: TCustomMSDataset;
begin
result := FDataset;
end;
procedure TCustomMSConnectionHelper.SetFDataset(const Value: TCustomMSDataset);
begin
FDataset := value;
end;
procedure OpenDatasets(c: TCustomMSConnection; const ds: array of TCustomMSDataset);
var
OldAutoPrepare: boolean;
i, p: Integer;
begin
if c._FDataSet = nil then
c._FDataSet := c.CreateDataSet as TCustomMSDataSet;
c._FDataSet._FBulkExecuting := True;
c._FDataSet.SQL.Text := '';
c._FDataSet.ParamCheck := False;
c._FDataSet.Params.Clear;
for i := Low(ds) to High(ds) do begin
ds[i]._DoBeforeOpenCursor;
if ds[i].CursorType <> ctDefaultResultSet then
DatabaseError(SUnallowableCursorType, ds[i]);
c._FDataSet.SQL.Add(ds[i].FinalSQL); // finalsql insted of simple sql.text
for p := 0 to ds[i].Params.Count - 1 do
c._FDataSet.Params.Add.Assign(ds[i].Params[p]);
end;
try
if c._FDataSet._FIRecordSet <> nil then
c._FDataSet._FIRecordSet.SetProp(prBulkExecuting, True);
c._FDataSet.Execute;
Assert(c._FDataSet._FIRecordSet <> nil);
for i := Low(ds) to High(ds) do begin
c._FDataSet._FIRecordSet.AssignToNextResult(ds[i]._FIRecordSet);
OldAutoPrepare := ds[i].Options.AutoPrepare;
try
ds[i].Options.AutoPrepare := False;
ds[i].Open;
finally
ds[i].Options.AutoPrepare := OldAutoPrepare;
end;
end;
finally
c._FDataSet._FIRecordSet.Active := True;
c._FDataSet._CloseCursor;
end;
end;
Re: TMSConnection.OpenDatasets & macros
Thank you for the information. We will change this behavior in one of the next versions.