Dataset Fields which belong to a parameter

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
flyy
Posts: 17
Joined: Fri 18 Sep 2009 08:34

Dataset Fields which belong to a parameter

Post by flyy » Wed 09 Dec 2009 09:55

Hi all,

in a uniquery dataset, I'm writing a sql which has a parameter like that:

Select * From Table1 Where Field1 = :P_Field1

while I am inserting a new record, I want that "Field1" field has value of "P_Field1". how could i do that?

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Thu 10 Dec 2009 09:01

You can use the AfterInsert event to fill the value of Field1:

Code: Select all

UniQuery.FieldByName('Field1').Value := UniQuery.ParamByName('P_Field1').Value;
Note that UniDAC can fill Field1 automatically if you link your query to the master dataset.

flyy
Posts: 17
Joined: Fri 18 Sep 2009 08:34

Post by flyy » Thu 10 Dec 2009 21:57

i think i couldnt explain my needs. I know how to assign a value from a parameter to field. what i need is, in where clause of select statement, which parameter is assigned to which field.

there are more than one parameters in where clause for different fields and there are dynamicly created parameters in code. i have the parameters by using Uniquery.Params property but which parameter is assigned to which field.

to solve my problem i made same name for parameters and fields, like that

field1 = :field1

so OnNewRecord event, I wrote that code

Code: Select all

  for i := 0 to UniQuery.ParamCount - 1 do
  begin
      UniQuery.FieldByName(UniQuery.Params[i].Name).AsVariant := UniQuery.Params[i].Value;
    end;
  end;
is there a better way? Also this code is temporary solution, if there is a condition with "OR" this code will be wrong, for ex:

where
(field1 = :field1 Or field1 = :field1_1)

second parameter must be different and my code above will cause an error because there is no field named "field1_1". in this example for field1 field, must not have a default value in OnNewRecord event.

thanks for answer.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Mon 14 Dec 2009 08:43

There is no better way for copying values from parameters to fields. You need to create special logic in your procedure to handle OR conditions.

flyy
Posts: 17
Joined: Fri 18 Sep 2009 08:34

Post by flyy » Mon 14 Dec 2009 11:16

thanks for your help @plash

Post Reply