Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Multiple records fetches issue using DBD::ODBC in Perl

by Marshall (Canon)
on Apr 18, 2020 at 09:09 UTC ( #11115721=note: print w/replies, xml ) Need Help??


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". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2022-05-25 15:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (90 votes). Check out past polls.

    Notices?