Contents Index Retrieving LONG data Using stored procedures

ASA Programming Guide
  Embedded SQL Programming
    Sending and retrieving long values

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 VARCHAR or LONG BINARY value (static SQL)

  1. Declare a host variable of type DECL_LONGVARCHAR or DECL_LONGBINARY, as appropriate.

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

    For more information, see Indicator variables.

  3. Set the stored_len field of the DECL_LONGVARCHAR or DECL_LONGBINARY 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 snippet 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 value using a LONGVARCHAR or LONGBINARY structure (dynamic SQL)

  1. Set the sqltype field to DT_LONGVARCHAR or DT_LONGBINARY as appropriate.

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

  3. Set the sqldata field to point to the LONGVARCHAR or LONGBINARY structure.

    You can use the LONGVARCHARSIZE( 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 LONGVARCHAR or LONGBINARY structure to the number of bytes allocated for the array field.

  5. Set the stored_len field of the LONGVARCHAR or LONGBINARY 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.


Contents Index Retrieving LONG data Using stored procedures