simple query with params

Forum related to Firebird

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
Josef Koller
Junior Boarder
Junior Boarder
Posts: 26
Joined: 04.09.2005, 14:46

simple query with params

Post by Josef Koller »

Hello,

I would like to start the following SQL-statement:

dmlager.zquery2.SQL.Clear;
dmlager.ZQuery2.SQL.Add('select * from "T_BUCHUNG" where "LAGERORT" = :vrLager order by :vrsort');
dmlager.ZQuery2.Params[0].AsString:=vrLager;
dmlager.zquery2.params[1].asstring:=vrsort;
dmlager.ZQuery2.Open;

but I get the following error message:

An error was found in the application program input parameters for the sql statement. The sql: select * from "T_BUCHUNG" where "LAGERORT" = ? order by ?;' . .....

vrLager has the value: for example KOLL and vrsort BUCHUNGSDATUM.

Only with the following statement I got a result:

dmlager.zquery2.SQL.Clear;
dmlager.ZQuery2.SQL.Add('select * from "T_BUCHUNG" where "LAGERORT" = ' +qoutedstr(vrLager)+' order by '+quotedstr(vrsort)+'');
//dmlager.ZQuery2.Params[0].AsString:=vrLager;
//dmlager.zquery2.params[1].asstring:=vrsort;
dmlager.ZQuery2.Open;

That's not normal, I think. What's wrong in my first statement?

Many thanks and best regards

Josef
pol
Senior Boarder
Senior Boarder
Posts: 91
Joined: 13.10.2005, 08:19

Post by pol »

Hello Josef,

You want to pass the column name for your "order by" as a bind variable? I don't think that this is possible.

Best regards,
Rüdiger
designshouse
Fresh Boarder
Fresh Boarder
Posts: 20
Joined: 21.11.2005, 10:13
Location: Pieštany
Contact:

Post by designshouse »

dmlager.zquery2.SQL.Clear;
dmlager.ZQuery2.SQL.Add('select * from "T_BUCHUNG" where "LAGERORT" = :vrLager order by :vrsort');
dmlager.ZQuery2.ParamByName('vrLarger').AsString:=vrLager;
dmlager.zquery2.ParamByName('vrsort').AsString:=vrsort;
dmlager.ZQuery2.Open;
Josef Koller
Junior Boarder
Junior Boarder
Posts: 26
Joined: 04.09.2005, 14:46

Post by Josef Koller »

Hi,

thanks for answer, but with your statement I get the same error.
The problem is the paramter for the field in the order statement BUCHUNGSDATUM.

At first I thougt that the ' ' are the problem. but I found in the JEDI-Lib a function StrTrimQuotes but I get the errer, too.

I find no way to declare a fieldname with a parameter statement. Only

sql. add('Select * from ..........order by '+:vrSort) works.

Any other ideas?

Kind regards

Josef
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post by zippo »

Quick and dirty: Insert the parameters diractly into SQL, example:

Code: Select all

dmlager.zquery2.SQL.Clear;
dmlager.ZQuery2.SQL.Add('select * from "T_BUCHUNG" where "LAGERORT" = '+LagerVar+' order by '+VSortVar);
dmlager.ZQuery2.Open;
Where LagerVar and VSortVar is your variable. If needed, apply IntToStr, FloatToStr,.. etc.
Byungho
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 04.01.2006, 12:36
Contact:

Post by Byungho »

An error was found in the application program input parameters for the sql statement. The sql: select * from "T_BUCHUNG" where "LAGERORT" = ? order by ?;' . .....
I got a same error, too! Bellow code does not work correctly!!

Code: Select all

ZQuery1.ParamByName('USERID').AsString := 'test';
My app works on D7 Enterprise and Zeos 6.1.5 with path2

regards
byungho
pol
Senior Boarder
Senior Boarder
Posts: 91
Joined: 13.10.2005, 08:19

Post by pol »

@Byungho:
What is your SQL?

Regards,
Rüdiger
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post by zippo »

I always construct the entire SQL statement by myself and works well... I had similar problems with params in the past, so I switched to "manual"...
Byungho
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 04.01.2006, 12:36
Contact:

Post by Byungho »

pol wrote:@Byungho:
What is your SQL?

Regards,
Rüdiger
I use embedded firebird-1.5 , D7 and Zeos 6.1.5!! Windows XP SP2
pol
Senior Boarder
Senior Boarder
Posts: 91
Joined: 13.10.2005, 08:19

Post by pol »

No, I mean, what is ZQuery1.SQL?
Post Reply