The bulk-copy-in process

A typical application follows these steps to perform a bulk-copy-in operation:

  1. Initializes the application in the same way as for a Client-Library application and sets up Client-Library error handling. Bulk-Library reports errors generated by calls to client-side routines as Client-Library messages.

  2. Allocates the connection structure to be used.

  3. Calls ct_con_props to set the necessary properties to connect to the target server. In addition, the application must set the CS_BULK_LOGIN property to CS_TRUE to enable the connection to perform bulk copies.

    NoteProgrammers can often tune the Tabular Data Stream™ (TDS) packet size to increase throughput. A packet size larger than the default usually increases performance. First, make sure that the Adaptive Server is configured to accept a larger TDS packet size, then set the CS_PACKET_SIZE connection property in your application. See the Adaptive Server Enterprise System Administration Guide for details on increasing the allowable network packet size and the Open Client Client-Library/C Reference Manual for details on connection properties.

  4. Calls ct_connect to open the connection.

  5. Calls blk_alloc to allocate a bulk-descriptor structure.

  6. Calls blk_init to initialize the bulk-copy operation.

  7. For each column in the target table, the application:

  8. Transfers the data.

    While data remains to be transferred, the application places data into the program variables that are bound to the table columns, then calls blk_rowxfer_mult to transfer the row.

    Before each call to blk_rowxfer_mult, for each bound column, the application sets datalen and indicator values to specify what value should be inserted:

    datalen value

    indicator value

    Result

    > 0

    Any (is ignored).

    blk_rowxfer_mult reads datalen bytes from buffer as the column value.

    0

    0

    The column’s default value, if available, is inserted. If no default is available, NULL is inserted.

    0

    -1

    NULL is inserted.

    If the row contains columns whose data is being transferred in chunks, the application calls blk_textxfer in a loop for each column. Data being transferred via blk_textxfer must reside at the end of the row, following any bound columns.

    The application can call blk_done(CS_BLK_BATCH), if needed, to send a batch of rows. This call instructs the Adaptive Server to permanently save all rows transferred since the application’s last blk_done call.

  9. Calls blk_done(CS_BLK_ALL) to send the last batch of rows and indicate that the bulk-copy operation is complete.

  10. Calls blk_drop to deallocate the bulk-descriptor structure.

NoteAn application can call blk_bind between calls to blk_rowxfer_mult to specify a different program variable address or length.