From jw.pgsql@sduept.com Fri Jan 6 02:17:29 2006 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B05229DC9FF for ; Thu, 5 Jan 2006 22:17:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 66455-03 for ; Thu, 5 Jan 2006 22:17:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from hp.sduept.com (unknown [60.208.83.220]) by postgresql.org (Postfix) with ESMTP id 87CE69DC802 for ; Thu, 5 Jan 2006 22:17:26 -0400 (AST) Received: from [192.168.1.36] (soft36.sduept.com [192.168.1.36]) by hp.sduept.com (8.13.1/8.13.1) with ESMTP id k062FJBf017719; Fri, 6 Jan 2006 10:15:20 +0800 Message-ID: <43BDD2B7.2090609@sduept.com> Date: Fri, 06 Jan 2006 10:15:19 +0800 From: JiangWei User-Agent: Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Michael Fuhr CC: pgsql-interfaces@postgresql.org Subject: Re: [C API] Is there a nice way to get table/column References: <43BDC8B4.6020801@sduept.com> <20060106021149.GA80657@winnie.fuhr.org> In-Reply-To: <20060106021149.GA80657@winnie.fuhr.org> Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.113 required=5 tests=[AWL=0.111, HTML_MESSAGE=0.001, MIME_HTML_ONLY=0.001] X-Spam-Score: 0.113 X-Spam-Level: X-Archive-Number: 200601/5 X-Sequence-Number: 5921 Michael Fuhr wrote:
[Please post in plain text, not HTML.]

On Fri, Jan 06, 2006 at 09:32:36AM +0800, JiangWei wrote:
  
42703 UNDEFINED COLUMN   undefined_column
42883 UNDEFINED FUNCTION undefined_function
42P01 UNDEFINED TABLE    undefined_table

I want to know which column undefined when "undefined_column" Happen
at run time.
    

With libpq you can call PQerrorMessage(), PQresultErrorMessage(),
or PQresultErrorField() to get a string that should identify the
offending column, function, table, etc.  Will that work for your
purpose?

  
No.  I want to throw a exception with  the column name, like this :

if (sqlstate == undefined_column)
  throw UnknownProperty(column_name);


From jtv@xs4all.nl Fri Jan 6 04:20:19 2006 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D21059DCA04 for ; Fri, 6 Jan 2006 00:20:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91126-01 for ; Fri, 6 Jan 2006 00:20:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp-vbr4.xs4all.nl (smtp-vbr4.xs4all.nl [194.109.24.24]) by postgresql.org (Postfix) with ESMTP id 22F0A9DC947 for ; Fri, 6 Jan 2006 00:20:16 -0400 (AST) Received: from webmail.xs4all.nl (dovemail7.xs4all.nl [194.109.26.9]) by smtp-vbr4.xs4all.nl (8.13.3/8.13.3) with ESMTP id k064JoMp028954; Fri, 6 Jan 2006 05:19:55 +0100 (CET) (envelope-from jtv@xs4all.nl) Received: from 125.24.3.239 (SquirrelMail authenticated user jtv) by webmail.xs4all.nl with HTTP; Fri, 6 Jan 2006 11:19:56 +0700 (ICT) Message-ID: <7738.125.24.3.239.1136521196.squirrel@webmail.xs4all.nl> In-Reply-To: <20060106040158.GA81499@winnie.fuhr.org> References: <43BDC8B4.6020801@sduept.com> <20060106021149.GA80657@winnie.fuhr.org> <43BDD2B7.2090609@sduept.com> <20060106040158.GA81499@winnie.fuhr.org> Date: Fri, 6 Jan 2006 11:19:56 +0700 (ICT) Subject: Re: [C API] Is there a nice way to get table/column From: "Jeroen T. Vermeulen" To: "Michael Fuhr" Cc: "JiangWei" , pgsql-interfaces@postgresql.org User-Agent: SquirrelMail/1.4.5 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/7 X-Sequence-Number: 5923 On Fri, January 6, 2006 11:01, Michael Fuhr wrote: > On Fri, Jan 06, 2006 at 10:15:19AM +0800, JiangWei wrote: >> No. I want to throw a exception with the column name, like this : >> if (sqlstate == undefined_column) >> throw UnknownProperty(column_name); > > I'm not aware of a way to get just the column name, so if nobody > else posts a way then you might have to parse the error message > (admittedly a pain, especially if you have to deal with different > languages). Well, assuming your program has a hand in constructing the queries and therefore understands their structure, you could have a pretty good stab at finding out. Just query the system catalog to find the invalid column name. It'd be slow, but exceptions are presumably rare so the cost may be acceptable. (BTW apparently you're using C++, not C, so why are you using the C API?) Jeroen From jw.pgsql@sduept.com Fri Jan 6 04:47:36 2006 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9B5759DC947 for ; Fri, 6 Jan 2006 00:47:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 95637-04 for ; Fri, 6 Jan 2006 00:47:35 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from hp.sduept.com (unknown [60.208.83.220]) by postgresql.org (Postfix) with ESMTP id 2C6E39DC888 for ; Fri, 6 Jan 2006 00:47:31 -0400 (AST) Received: from [192.168.1.36] (soft36.sduept.com [192.168.1.36]) by hp.sduept.com (8.13.1/8.13.1) with ESMTP id k064jbdt018607 for ; Fri, 6 Jan 2006 12:45:37 +0800 Message-ID: <43BDF5F0.5040806@sduept.com> Date: Fri, 06 Jan 2006 12:45:36 +0800 From: JiangWei User-Agent: Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929) X-Accept-Language: en-us, en MIME-Version: 1.0 CC: pgsql-interfaces@postgresql.org Subject: Re: [C API] Is there a nice way to get table/column References: <43BDC8B4.6020801@sduept.com> <20060106021149.GA80657@winnie.fuhr.org> <43BDD2B7.2090609@sduept.com> <20060106040158.GA81499@winnie.fuhr.org> <7738.125.24.3.239.1136521196.squirrel@webmail.xs4all.nl> In-Reply-To: <7738.125.24.3.239.1136521196.squirrel@webmail.xs4all.nl> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.196 required=5 tests=[AWL=0.007, MISSING_HEADERS=0.189] X-Spam-Score: 0.196 X-Spam-Level: X-Archive-Number: 200601/8 X-Sequence-Number: 5924 >(BTW apparently you're using C++, not C, so why are you using the C API?) > > >Jeroen > > > > > C API is simple,clean