pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
getArray() and char[]
3+ messages / 2 participants
[nested] [flat]

* getArray() and char[]
@ 2007-02-01 11:14  Jeffrey Cox <namredips@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Jeffrey Cox @ 2007-02-01 11:14 UTC (permalink / raw)
  To: pgsql-jdbc

While looking into updating getProcedureColumns, to appropriately  
return COLUMN_TYPE, ran into a 'not implemented' exception. Seems  
that getArray is not implemented for arrays of type char. Kinda fuzzy  
on all this, but walked the code and ultimately added an entry in  
TypeInfoCache for 'char' and then updated AbstractJdbc2Array to  
handle 'char' as a java.lang.Character[] rather than java.lang.String[]

it seems that the issue was that char[] was being identified as  
Types.OTHER in TypeInfoCache. Which fixed the unimplemented error.  
However, considering char[] as a String caused getArray() to return a  
string containing leading and trailing curly brackets. Hence the  
change to AbstractJdbc2Array.

Am I missing something, or is there another way around this?


Jeff



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

* Re: getArray() and char[]
@ 2007-02-01 17:52  Kris Jurka <books@ejurka.com>
  parent: Jeffrey Cox <namredips@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Kris Jurka @ 2007-02-01 17:52 UTC (permalink / raw)
  To: Jeffrey Cox <namredips@gmail.com>; +Cc: pgsql-jdbc



On Thu, 1 Feb 2007, Jeffrey Cox wrote:

> While looking into updating getProcedureColumns, to appropriately return 
> COLUMN_TYPE, ran into a 'not implemented' exception. Seems that getArray 
> is not implemented for arrays of type char. Kinda fuzzy on all this, but 
> walked the code and ultimately added an entry in TypeInfoCache for 
> 'char' and then updated AbstractJdbc2Array to handle 'char' as a 
> java.lang.Character[] rather than java.lang.String[]

This is not quite right.  The pg_proc column you are looking at is an 
array of "char" which is a special one byte datatype which is different 
than something like char(N) which is implemented by the bpchar type on the 
backend.  The new TypeInfoCache code is correct, but the 
AbstractJdbc2Array must still return String[] since it must support the 
char(N) version as well.

> it seems that the issue was that char[] was being identified as 
> Types.OTHER in TypeInfoCache. Which fixed the unimplemented error. 
> However, considering char[] as a String caused getArray() to return a 
> string containing leading and trailing curly brackets. Hence the change 
> to AbstractJdbc2Array.
>

I'm not sure why that would happen, perhaps it indicates another bug?
I cannot duplicate it here with the attached test case and your 
TypeInfoCache changes.

Kris Jurka

Attachments:

ArrayTest.java (text/plain, 561B) download import java.sql.*; public class ArrayTest { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5820/jurka","jurka",""); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT '{i,o,o}'::\"char\"[]"); rs.next(); Array arr = rs.getArray(1); String s[] = (String[])arr.getArray(); for (int i=0; i<s.length; i++) { System.out.println(s[i]); } conn.close(); } }
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: getArray() and char[]
@ 2007-02-02 02:40  Kris Jurka <books@ejurka.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Kris Jurka @ 2007-02-02 02:40 UTC (permalink / raw)
  To: Jeffrey Cox <namredips@gmail.com>; +Cc: pgsql-jdbc



On Thu, 1 Feb 2007, Jeffrey Cox wrote:

> Are you saying that the line I added in TypeInfoCache was correct with 
> "java.lang.Character", but in AbstractJdbc2Array I need to do something to 
> ensure the return of a string... or should the line in TypeInfoCache be a 
> string?
>


I was only really thinking about the addition to TypeInfoCache mapping 
"char" -> Types.CHAR, but you're right the class should be 
java.lang.String.  That class must be what's returned by getObject which 
is driven off the Types.CHAR value.

Kris Jurka





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


end of thread, other threads:[~2007-02-02 02:40 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-02-01 11:14 getArray() and char[] Jeffrey Cox <namredips@gmail.com>
2007-02-01 17:52 ` Kris Jurka <books@ejurka.com>
2007-02-02 02:40   ` Kris Jurka <books@ejurka.com>

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