Set the value of a Geometry type using a Well-Known Text (WKT) CLOB represented by a LOB_RESULT_LOCATOR.
Syntax
void FNC_GeomGetWKTClob(GEO_HANDLE geoHandle, LOB_RESULT_LOCATOR geoClob, int srid)
Syntax Elements
- geoHandle
- A handle to a Geometry type that is defined to be a return value for a UDF/UDM or an INOUT/OUT parameter to an external stored procedure.
- geoClob
- LOB locator for the WKT CLOB containing the return value for the ST_Geometry type in the Latin character set.
- srid
- Spatial Reference System Identifier of the Geometry to be set.
Usage Notes
The FNC_GeomSetWKTClob function sets the ST_Geometry return/OUT/INOUT parameter value using a LOB result locator. The ST_Geometry Handle geoHandle is passed as input along with a LOB result locator geoClob.. The geoClob locator value is obtained by calling FNC_GeomGetResultWKTClob, and LOB FNC routines are used to append the WKT value to the CLOB, which is passed to the FNC_GeomSetWKTClob routine. The CLOB must be in the Latin character set.
Use FNC_GeomSetWKTClob only with a LOB-based ST_Geometry value. Otherwise a 7579 error is generated: FNC_GeomSetWKTClob is only valid for LOB-based ST_Geometry values. Use FNC_GeomSetWKT() instead.
Example: Using FNC_GeomGetResultWKTClob and FNC_GeomSetWKTClob to retrieve and set the value of a return ST_Geometry
The following function takes an ST_Geometry parameter and returns an ST_Geometry that has the same value. It first retrieves the Well-Known Text format from the input geometry. It then retrieves the LOB result locator from the return ST_Geometry, appends the WKT to the CLOB, and then sets the CLOB into the return ST_Geometry.
REPLACE FUNCTION geo_wkt(p1 ST_Geometry)
RETURNS ST_Geometry
SPECIFIC geo_wkt
NO SQL
PARAMETER STYLE SQL
DETERMINISTIC
LANGUAGE C
EXTERNAL NAME 'CS!geo_wkt!geo_wkt.c!F!geo_wkt';
#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>
void geo_wkt( GEO_HANDLE *geo_in,
GEO_HANDLE *geo_out,
int *indicator_geo_in,
int *indicator_geo_out,
char sqlstate[6],
SQL_TEXT extname[129],
SQL_TEXT specific_name[129],
SQL_TEXT error_message[257])
{
LOB_RESULT_LOCATOR geoClob_out;
LOB_LOCATOR geoClob_in;
BYTE buffer[64000];
LOB_CONTEXT_ID id;
FNC_LobLength_t actlen;
int trunc_err = 0;
FNC_LobLength_t clob_length;
int srid = -1;
int max_length, max_length2, numLobs, numLobs2;
/* If input is null set return value to null. */
if (*indicator_geo_in == -1 )
{
*indicator_geo_out = -1;
return;
}
/* Get the Input Geometry Info */
FNC_GetGeometryInfo(*geo_in,&max_length, &numLobs);
/* Get the Output Geometry Info */
FNC_GetGeometryInfo(*geo_out,&max_length2, &numLobs2);
/*
* Copy geo_in ST_Geometry value to geo_out ST_Geometry value.
*
*/
if(numLobs ==1 && numLobs2==1)
{
/* Get the LOB_RESULT_LOCATOR of geo_out. */
FNC_GeomGetResultWKTClob(*geo_out, &geoClob_out);
/* Get the LOB_LOCATOR and srid of the input ST_Geometry value. */
FNC_GeomGetWKTClob(*geo_in, &geoClob_in, &srid);
FNC_LobOpen(geoClob_in, &id, 0, 0);
clob_length = FNC_GetLobLength(geoClob_in);
while (FNC_LobRead(id, buffer, clob_length, &actlen) == 0 && !trunc_err)
trunc_err = FNC_LobAppend(geoClob_out, buffer, actlen, &actlen);
FNC_LobClose(id);
/* Set the return ST_Geometry value */
FNC_GeomSetWKTClob(*geo_out, geoClob_out, srid);
}
}