OpenDataSets and BeforeOpen

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
brace
Posts: 213
Joined: Wed 14 Feb 2007 08:26

OpenDataSets and BeforeOpen

Post by brace » Tue 14 Jan 2014 17:26

I realized that I have problems with TMSQuery and OpenDataSets. if TMSQuery has some BeforeOpen code, such as PAramByNAme assignment the dataset returned by OpenDataSets is empty.

But if I remove the code from BeforeOpen and put it just before OpenDataSets it works.

Is this a known isssue? I use sdac 6.1.6

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: OpenDataSets and BeforeOpen

Post by AlexP » Wed 15 Jan 2014 15:53

Hello,

Such behavior is due to the fact that all SQL commands are "built" into one SQL query and run "simultaneously", that increases performance, and then all the retrieved ResulSets are copied to their DataSets. Now, at this, we don't call the BeforeOpen and BeforeExecute events, therefore parameters set in these methods are not set up and not transferred to the server. We will consider the possibility to modify this behaviour in one of the next versions.

brace
Posts: 213
Joined: Wed 14 Feb 2007 08:26

Re: OpenDataSets and BeforeOpen

Post by brace » Thu 16 Jan 2014 08:20

Thanks for the reply.

Anyway just to inform you i noticed that beforeopen is executed for datasets opened with opendatasets.

ParamByName is not working in BeforeOpen if OpenDataSets are used, but other code such this works:

Code: Select all

  // In BeforeOpen on a Dataset opened with OpenDatasets
  MSQwuery1.DeleteWhere;
  if MyCondition then
     MyQuery2.AddWhere(' FIELD ='+IntToStr(MyID))
     else
     MyQuery2.AddWhere(' FIELD < 3 ')
may be you want to consider this when you implement better support for berofreopen and befoerexecute as you mentioned.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: OpenDataSets and BeforeOpen

Post by AlexP » Thu 16 Jan 2014 12:52

Hello,

The BeforeOpen method is called on opening DataSet, which already contains the data retrieved by execution of the "full" SQL from all the DataSets specified in the OpenDataSets method . At this, there occurs opening of the local DataSet, i.e., parameters are filled in, SQL is modified, but commands are not transferred to the server.

brace
Posts: 213
Joined: Wed 14 Feb 2007 08:26

Re: OpenDataSets and BeforeOpen

Post by brace » Fri 17 Jan 2014 11:15

i wrote that because in your first reply you wrote:
we don't call the BeforeOpen and BeforeExecute events

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: OpenDataSets and BeforeOpen

Post by AlexP » Fri 17 Jan 2014 11:32

Hello,

It was intended, that the method are not called before sending commands to the server.

Post Reply