Simple utility sub to call a Sybase stored procedure and getting the output parameter values.
Call like this:
my $raOutput = executeProcedure($oDbConfig, q{
declare @default_type int, @default_language_id char(2)
exec get_config @default_type output, @default_language_id out
+put
}) or die("Could not exec SP\n");
/J
=head2 executeProcedure($oDbh, $sql)
Execute the SP defined by $sql in $oDbh, and return an
array ref with the output parameters.
Return undef on failure. Die on db failure.
=cut
sub executeProcedure { my $self = shift; my $pkg = ref($self);
my ($oDbh, $sql) = @_;
my $oSth = $oDbh->prepare($sql) or die("Could not prepare SQL ($sq
+l)\n");
$oSth->execute() or die("Could not execute SQL ($sql)\n");
my $raRowOutput = undef;
do {
while(my $raRow = $oSth->fetch()) {
if($oSth->{syb_result_type} == 4042) { # it's a PARAM resu
+lt
$raRowOutput = $raRow;
last;
}
}
} while($oSth->{syb_more_results});
return($raRowOutput);
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.