http://qs321.pair.com?node_id=11115721


in reply to Multiple records fetches issue using DBD::ODBC in Perl

I don't know anything about using stored procedures.
However when you execute a prepared sql statement handle, you have to assign that result to a variable.
Does this help?
use strict; use DBI; use DBD::ODBC; use Data::Dump qw(pp); print "Trying to connect\n"; my $server_name = "XXXXXXXX"; my $server_port = 'NNNN'; my $database_name = 'XXXXX'; my $database_user = 'XX'; my $database_pass = 'XXXXX'; my $dbh = DBI->connect("dbi:ODBC:DSN=sql_test", $database_user, $datab +ase_pass) || die "Couldn't open database: $DBI::errstr\n"; my $sql = $dbh->prepare("Exec sp_listUsers '25329601','1'") or die "ba +d prepare $!"; my $results = $sql->execute(); pp $results;

Replies are listed 'Best First'.
Re^2: Multiple records fetches issue using DBD::ODBC in Perl
by maria80e (Novice) on Apr 20, 2020 at 04:57 UTC

    If I executed the above program I got the $results "-1". So I enabled set DBI TRACE=1. Please find the below TRACE log.

      I am a bit flummoxed as to how you get -1 as the result. What does this do?
      my $results = $sql->execute() or die("EXECUTE FAILED $!"); my $array_ref = $results->fetchall_arrayref(); pp $array_ref;
        I am a bit flummoxed as to how you get -1 as the result.

        -1 is a legal return value for $sth->execute(). Quoting the DBI documentation:

        For a non-SELECT statement, execute returns the number of rows affected, if known. If no rows were affected, then execute returns "0E0", which Perl will treat as 0 but will regard as true. Note that it is not an error for no rows to be affected by a statement. If the number of rows affected is not known, then execute returns -1.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)