Page 1 of 1

How to pass argument to a stored procedure

Posted: Fri 18 Mar 2016 10:52
by marc_3
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.

Re: How to pass argument to a stored procedure

Posted: Fri 18 Mar 2016 11:03
by FCS
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

Re: How to pass argument to a stored procedure

Posted: Fri 18 Mar 2016 11:34
by marc_3
Many thanks, it works now

BG

marc_3

Re: How to pass argument to a stored procedure

Posted: Fri 18 Mar 2016 12:44
by ViktorV
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