Use Datablade API with spatial datablade?
Posted in 2012
Topics: Data Types & Schema Design
(I posted this to the Spatial Users forum as well, but that forum doesn't seem
to be very active).
I've been trying to upload geometry to an st_geometry column using the
datablade api.
I set my mi_lvarchar variable lvvar using
geom_to_wkb (&geom, &max_alloced, &lot_wkb_len, &lot_wkb_buf);
lvvar = mi_new_var(lot_wkb_len);
mi_set_varlen(lvvar,lot_wkb_len);
mi_set_vardata(lvvar,lot_wkb_buf);
(where geom_to_wkb is as in the spatial datablade example code)
I then do prepare the statement:
insert into table(linework,id) values(st_geomfromwkb(?,15),?);
and set:
numTypes = 2
values[0] = lvvar;
types[0] = "lvarchar";
nulls[0] = MI_FALSE;
lengths[0] = 0;
(and set values[1], etc.)
I get the error:
ERROR: USE44 XUSE44:-937:Unknown OGIS WKB byte-order byte encountered in
ST_GeomFromWKB. while executing statement <no query text>
when I execute the prepared statement:
mi_exec_prepared_statement(statement, MI_SEND_READ, 1,
numTypes,
values, lengths, nulls, types, 0, 0)
However, I when I do an mi_get_vardata on the mi_lvarchar that I'm passing up
(lvvar) and inspect the binary contents, I get:
length is 98
swap_bytes is 0
wkb_type is 5
nlines is 1
swap_bytes is 0 (for first line)
wkb_type is 2 (for first line)
...
Both swap_bytes appear to be correct.
Thanks for any help you can provide.
Mike Dunham-Wilkie
Just to close the loop on this... I've received confirmation that the milib client interface is incompatible with the Spatial DataBlade st_*fromwkb methods, due to the way the lvarchar parameter is handled in the client-server interchange. IBM recommends using the ODBC or ESQL interfaces, and supplies (with the Spatial DataBlade) very helpful sample code for these two interfaces.