Sql Error

Abigail abigail at abigail.be
Thu May 15 16:32:47 BST 2008


On Thu, May 15, 2008 at 04:15:06PM +0100, Hemant Verma wrote:
> 
> Hi,
> 
> Can any body please let me know how I can print the error message
> associated with a query.
> 
> Following is the psuedo code for perl.
> 
> $query = "select * from table";
> 
> If I make any mistake in this query like
> 
> $query = "selects * from table";
> 
> $result = $db->sql($query);
> 
>  I used to print error as $db-error();
> 
> But it does not print any thing.
> 
> How can I print the error message associated with this query.

What I usually do is:

    local $dbh -> {AutoCommit} = 0;
    local $dbh -> {PrintError} = 0;
    local $dbh -> {RaiseError} = 1;

    my $r = eval {
        my $query = "...";
        ... database calls ...
        $dbh -> commit;
        1;
    };
    unless ($r) {
        my $error = $@;
        unless (eval {$dbh -> rollback; 1}) {
            die "Rollback afer '$error' failed: $@";
        }
        die $error;
    }




Abigail
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://london.pm.org/pipermail/london.pm/attachments/20080515/58272773/attachment.pgp


More information about the london.pm mailing list