pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Multi-Demensional Array Support.
2+ messages / 2 participants
[nested] [flat]

* Multi-Demensional Array Support.
@ 2005-02-22 17:43  Greg Johnson <gregj@interprose.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Greg Johnson @ 2005-02-22 17:43 UTC (permalink / raw)
  To: pgsql-jdbc

I started hacking in multi-dimensional array support into the driver. 

However, with the getArray() function I have to return an ArrayList of
ArrayLists (or Object[] of Object[]) instead of the native type Object
[][] for example. I was wondering what you guys/gals thoughts are on the
this? 

As an application developer I personally would like to get ArrayLists of
ArrayLists back. 

It seems that unless you what to have a whole bunch of nasty "if" logic
that is the only way to implement multi-dimensional arrays cleanly. 
Example:
 if array_dims==1
	returnVal = String[];
 if array_dims==2 
	returnVal = String[][];
 else if array_dims==3 
	returnVal = String[][][];

.. but I am not java guru so if there is a better way let me know.

Also, is there a reason why a regular expression is not used to parse
out the array string returned from postgresql?

Thanks, I hope I can help out!
Greg




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

* Re: Multi-Demensional Array Support.
@ 2005-02-22 21:44  Oliver Jowett <oliver@opencloud.com>
  parent: Greg Johnson <gregj@interprose.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Oliver Jowett @ 2005-02-22 21:44 UTC (permalink / raw)
  To: Greg Johnson <gregj@interprose.com>; +Cc: pgsql-jdbc

Greg Johnson wrote:
> I started hacking in multi-dimensional array support into the driver. 
> 
> However, with the getArray() function I have to return an ArrayList of
> ArrayLists (or Object[] of Object[]) instead of the native type Object
> [][] for example. I was wondering what you guys/gals thoughts are on the
> this? 
> 
> As an application developer I personally would like to get ArrayLists of
> ArrayLists back. 

I assume you mean java.sql.Array.getArray(). The javadoc says you have 
to return a real array, not an ArrayList. I think it makes sense to 
return a multidimensional array when you have a multidimensional array 
on the server side; why would you want to require the extra casting on 
element access that you'd need if you returned an Object[] containing 
Object[] elements?

(are there any other JDBC drivers that support multidimensional arrays? 
what do they do here?)

> It seems that unless you what to have a whole bunch of nasty "if" logic
> that is the only way to implement multi-dimensional arrays cleanly. 
> Example:
>  if array_dims==1
> 	returnVal = String[];
>  if array_dims==2 
> 	returnVal = String[][];
>  else if array_dims==3 
> 	returnVal = String[][][];
> 
> .. but I am not java guru so if there is a better way let me know.

You can build and access arrays where you don't know the component type 
at compile type by using the methods of java.lang.reflect.Array.

> Also, is there a reason why a regular expression is not used to parse
> out the array string returned from postgresql?

java.util.regex is not present in JDK 1.2/1.3, which the driver needs to 
compile under.

-O



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


end of thread, other threads:[~2005-02-22 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-22 17:43 Multi-Demensional Array Support. Greg Johnson <gregj@interprose.com>
2005-02-22 21:44 ` Oliver Jowett <oliver@opencloud.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