GET DATA statement [ESQL]
536
WITH TEXTPTR can be used only with long data types (LONG BINARY,
LONG VARCHAR, TEXT, IMAGE). If you attempt to use it with another
data type, the error INVALID_TEXTPTR_VALUE is returned.
The total length of the data is returned in the SQLCOUNT field of the
SQLCA structure.
♦
SQL/92 Vendor extension.
♦
Sybase Not supported by Open Client/Open Server. An alternative is
the Transact-SQL READTEXT statement.
♦ The following example uses GET DATA to fetch a binary large object
(often called a blob).
EXEC SQL BEGIN DECLARE SECTION;
DECL_BINARY(1000) piece;
short ind;
long offset;
EXEC SQL END DECLARE SECTION;
int size;
/* Open a cursor on a long varchar field */
EXEC SQL DECLARE big_cursor CURSOR FOR
SELECT long_data FROM some_table
WHERE key_id = 2;
EXEC SQL OPEN big_cursor;
EXEC SQL FETCH big_cursor INTO :piece;
for( offset = 0; ; offset += piece.len ) {
EXEC SQL GET DATA big_cursor COLUMN 1
OFFSET :offset INTO :piece:ind;
/* Done if the NULL value */
if( ind < 0 ) break;
write_out_piece( piece );
/* Done when the piece was not truncated */
if( ind == 0 ) break;
}
EXEC SQL CLOSE big_cursor;
Standards and
compatibility
Example