Обсуждение: Binary Cursors (& Geometric Type Support)

Поиск
Список
Период
Сортировка

Binary Cursors (& Geometric Type Support)

От
Jeff Hoffmann
Дата:
I'm trying to port some code from C/libpq to Java & one of the things
I'm having trouble with is getting binary cursors to work.  The C code
uses a binary cursor to speed up a loop through a bunch of polygons & I
was hoping it would have the same effect with Java.  The code for a
non-binary cursor works fine, but is just taking too long.  Basically,
here's what I'm doing:

query.executeUpdate("declare my_cursor cursor for select p from
my_polygon");
ResultSet rs = query.executeQuery("fetch 1 from my_cursor");
PGpolygon p = (PGpolygon)rs.getObject("p");

When I switch the "cursor" to a "binary cursor", I get the following error:

Conversion of point failed - java.lang.NumberFormatException:
??n?gk@A?z?v A?OT&?A@A

Is there something else I have to do to get this to work or am I going
to be out of luck?  I've seen references to people successfully using
binaries cursors in earlier messages in the list -- is it just the
non-standard geometric types that are troublesome from a binary perspective?

Thanks,

Jeff Hoffmann
PropertyKey.com


Re: Binary Cursors (& Geometric Type Support)

От
Barry Lind
Дата:
Jeff,

Since the curror is returning binary data, the only method that works re
retrieve the data is getBytes().  Get Object will not work with binary
cursors.

--Barry

Jeff Hoffmann wrote:
> I'm trying to port some code from C/libpq to Java & one of the things
> I'm having trouble with is getting binary cursors to work.  The C code
> uses a binary cursor to speed up a loop through a bunch of polygons & I
> was hoping it would have the same effect with Java.  The code for a
> non-binary cursor works fine, but is just taking too long.  Basically,
> here's what I'm doing:
>
> query.executeUpdate("declare my_cursor cursor for select p from
> my_polygon");
> ResultSet rs = query.executeQuery("fetch 1 from my_cursor");
> PGpolygon p = (PGpolygon)rs.getObject("p");
>
> When I switch the "cursor" to a "binary cursor", I get the following error:
>
> Conversion of point failed - java.lang.NumberFormatException:
> ??n?gk@A?z?v A?OT&?A@A
>
> Is there something else I have to do to get this to work or am I going
> to be out of luck?  I've seen references to people successfully using
> binaries cursors in earlier messages in the list -- is it just the
> non-standard geometric types that are troublesome from a binary
> perspective?
>
> Thanks,
>
> Jeff Hoffmann
> PropertyKey.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>


Re: Binary Cursors (& Geometric Type Support)

От
Jeff Hoffmann
Дата:
Barry Lind wrote:
> Jeff,
>
> Since the curror is returning binary data, the only method that works re
> retrieve the data is getBytes().  Get Object will not work with binary
> cursors.

Gotcha.  I was hoping getObject would automagically do the type
conversion.  If only the bytes would be in the right order do use the
DataInput classes, my life would have been a little easier, but it
apparently works, so I guess I'll just take this as a learning
experience.  I guess my other question should have been "Is this the
best way to use cursors with this driver?"  I was pretty much directly
translating from a C program, but is there a better way to do it, both
for binary and regular cursors?

----
Jeff Hoffmann
PropertyKey.com


Re: Binary Cursors (& Geometric Type Support)

От
Barry Lind
Дата:
Jeff,

I use both binary and regular cursors in my code without any apparent
problems.  I am not sure what you mean by 'Is this the best way to use
cursors with this driver?'

thanks,
--Barry

Jeff Hoffmann wrote:
 > Barry Lind wrote:
 >
 >> Jeff,
 >>
 >> Since the curror is returning binary data, the only method that works
 >> re retrieve the data is getBytes().  Get Object will not work with
 >> binary cursors.
 >
 >
 > Gotcha.  I was hoping getObject would automagically do the type
 > conversion.  If only the bytes would be in the right order do use the
 > DataInput classes, my life would have been a little easier, but it
 > apparently works, so I guess I'll just take this as a learning
 > experience.  I guess my other question should have been "Is this the
 > best way to use cursors with this driver?"  I was pretty much directly
 > translating from a C program, but is there a better way to do it, both
 > for binary and regular cursors?
 >
 > ----
 > Jeff Hoffmann
 > PropertyKey.com
 >
 >