How to pass argument to a stored procedure

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
marc_3
Posts: 6
Joined: Thu 10 Mar 2016 11:19

How to pass argument to a stored procedure

Post by marc_3 » Fri 18 Mar 2016 10:52

Hello,
I try to use TUniStoredProc this way :

Code: Select all

   sql_StoredProc         :  TUniStoredProc;
   sql_StoredProc.StoredProcName := 'is_leg_in_database';

   sql_StoredProc.ParamByName('given_Arp_dep').AsString   := 'AAL';  // hier that dosen't work
   sql_StoredProc.Execute;
But I can't pass an argument to the procedure : is_leg_in_database

I have an error message, so that the parameter : given_Arp_dep was not found

Hier is the stored procedure from my mariaDB database, it does what I need actually

Code: Select all

DROP PROCEDURE IF EXISTS is_leg_in_database;
DELIMITER $$
CREATE PROCEDURE is_leg_in_database(IN given_Arp_dep VARCHAR(3), IN given_Arp_arr VARCHAR(3), IN given_time_dep INT, OUT nof_leg INT)
  LANGUAGE SQL 
BEGIN
SELECT ( SELECT   COUNT(*) 
FROM     TW_LEG where     DEP_ARP_CD  = given_Arp_dep
                      and ARR_ARP_CD  = 'CPH'   // for test only 
                      and S_TIME_DEP  = 620
                      and S_TIME_ARR  = 705
                      and DAY_OF_WEEK = 4) INTO nof_leg; 	
END;
$$
DELIMITER ;
I have done a first try with no argument and I had the right answer so it should work.

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: How to pass argument to a stored procedure

Post by FCS » Fri 18 Mar 2016 11:03

Hello,

Try

Code: Select all

   sql_StoredProc         :  TUniStoredProc;
   sql_StoredProc.StoredProcName := 'is_leg_in_database';

   sql_StoredProc.PrepareSQL;  // add this line here

   sql_StoredProc.ParamByName('given_Arp_dep').AsString   := 'AAL';  // hier that dosen't work
   sql_StoredProc.Execute;
Regards
Michal

marc_3
Posts: 6
Joined: Thu 10 Mar 2016 11:19

Re: How to pass argument to a stored procedure

Post by marc_3 » Fri 18 Mar 2016 11:34

Many thanks, it works now

BG

marc_3

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: How to pass argument to a stored procedure

Post by ViktorV » Fri 18 Mar 2016 12:44

Michal provided a correct problem solution. The PrepareSQL method generates SQL statement for a stored procedure execution and describes stored procedure parameters. See more details about this method in the UniDAC help: https://www.devart.com/unidac/docs/inde ... olean).htm

Post Reply