This section describes how to send LONG values to the database from embedded SQL applications. For background information, see Sending and retrieving long values.
The procedures are different depending on whether you are using static or dynamic SQL.
Declare a host variable of type DECL_LONGVARCHAR, DECL_LONGNVARCHAR, or DECL_LONGBINARY, as appropriate.
If you are sending NULL, set the indicator variable to a negative value.
For more information, see Indicator variables.
Set the stored_len field of the host variable structure to the number of bytes of data in the array field.
Send the data by opening the cursor or executing the statement.
The following code fragment illustrates the mechanics of sending a LONG VARCHAR using static embedded SQL. It is not intended to be a practical application.
#define DATA_LEN 12800 EXEC SQL BEGIN DECLARE SECTION; // SQLPP initializes longdata.array_len DECL_LONGVARCHAR(128000) longdata; EXEC SQL END DECLARE SECTION; void set_test_var() { // init longdata for sending data memset( longdata.array, 'a', DATA_LEN ); longdata.stored_len = DATA_LEN; printf( "Setting test_var to %d a's\n", DATA_LEN ); EXEC SQL SET test_var = :longdata; } |
Set the sqltype field to DT_LONGVARCHAR, DT_LONGNVARCHAR, or DT_LONGBINARY, as appropriate.
If you are sending NULL, set * sqlind to a negative value.
If you are not sending NULL, set the sqldata field to point to the LONGVARCHAR, LONGNVARCHAR, or LONGBINARY host variable structure.
You can use the LONGVARCHARSIZE(n), LONGNVARCHARSIZE(n), or LONGBINARYSIZE(n) macros to determine the total number of bytes to allocate to hold n bytes of data in the array field.
Set the array_len field of the host variable structure to the number of bytes allocated for the array field.
Set the stored_len field of the host variable structure to the number of bytes of data in the array field. This must not be more than array_len.
Send the data by opening the cursor or executing the statement.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |