views:

43

answers:

2

Does DBD::mysql implement the bind_param_inout method? I am getting the following error messages when trying it out:

DBD::mysql::st bind_param_inout failed: Output parameters not implemented [for Statement "call spCreateTransactionRecord(?, ?)" with ParamValues: 0=Null!, 1=Null!] at ./db.pl line 23

My code:

#!/usr/bin/perl

use strict;
use warnings;
use DBI;
use DBI qw(:sql_types);
use Data::Dumper;

my ($dbh, $dsn, $sth, $sql);
my ($RecID, TypeID);
my ($user, $pass) = '';

# Open DB connection
$dsn = "dbi:mysql:database=mp;mysql_read_default_file=$ENV{HOME}/.my.cnf";
$dbh = DBI->connect($dsn, $user, $pass, 
             {RaiseError=>1, AutoCommit=>0, ShowErrorStatement=>1}) 
            || die "DB open error: $DBI::errstr";

# Call stored procedure
$sql = "call spCreateTransactionRecord(?, ?)";
$sth = $dbh->prepare($sql);
$sth->bind_param_inout(2, \$p_RecID, 11, {TYPE=>SQL_INTEGER});
$sth->execute($p_TypeID) || print $sth->errstr;

# Disconnects
$dbh->commit();
$dbh->disconnect;

The stored procedures is declared as:

CREATE PROCEDURE spCreateTransactionRecord(IN p_TypeID INTEGER, OUT p_RecID INTEGER)

+2  A: 

It is a known bug with "Verified" status, meaning it never got addressed.

http://bugs.mysql.com/bug.php?id=23554

That bug reports also contains a possible workaround.

A separate confirmation that the issue is still not addressed is that the source code for the current (4.017) version still has the error:

if (is_inout)
{
   do_error(sth, JW_ERR_NOT_IMPLEMENTED, "Output parameters not implemented", NULL);
   return FALSE;
}
DVK
Thanks. That's what I was afraid of. Strange that they haven't fixed this bug yet, considering it's been reported in 2006.
emx
+2  A: 

The new code with a workaround:

# Call stored procedure
$sql = "call spCreateTransactionRecord($p_TypeID, \@rtnVal)";
$dbh->do($sql);
$p_RecID = $dbh->selectrow_array('SELECT @rtnVal');
print "Received RecID = $p_RecID\n";

Not as proper (two database calls instead of one) but does the job.

emx