Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - Programming » SQL Anywhere Embedded SQL » Sending and retrieving long values

Retrieving LONG data Next Page

Sending LONG data


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.

To send a LONG value (static SQL)
  1. Declare a host variable of type DECL_LONGVARCHAR, DECL_LONGNVARCHAR, or DECL_LONGBINARY, as appropriate.

  2. If you are sending NULL, set the indicator variable to a negative value.

    For more information, see Indicator variables.

  3. Set the stored_len field of the host variable structure to the number of bytes of data in the array field.

  4. 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;
}
To send a LONG value (dynamic SQL)
  1. Set the sqltype field to DT_LONGVARCHAR, DT_LONGNVARCHAR, or DT_LONGBINARY, as appropriate.

  2. If you are sending NULL, set * sqlind to a negative value.

  3. 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.

  4. Set the array_len field of the host variable structure to the number of bytes allocated for the array field.

  5. 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.

  6. Send the data by opening the cursor or executing the statement.