Handling SQL errors using libpq
Handling SQL errors using libpq
От:
brennan@unix2.netaxs.com (William Brennan)
Дата:
I'm new to Postgresql, so please bear with me. After a call to libpq, I would like to be able to recognize specific SQL errors which might occur, beyond the simple results obtainable via a call to PQresultStatus(). I want more precision. For example, I have a table with a primary key. If I attempt to insert a new row with a duplicate key, PQresultStatus() rightly returns an error (PGRES_FATAL_ERROR). However my program has no way to distinguish from this blunt instrument whether it's a duplicate-key problem, or any of hundreds of other problems. How should my program recognize the duplicate-key error? And more generally, how to I reconize other anticipated SQL errors? Thanks for your help! -- Bill
Re: Handling SQL errors using libpq
От:
Oliver Elphick <olly@lfix.co.uk>
Дата:
On Thu, 2002-11-21 at 18:37, William Brennan wrote: > After a call to libpq, I would like to be able to recognize specific > SQL errors which might occur, beyond the simple results obtainable > via a call to PQresultStatus(). I want more precision. You can get the actual error message with PQresultErrorMessage() -- Oliver Elphick LFIX Limited