MySQL Storedprocedures
Moderators: gto, cipto_kh, EgonHugeist
MySQL Storedprocedures
Hi
I created a storedprocedure in MySQL 5.0.19 and if I test the procedure with my SQL manager i works fine but not from Delphi it tells me the parameters is not found
I can'd find anywhere to see what is needed in a stedprocedure
This is the code
ZStoredProc.StoredProcName := 'Newdocument';
ZStoredProc.ParamByName('CaseRef').AsString := Edit1.Text;
ZStoredProc.ParamByName('UserID').AsInteger := 12;
ZStoredProc.ExecProc;
can someone please assist me
Thanx
Kite
I created a storedprocedure in MySQL 5.0.19 and if I test the procedure with my SQL manager i works fine but not from Delphi it tells me the parameters is not found
I can'd find anywhere to see what is needed in a stedprocedure
This is the code
ZStoredProc.StoredProcName := 'Newdocument';
ZStoredProc.ParamByName('CaseRef').AsString := Edit1.Text;
ZStoredProc.ParamByName('UserID').AsInteger := 12;
ZStoredProc.ExecProc;
can someone please assist me
Thanx
Kite
ZStoredProc is not implemented for mysql. If you wish to call stored procedure try to ZSQLProcessor.
[syntax="delphi"]
ZSQLProcessor1.Script.text:= 'Call Newdocument( :CaseRef , :UserID )';
ZSQLProcessor1.ParamCheck:=true;
ZSQLProcessor1.ParamByName('CaseRef').AsString := Edit1.Text;
ZSQLProcessor1.ParamByName('UserID').AsInteger := 12;
ZSQLProcessor1.Execute;
[/syntax]
[syntax="delphi"]
ZSQLProcessor1.Script.text:= 'Call Newdocument( :CaseRef , :UserID )';
ZSQLProcessor1.ParamCheck:=true;
ZSQLProcessor1.ParamByName('CaseRef').AsString := Edit1.Text;
ZSQLProcessor1.ParamByName('UserID').AsInteger := 12;
ZSQLProcessor1.Execute;
[/syntax]
Dorin Hongu
Procedures do not return values if I'm not wrong - functions do that.
To return a value from the function follow this example (syntax is aproximative):
Now just call it in the Delphi application:
The result set should be 15 and zou read it like this>
Hope it's clear and it helps you.
To return a value from the function follow this example (syntax is aproximative):
Code: Select all
DELIMITER $$
DROP FUNCTION IF EXISTS `test`.`USR_MULTIPLY` $$
CREATE FUNCTION `USR_MULTIPLY`(X Integer, Y Integer) RETURNS Integer
DETERMINISTIC
COMMENT 'Just a test...'
Begin
Declare RESULT Integer Default 0;
Set RESULT = X * Y;
Return RESULT;
End $$
DELIMITER ;
Code: Select all
Query.SQL.Text := 'Select USR_MULTIPLY(5,3)';
Query.Open;
Code: Select all
MyResult := Query.Fields[0].AsInteger;
Hope it's clear and it helps you.
zippo
Functions returns only scalar data types, but procedures returns data through OUT or INOUT parameters or returns datasets like SELECT operator, but i can not use 'call spMySuperSP(param);' in TZQuery, cause mysqlerror "procedure blablabla can't return dataset in given context"Procedures do not return values if I'm not wrong - functions do that.
example
Code: Select all
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`spMySuperSP`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `spMySuperSP`()
READS SQL DATA
BEGIN
select * from b;
END$$
DELIMITER ;
functions via select, procedures via call
like i wrote above: call spMySuperSP(param);
I'm writing megasecure app with all its logic on server side, so my app will communicate with db hrough sp calls not via select/insert/update an so on.
That's why i'm asking about full sp support, not only one way via ZScriptProcessor
like i wrote above: call spMySuperSP(param);
I'm writing megasecure app with all its logic on server side, so my app will communicate with db hrough sp calls not via select/insert/update an so on.
That's why i'm asking about full sp support, not only one way via ZScriptProcessor