DBD::Pg errstr method doesn't return full error messages

From: Vivek Khera <khera(at)kcilink(dot)com>
To: E(dot)Mergl(at)bawue(dot)de
Cc: pgsql-general(at)postgresql(dot)org
Subject: DBD::Pg errstr method doesn't return full error messages
Date: 2001-05-03 19:24:31
Message-ID: 15089.45167.298471.377749@onceler.kciLink.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Hi, I'm using DBD::Pg version 0.98 with Postgres 7.1. I'm noticing
that quite often on an error, the $dbh->errstr method doesn't return
the full error. For example, if I have a table with a unique key
constraint:

CREATE TABLE urls (
url_id SERIAL PRIMARY KEY,
msg_id integer NOT NULL REFERENCES msg_info(msg_id),
url_link varchar(255) NOT NULL default ''
);

and I do this insert:

INSERT INTO urls (msg_id,url_link) VALUES (9,'http://www.kcilink.com/');

the second time I insert it, I get this on the psql command line:

ERROR: Cannot insert a duplicate key into unique index urls_id_link

However, if I use a perl module to do it, like this:

my $sth = $dbh->prepare('INSERT INTO urls (msg_id,url_link) VALUES (?,?)');
if ($sth and $sth->execute($msgid,$url)) {
($urlid) = $dbh->selectrow_array("SELECT currval('urls_url_id_seq')");
} else {
print $dbh->errstr(),"\n";
}

where $msgid and $url are the same values above, I get this output:

ERROR: Cannot i

This makes it a bit difficult to distinguish between a hard error and
simply a duplicate insert error, which I can handle in this app.

Also, at other times, I get just "7" as the error message rather than
the full message, making error reporting just a bit confusing. ;-)

Do you know of any issues with $dbh->errstr that could be causing
this? Any workarounds I might try?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joel Burton 2001-05-03 19:49:59 Cygwin PostgreSQL seems to work fine
Previous Message Bruce Momjian 2001-05-03 19:13:51 Re: ODBC 3.0 functions (UCASE, LCASE, etc.)

Browse pgsql-hackers by date

  From Date Subject
Next Message Ryan Mahoney 2001-05-03 20:07:42 Extrordinarily Poor Performance....
Previous Message Bruce Momjian 2001-05-03 19:21:51 Re: Found an example prooving bug