Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 22nd, 2005, 08:47 AM
Adam Bukla
Guest
 
Posts: n/a
Default Problem with API (libpq) - detailed error codes

Hi!

I started programming PostgreSQL database with libpq API (client
side). It looks very easy, but unexpected I found problem, which I
cannot solve myself.
If function PQexec fails, I can get error code using PQresultStatus.
But returned codes are very generally and do not specify what really
happen. I can get detailed error description using PQerrorMessage
function, but I need detailed error code (number).

For instance, if I create table, I would like to know, that operation
failed because:
- table already exist
- sql syntax error
- invalid columnt type
and so on.

I searched documents about libpq API and even header file
'internal/libpq-int.h' but I didn't found any interesting.

I would be very gracefully for any hint.

Best regards,
Adam Bukla



  #2  
Old November 22nd, 2005, 08:48 AM
ljb
Guest
 
Posts: n/a
Default Re: Problem with API (libpq) - detailed error codes

Adam.Bukla@interia.pl wrote:[color=blue]
>...
>
> If function PQexec fails, I can get error code using PQresultStatus.
> But returned codes are very generally and do not specify what really
> happen. I can get detailed error description using PQerrorMessage
> function, but I need detailed error code (number).
>
> For instance, if I create table, I would like to know, that operation
> failed because:
> - table already exist
> - sql syntax error
> - invalid columnt type
> and so on.
>
> I searched documents about libpq API and even header file
> 'internal/libpq-int.h' but I didn't found any interesting.
>
> I would be very gracefully for any hint.[/color]

Appendix A of the PostgreSQL 7.4.1 Reference Manual has a list of error
codes (5 digit numbers) and their meanings. You get at the error code
with PQresultErrorField(result, PG_DIAG_SQLSTATE).
  #3  
Old November 22nd, 2005, 08:48 AM
Tom Lane
Guest
 
Posts: n/a
Default Re: Problem with API (libpq) - detailed error codes

Adam.Bukla@interia.pl (Adam Bukla) writes:[color=blue]
> If function PQexec fails, I can get error code using PQresultStatus.
> But returned codes are very generally and do not specify what really
> happen. I can get detailed error description using PQerrorMessage
> function, but I need detailed error code (number).[/color]

Beginning in Postgres 7.4, there are standard SQLSTATE error codes
available (see PQresultErrorField), but older releases do not have them.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

  #4  
Old November 22nd, 2005, 08:49 AM
Adam Bukla
Guest
 
Posts: n/a
Default Re: Problem with API (libpq) - detailed error codes

Hi!

Thanks ljb and Tom Lane - it's exactly what I wanted.
I read documentation to 7.3 so I couldn't find PQresultErrorField function.
I'm suprised, that such necessary functionality exist only in 7.4 version.

Thanks once again,
Adam Bukla
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.