pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
libpq: how to get error code (not message)
3+ messages / 2 participants
[nested] [flat]

* libpq: how to get error code (not message)
@ 2004-12-02 03:11 X X <junkmbox@yahoo.com>
  2004-12-02 06:06 ` Re: libpq: how to get error code (not message) Michael Fuhr <mike@fuhr.org>
  0 siblings, 1 reply; 3+ messages in thread

From: X X @ 2004-12-02 03:11 UTC (permalink / raw)
  To: pgsql-interfaces

Hello,

I'm writing a client in C++ using the C-library
(libpq) interface to PostgreSQL server.

I would like to know what function to call to obtain
one of the codes listed at 

http://www.postgresql.org/docs/7.4/static/errcodes-appendix.html

(I'm aware from other postings that in JDBC it would
be a getSQLState() call, but what if I have to code
the client in C/C++ and use libpq ?)

I found that the error codes are defined in file
errcodes.h under the /server include directory, but
can't find the client-side function that returns them.

Any hints are much appreciated,
Serge



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: libpq: how to get error code (not message)
  2004-12-02 03:11 libpq: how to get error code (not message) X X <junkmbox@yahoo.com>
@ 2004-12-02 06:06 ` Michael Fuhr <mike@fuhr.org>
  2004-12-03 01:41   ` Re: libpq: how to get error code (not message) Michael Fuhr <mike@fuhr.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Michael Fuhr @ 2004-12-02 06:06 UTC (permalink / raw)
  To: X X <junkmbox@yahoo.com>; +Cc: pgsql-interfaces

On Wed, Dec 01, 2004 at 07:11:44PM -0800, X X wrote:

> I would like to know what function to call to obtain
> one of the codes listed at 
> 
> http://www.postgresql.org/docs/7.4/static/errcodes-appendix.html

I think you're looking for PQresultErrorField() called with the
fieldcode argument set to PG_DIAG_SQLSTATE.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: libpq: how to get error code (not message)
  2004-12-02 03:11 libpq: how to get error code (not message) X X <junkmbox@yahoo.com>
  2004-12-02 06:06 ` Re: libpq: how to get error code (not message) Michael Fuhr <mike@fuhr.org>
@ 2004-12-03 01:41   ` Michael Fuhr <mike@fuhr.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Michael Fuhr @ 2004-12-03 01:41 UTC (permalink / raw)
  To: X X <junkmbox@yahoo.com>; +Cc: pgsql-interfaces

On Thu, Dec 02, 2004 at 03:59:46PM -0800, X X wrote:

> > I think you're looking for PQresultErrorField()
> > called with the
> > fieldcode argument set to PG_DIAG_SQLSTATE.
>
> Thanks for your reply. This is exactly what I was
> looking for, but the libpq documentation does not
> mention it (at least I did not find).

Appendix A says:

    All messages emitted by the PostgreSQL server are assigned
    five-character error codes that follow the SQL standard's
    conventions for "SQLSTATE" codes. 

The PQresultErrorField() function is documented in the libpq
"Command Execution Functions" section:

http://www.postgresql.org/docs/7.4/static/libpq-exec.html#AEN20619

The documentation says:

    The following field codes are available:
    ...

    PG_DIAG_SQLSTATE
        The SQLSTATE code for the error (see Appendix A). Not localizable.
	Always present.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2004-12-03 01:41 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-12-02 03:11 libpq: how to get error code (not message) X X <junkmbox@yahoo.com>
2004-12-02 06:06 ` Michael Fuhr <mike@fuhr.org>
2004-12-03 01:41   ` Michael Fuhr <mike@fuhr.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox