Thread: [C API] Is there a nice way to get table/column name on some error ?

[C API] Is there a nice way to get table/column name on some error ?

From
JiangWei
Date:
<table border="1" class="CALSTABLE"><tbody><tr><td>42703</td><td>UNDEFINED
COLUMN</td><td>undefined_column</td></tr><tr><td>42883</td><td>UNDEFINED
FUNCTION</td><td>undefined_function</td></tr><tr><td>42P01</td><td>UNDEFINED
TABLE</td><td>undefined_table</td></tr></tbody></table><br/> I want to know which column undefined when
"undefined_column"Happen at run time.<br /><br /><br /><br /><br /> 

Re: [C API] Is there a nice way to get table/column name on some error ?

From
Michael Fuhr
Date:
[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?

-- 
Michael Fuhr


Re: [C API] Is there a nice way to get table/column

From
JiangWei
Date:
Michael Fuhr wrote: <blockquote cite="mid20060106021149.GA80657@winnie.fuhr.org" type="cite"><pre wrap="">[Please post
inplain text, not HTML.]
 

On Fri, Jan 06, 2006 at 09:32:36AM +0800, JiangWei wrote: </pre><blockquote type="cite"><pre wrap="">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.   </pre></blockquote><pre wrap="">
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?
 </pre></blockquote> No.  I want to throw a exception with  the column name, like this :<br /><br /> if (sqlstate ==
undefined_column)<br/>   throw UnknownProperty(column_name);<br /><br /><br /> 

Re: [C API] Is there a nice way to get table/column name on some error ?

From
Michael Fuhr
Date:
[Please post in plain text, not HTML.]

On Fri, Jan 06, 2006 at 10:15:19AM +0800, JiangWei wrote:
> > 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);

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).

-- 
Michael Fuhr


Re: [C API] Is there a nice way to get table/column

From
"Jeroen T. Vermeulen"
Date:
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




Re: [C API] Is there a nice way to get table/column

From
JiangWei
Date:
>(BTW apparently you're using C++, not C, so why are you using the C API?)
>
>
>Jeroen
>
>
>
>  
>
C API is simple,clean