Unable to Override parameters of Query component at runtime

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Balaji
Posts: 20
Joined: Thu 05 Oct 2006 04:45

Unable to Override parameters of Query component at runtime

Post by Balaji » Tue 14 Nov 2006 16:03

Hi,

I am using licensed 3.80.0.32 version of SDAC components.

I am facing the following problem with SDAC components in my Project.

My Project has a Query component, UpdateSQL and a DataSource. UpdateSQL handles the insert, delete and Update operations of a table (Sorry I cannot use SQLInsert etc of Query Compoenet). This Update SQL is attached to the UpdateObject property of Query component and for the DataSource Querycomponent is attached.

During certain cases of Inserting Data into the Data base, i am overriding the values of Query component and passing new values to the "insert" statement of UpdateSQL in the OnUpdateRecord event of Query component and then i am doing an ApplyUpdates of the Query component.

I still found that UpdateSQL is picking the values of Query component rather than the values passed at runtime.

I already read a similar problem posted in the Forums on Nov9 by Mr.Japhar and my problem is very much similar to his.
I also looked into the solution provided by Corelab team. I cannot use the Solution as i have to use CachedUpdates. Also i have gone through the demos and i couldnt find any reference to the problem i faced.

Please provide me a solution, also please correct if i am worng or please inform me whether there is a bug in SDAC components in this case.

Thanks in Advance

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Wed 15 Nov 2006 14:29

It seems that you need TCustomDADataSet.BeforeUpdateExecute instead of TMemDataSet.OnUpdateRecord.

Balaji
Posts: 20
Joined: Thu 05 Oct 2006 04:45

Unable to Override parameters of Query component at runtime

Post by Balaji » Thu 16 Nov 2006 13:34

I think, you havent got my question:
Let me explain again in a simpler way, with simple code:


I have a small delphi project in which there is a single form and a Unit of it.
On the Form i have placed a Connection component, Two Query components( All SDAC Components) a Data Source and a button.

For Connection component i have set the connection string required.
For Query1 following are the properties set:
MasterSource = DataSource1
SQL = 'insert into employee(inso,categ,play,tet,rtuy)
values (:inso,:categ,:play,:tet,:rtuy)'

For DataSource DataSet Property is Set to Query2.

For Query2 following Properties were set:
SQL = select inso,categ,play,tet,rtuy from employee where inso = 'TEST', categ = 'HAI', play = 'CRIC'
( Above Query returns only one row in my defined database as insco,categ,play column combination is defined as Unique)



Now the Source Code written in my unit is as below:

In the FormCreate Event:

MedicConnection1.Connected := True;

In the ButtonClick Event:

Query2.Open;
Query1.ParamByName('inso').AsString := '11';
Query1.ParamByName('categ').AsString := 'AAA';
Query1.ParamByName('play').AsString := 'STND';
Query1.Execute;

Now when i execute the above code i am getting error in the buttonclick event when Execute line is encountered, there is an error saying that unique
Key is voilated.

This is because the values passed to insert statement are TEST,HAI and CRIC but not the values in the button click event.

Please provide me a proper answer, whether there any problem in my approach. Also please tell me whether this will work at all or not with SDAC ??

Other information required for you:
DataBase : SQLSERVER 2005
Delphi Version 7
SDAC Version : 3.80 ( Unlimited Developer liecensed Version)

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Fri 17 Nov 2006 12:03

The master/detail relationship is meant to be used with the SELECT statement.
We can't guarantee that the behaviour would be as you suppose when the INSERT, UPDATE or DELETE statement is used in the Master/detail relationship.

Balaji
Posts: 20
Joined: Thu 05 Oct 2006 04:45

Post by Balaji » Fri 17 Nov 2006 12:29

Can You Suggest me any Alternative Way of Achieving the Same with SDAC components...

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Mon 20 Nov 2006 15:02

Remove reference to the master data source from Query1 component:

Code: Select all

Query1.MasterSource := nil;

Balaji
Posts: 20
Joined: Thu 05 Oct 2006 04:45

Post by Balaji » Wed 22 Nov 2006 05:52

Sorry, i already have this solution..and it will not work at all for me...

I feel this as a limitation of SDAC of components...because there so many other DataAccess components which are supporting the same.

Is there any document which will help me to understand, which property is "meant" for what purpose apart from the documention of SDAC?

This is very much needed for me as it will help me a lot in using these components.

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Wed 22 Nov 2006 13:54

We believe that using master/detail with non-SELECT statements is a misleading architecture design.
If you briefly formulate your goals, maybe we could suggest you a workaround scheme.

Post Reply