dbTalk Databases Forums  

HELP: FUNCTION and PROCEDURE best practices....

comp.databases.mysql comp.databases.mysql


Discuss HELP: FUNCTION and PROCEDURE best practices.... in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
daniel@mfaconsulting.com
 
Posts: n/a

Default HELP: FUNCTION and PROCEDURE best practices.... - 09-26-2006 , 01:11 AM






Hi All,

Got a best practices question....

I often have to write PROCEDURES that return a value (because it needs
to have a transaction in it)...and I can't do that in a FUNCTION.

eg

CREATE PROCEDURE `sp_test01`()
BEGIN

START TRANSACTION;

-- Do some insert

COMMIT;

SELECT 1;

END$$

This makes it very easy to get a return value from the CALL sp_test01()
from, for example, C#....set it up.....ExecuteScalar.

However, it doesn't allow me to call this and get a return value from
within another PROCEDURE.

eg.

CALL sp_test01() INTO var_X;

now I know I can use an OUT parameter for the procedure, but coding for
that in C# is a pain. Most specifically its that in order to get the
OUT parameter ALL the parameters HAVE to be defined EXACTLY as they are
in the stored procedure.

So is there another way I can do this?

Regards

D.


Reply With Quote
  #2  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: HELP: FUNCTION and PROCEDURE best practices.... - 09-26-2006 , 05:59 AM






daniel (AT) mfaconsulting (DOT) com wrote:
Quote:
Hi All,

Got a best practices question....

I often have to write PROCEDURES that return a value (because it needs
to have a transaction in it)...and I can't do that in a FUNCTION.

eg

CREATE PROCEDURE `sp_test01`()
BEGIN

START TRANSACTION;

-- Do some insert

COMMIT;

SELECT 1;

END$$

This makes it very easy to get a return value from the CALL sp_test01()
from, for example, C#....set it up.....ExecuteScalar.

However, it doesn't allow me to call this and get a return value from
within another PROCEDURE.

eg.

CALL sp_test01() INTO var_X;

now I know I can use an OUT parameter for the procedure, but coding for
that in C# is a pain. Most specifically its that in order to get the
OUT parameter ALL the parameters HAVE to be defined EXACTLY as they are
in the stored procedure.

So is there another way I can do this?

Regards

D.

Standard SQL indicates you must specify the IN and OUT parameters. You
may think it's a pain - but that's how it works.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.