X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9CF213A4131 for ; Fri, 3 Dec 2004 01:41:22 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92308-06 for ; Fri, 3 Dec 2004 01:41:17 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 7F08E3A4016 for ; Fri, 3 Dec 2004 01:41:19 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id iB31fGHY024051 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 2 Dec 2004 18:41:19 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id iB31fGGg011029; Thu, 2 Dec 2004 18:41:16 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id iB31fFGR011028; Thu, 2 Dec 2004 18:41:15 -0700 (MST) (envelope-from mfuhr) Date: Thu, 2 Dec 2004 18:41:15 -0700 From: Michael Fuhr To: X X Cc: pgsql-interfaces@postgresql.org Subject: Re: libpq: how to get error code (not message) Message-ID: <20041203014115.GA5451@winnie.fuhr.org> References: <20041202060648.GA60984@winnie.fuhr.org> <20041202235946.94486.qmail@web51107.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20041202235946.94486.qmail@web51107.mail.yahoo.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200412/4 X-Sequence-Number: 5175 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/