Embedded SQL application support of BINARY and VARBINARY
Embedded SQL application
can copy BINARY data of predetermined length after you declare the
BINARY data type variable in the declare section. The VARBINARY data
type variable can be declared in the declare section of the embedded
SQL application with set length to copy the VARBINARY data.
The following example shows you how to use the BINARY and VARBINARY data types in an embedded application:
EXEC SQL BEGIN DECLARE SECTION;
sql type is binary(50) binary1 ;
sql type is varbinary(100) binary2 ;
EXEC SQL END DECLARE SECTION;
char strng1[50];
char strng2[50];
memset( binary1, 0x00, sizeof(binary1) );
memset( binary2.data, 0x00, sizeof(binary2.data) );
strcpy( strng1, "AAAAAAZZZZZMMMMMMMMMJJJJJJJJJJJJJJ" );
strcpy( strng2, "BBBBBBBBBBBBBBBCCCCCCCCCCCDDDDDDDDEEEEEEEEEEEK" );
memcpy( binary1, strng1, strlen(strng1) );
memcpy( binary2.data, strng2, strlen(strng2) );
binary2.length = strlen(binary2.data);
EXEC SQL INSERT INTO test1 VALUES ( :binary1, :binary2 );
On retrieval from the database, the length of the data is set properly
in the corresponding structure.