User's Guide and Reference

ST_WKBToSQL

ST_WKBToSQL constructs a ST_Geometry value given its well-known binary representation. An SRID value of 0 is automatically used.

Syntax

db2gse.ST_WKBToSQL(WKBGeometry Blob(1M))

Return type

db2gse.ST_Geometry

Examples

The following CREATE TABLE statement creates the LOTS table, which has two columns: the LOT_ID column, which uniquely identifies each lot, and the LOT multipolygon column, which contains the geometry of each lot.

CREATE TABLE lots (lot_id  integer,
                   lot     db2gse.ST_MultiPolygon);

The following C code fragment contains ODBC functions embedded with DB2 Spatial Extender SQL functions that insert data into the LOTS table.

The ST_WKBToSQL function converts WKB representations into DB2 Spatial Extender geometry. The entire INSERT statement is copied into a wkb_sql char string. The INSERT statement contains parameter markers to accept the LOT_ID data and the LOT data, dynamically.

/* Create the SQL insert statement to populate the lot id and the
   lot multipolygon. The question marks are parameter markers that 
   indicate the lot_id and lot values that will be retrieved at
   run time. */
 
strcpy (wkb_sql,"insert into lots (lot_id, lot) 
  values(?, db2gse.ST_WKBToSQL(cast(? as blob(1m))))");
 
/* Allocate memory for the SQL statement handle and associate the 
   statement handle with the connection handle. */
 
rc = SQLAllocStmt (handle, &hstmt);
 
/* Prepare the SQL statement for execution. */
 
rc = SQLPrepare (hstmt, (unsigned char *)wkb_sql, SQL_NTS);
 
/* Bind the integer key value to the first parameter. */
 
pcbvalue1 = 0; 
rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG,
     SQL_INTEGER, 0, 0, &lot_id, 0, &pcbvalue1);
 
/* Bind the shape to the second parameter. */
 
pcbvalue2 = blob_len;
rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_BINARY,
     SQL_BLOB, blob_len, 0, shape_blob, blob_len, &pcbvalue2);
 
/* Execute the insert statement. */
 
rc = SQLExecute (hstmt);


[ Top of Page | Previous Page | Next Page ]