Link to home
Start Free TrialLog in
Avatar of prgeorge3383
prgeorge3383

asked on

Mysql and perl DBI

I am trying to execute the below code, I am getting the error below

use DBI;
use Time::Local;
use File::Copy;
use Date::Calc qw(:all  );
use Text::Wrap;
use IniFile;
use strict;
use Cwd;

my $db_host = "dlssql01";
my $db_name = "invoice_tmp";
my $db_name_c = "DBI:mysql:" . "$db_name;host=$db_host;mysql_multi_results=1";
my $dbh = DBI->connect( $db_name_c,"x", "y" )   || die "Database connection not made: $DBI::errstr";
my $sproc = $dbh->prepare("CALL invoice_tmp.sp_get_subscriptions(256)");
$sproc->execute      || warn "Execute failed with following error $DBI::errstr";


D:\CLEC\v5\Invoice>perl  invdriver.pl
DBD::mysql::st execute failed: PROCEDURE invoice_tmp.sp_get_subscriptions can't
return a result set in the given context at invdriver.pl line 15.
Execute failed with following error PROCEDURE invoice_tmp.sp_get_subscriptions c
an't return a result set in the given context at invdriver.pl line 15.
Driver has not implemented the disconnect_all method. at D:/Perl/site/lib/DBI.pm
 line 552
END failed--call queue aborted.


DELIMITER $$

DROP PROCEDURE IF EXISTS `invoice_tmp`.`sp_get_subscriptions`$$

CREATE PROCEDURE `sp_get_subscriptions`(p_invoiceid bigint)
BEGIN
SELECT * FROM invoice.invoice_subscription where InvoiceId = p_invoiceid ;
END$$

DELIMITER ;
Avatar of mjcoyne
mjcoyne

Simplify it a bit, and see what happens:

#!/usr/bin/perl -w
use strict;

use DBI;
use Time::Local;
use File::Copy;
use Date::Calc qw(:all  );
use Text::Wrap;
use IniFile;
use strict;
use Cwd;

my $dbh = DBI->connect("DBI:mysql:database=invoice_tmp;host=dlssql01",
                       "user", "user's password", {'RaiseError' => 1})
                        || die "Database connection not made: $DBI::errstr";
my $sproc = $dbh->prepare("CALL invoice_tmp.sp_get_subscriptions(256)");
$sproc->execute      || warn "Execute failed with following error $DBI::errstr";

Avatar of prgeorge3383

ASKER

thanks ....
tried it....
got the same error
did not help
I don't know a lot about this, but I think avoiding the "can't return a result set in the given context" error when calling a stored procedure, you have to set the CLIENT_MULTI_STATEMENTS flag, which automatically enables the CLIENT_MULTI_RESULTS flag.

Or you could forego the stored procedure, and move its functionality into the Perl script...
ASKER CERTIFIED SOLUTION
Avatar of mjcoyne
mjcoyne

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial