Page 1 of 1

How to get value from stored procedure,zeos+mysql5+delphi7 ?

Posted: 16.01.2007, 11:58
by amicom
Hi,

I use Delphi 7 + Mysql 5.0.22 + zeoslib 6.6.0 beta and have stored procedure :

CREATE DEFINER=`kasa`@`%` PROCEDURE `suma`(racun_br INT,OUT vrijednost FLOAT)
BEGIN
SELECT SUM(racuni.CijenabezPDV) INTO vrijednost from kasa.racuni where racuni.BrRacuna=racun_br;
END

in shell procedure works fine :

mysql> call suma(5,@izlaz);
Query OK, 0 rows affected (0.02 sec)

mysql> select @izlaz;
+-----------------+
| @izlaz |
+-----------------+
| 3.4188034534454 |
+-----------------+
1 row in set (0.00 sec)


how to get value from mysql variable @izlaz in delphi ?

something like not work correctly ( I get message "Can not open a Resultset") :

procedure TForm1.Button1Click(Sender: TObject);
var rezultat:double;
begin
zquery1.Close;
zquery1.SQL.Clear;
zquery1.SQL.text:='call kasa.suma(5,@izlaz);';
zquery1.Open;
rezultat:=zquery1.Params[0].Asfloat;
end;

Posted: 16.01.2007, 15:27
by dhongu
[syntax="delphi"]
procedure TForm1.Button1Click(Sender: TObject);
var rezultat:double;
begin
zquery1.Active:=false;
zquery1.SQL.text:='call kasa.suma(5,@izlaz);';
zquery1.ExecSQL;

zquery1.SQL.text:='select @izlaz;';
zquery1.open;
rezultat:=zquery1.Fields[0].Asfloat;
end;
[/syntax]

Posted: 16.01.2007, 15:57
by amicom
Thanks !