Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using @variables:= in delphi query does not work

I have the following problem.

ZQuery1.SQL.Text:= 
  ' SELECT                                                  '+
  '   IF(q.rank2 = 1, @rank:= 1, @rank:= @rank + 1) AS rank '+
  '   ,q.* FROM (                                            '+
  '   SELECT groep.id - MinGroepId(groep.id) AS rank2       '+
  '     ,groep.otherfields                                  '+
  '   FROM groep                                            '+
  '   ORDER BY rank2 ) q;                                   ';
ZQuery.Open;

When I run this code I get an exception Incorrect token followed by ":" in ZQuery1.
How do I fix this? I need to use Delphi, because I cannot put this select in a MySQL procedure.
Zeos 6 does not support MySQL procedures that return a resultset.

P.S.
I'm using Delphi 2007 and MySQL 5.1 with ZEOS 6.6.6.
Although I'm pretty sure the versions don't matter.
I'm not willing to switch versions as I'm too far into the project.

like image 599
Johan Avatar asked Nov 28 '25 01:11

Johan


1 Answers

This can't be done, you can only parameterize the value. Best you can do is SQL.Text := StringReplace() but you lose the speed of preparing queries.

like image 108
Jan Doggen Avatar answered Nov 30 '25 18:11

Jan Doggen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!