igongora has asked for the wisdom of the Perl Monks concerning the following question:

I am working on a perl script wich will call a SQL server stored procedure. This store procedure expects 2 parameter registration number and a password.

So far I am using freetds, however when I call the stored procedure

$action = $dbh->prepare("IBW_WebAuth $reg_num,$passwd") ; $action->execute ; $rows = $action->rows ; print "rows is $rows\n";

the print statement prints "rows is -1" what am I doing wrong? what does -1 mean??

Replies are listed 'Best First'.
Re: Execute stored procedure with freetd
by Belgarion (Chaplain) on May 19, 2004 at 18:22 UTC

    rows() returns the number of rows processed (if available, else -1.) That's taken from the DBI module's documentation. You likely want to use one of the fetchrow_* functions to actually retrieve any information the IBW_WebAuth procedure may return.

Re: Execute stored procedure with freetd
by injunjoel (Priest) on May 19, 2004 at 18:26 UTC
    Some information on DBI and Stored Procedures
    might help...
    Update
    Quote from the DBI docs regarding $sth->rows();
    $rv = $sth->rows;
    Returns the number of rows affected by the last row affecting command, or -1 if the number of rows is not known or not available.
    ...(clipped info)...
    For SELECT statements, it is generally not possible to know how many rows will be returned except by fetching them all. Some drivers will return the number of rows the application has fetched so far, but others may return -1 until all rows have been fetched. So use of the rows method or $DBI::rows with SELECT statements is not recommended.
    -injunjoel
Re: Execute stored procedure with freetd
by Fletch (Bishop) on May 19, 2004 at 18:24 UTC

    Probably means your DBD isn't returning a number of rows. See perldoc DBI where it discusses the rows() method and it explains when it may return -1.

Re: Execute stored procedure with freetd
by punkish (Priest) on May 19, 2004 at 19:23 UTC
    Don't know if this will help you or not, but afaik, a stored proc is called with an exec statement. I would do it like so --
    $action = $dbh->prepare("EXEC IBW_WebAuth $reg_num,$passwd") ; $action->execute; $rows = $action->rows ; $action->finish; print "rows is $rows\n";
    Other than that, others' notes above about -1 might also be helpful.