in reply to Re: Saving SQL PRINT statements - MSSQL, SQL Server, DBD::ODBC.
in thread Saving SQL PRINT statements - MSSQL, SQL Server, DBD::ODBC.

Thank you for the response!

I have actually used the code in the DBD::ODBC docs. That is what you see modified above. I wrapped all of the error trapping code in a subroutine. That was not included. The while on the end handles the PRINT statements if/when the occur.

I can print to console from within that subroutine. I can make that subroutine return its output as a variable. What I don't understand is how to take that variable and place it into the same data structure as the sql results in the order it returned from the database.

Thanks again for the response.

  • Comment on Re^2: Saving SQL PRINT statements - MSSQL, SQL Server, DBD::ODBC.

Replies are listed 'Best First'.
Re^3: Saving SQL PRINT statements - MSSQL, SQL Server, DBD::ODBC.
by runrig (Abbot) on Sep 22, 2007 at 17:12 UTC
    sorry, misunderstood the question due to lack of formatting. Wrap your code in <code></code> tags. Your error handler should be in the same scope as your while loop. A rough outline is:
    { my @output; local $dbh->{odbc_err_handler} = sub { .... push @output, $print_statement; ... }; while ($sth->{odbc_more_results}) { while (my $data = $sth->fetchrow_array()) { ... push @output, (join("|", @$data) . "\n"); } } }