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

hi, I am executing a restore database (MS SQL Server 2005) from perl dbi. but restore stops after printing this message MicrosoftODBC SQL Server DriverSQL ServerProcessed 168 pages for database 'aks1', file 'DBA_Test' on file 1. (SQL-01000) if run the restore database from sqlcmd, i get following output Processed 17632 pages for database 'aks1', file 'DBA_Test_Kline' on file 1. Processed 2 pages for database 'aks1', file 'DBA_Test_Kline_log' on file 1. RESTORE DATABASE successfully processed 17634 pages in 15.656 seconds (9.226 MB/sec). how can i make my dbi to continue executing after getting informational messages. thanks AK
  • Comment on DBI continuing execution after a warning/informational message

Replies are listed 'Best First'.
Re: DBI continuing execution after a warning/informational message
by mje (Curate) on Jan 19, 2010 at 20:36 UTC
      thanks for the reply. Yes, i do use DBD::ODBC Your example shows using odbc_more_results while retrieving data.. (fetch)
      my code sniffet is here.
      $sql = qq{ RESTORE DATABASE ${dbname} FROM disk = '${filename}' ${recovery} , MOVE '$datadev_srcname' TO '$datadev_phyname' , MOVE '$logdev_srcname' TO '$logdev_phyname' ,replace }; } $sth->execute() || die "Restore failed with this error $DBI::errstr nu +m: $DBI:err state: $DBI::state\n" ;
      As you can see this is a single command to sql server and i am not sure how do i incorporate your suggestion?
      should i change my code to
      do{ $sth->execute() || die "Restore failed with this error $DBI::errstr nu +m: $DBI:err state: $DBI::state\n" ; }while ($sth->{odbc_more_results});
      I am confused...
      thanks

        Messages output via print in a procedure are only seen in the DBI error handler so if you want to capture them you need to set that up. There is an example in the 20SqlServer.t test where a procedure is created which prints.

        MS SQL Server, by default does not batch up results and the prints are deemed a result (of a sort). I think you need to call execute then loop whilst odbc_more_results is true.

        $s->execute; while($s->odbc_more_results) { # your error handler will catch prints }
        </code>
      i was able to make it work , based on your comment. i got error
      Can't locate object method "odbc_more_results" via package "DBI::st"
      when i used
      while($sth->odbc_more_results) { print "Restore outputs $DBI:errstr \n"; }
      googling, i got an option for prepare statement.
      my $sth = $db->prepare( $sql, { odbc_exec_direct => 1})
      this seems to keep the connection on (basically to use with temporary table creation on prepare statement, otherwise temp tables are unaccessable)
      thanks for your hint, which solved my problem.

        That was a typo on my part - it should have been:

        while($sth->{odbc_more_results}) { ; # }

        sorry

      thanks, now it works with odbc_more_results too.