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

Hello Monks,

Can't find anything about this so I'm hoping your collective awesomeness might be able to point me in the right direction.

My script runs an UPDATE statement against the database but I want to have the results of said UPDATE statement print to the screen (anywhere is fine actually as long as I can see them).

Any suggestions?

Replies are listed 'Best First'.
Re: Return results of UPDATE statement
by moritz (Cardinal) on Oct 12, 2009 at 11:55 UTC

    What do you mean by "results of said UPDATE statement"? Normally the result is either a success or a failure. If you set the PrintError option when connecting to DBI, you get automatically notified of errors. Or you can check $dbh->err<c/> and <c>print "Success\n" if there was no error.

    Perl 6 - links to (nearly) everything that is Perl 6.
      Sorry for not making that clear. When you run the update statement you get something like the following.

      Query OK, 1 row affected, 1 warning (0.01 sec)

      Thats actually from an INSERT statement but it's very similiar. I'm looking for a way to get that output either to a screen or file. The errstr dosen't have anything in it when I print it.

        This string is generated by the mysql command line client, and since you don't use it, you have to construct it yourself.

        I think you can obtain the number of affected rows as the return value of $dbh->execute (but please check the documentation first), the time difference is easily computed by invoking time before and after the query, use Time::HiRes get sub-second resolution.

        Perl 6 - links to (nearly) everything that is Perl 6.
        You can get the number of rows affected by the previous statement using
        $sth->rows();
        where $sth is the statement handle.