Initiates a bulk-copy operation.
CS_RETCODE blk_init(blkdesc, direction, tablename, tnamelen) CS_BLKDESC *blkdesc; CS_INT direction; CS_CHAR *tablename; CS_INT tnamelen;
A pointer to the CS_BLKDESC controlling the bulk-copy operation. An application can allocate a CS_BLKDESC by calling blk_alloc.
The parent connection of the CS_BLKDESC must be open when blk_init is called and cannot have any pending results.
One of the following symbolic values, to indicate the direction of the bulk-copy operation:
Value of direction |
blk_init |
---|---|
CS_BLK_IN |
Begins a bulk-copy operation to upload rows from the client to the server. |
CS_BLK_OUT |
Begins a bulk-copy operation to download rows from the server to the client. |
A pointer to the name of the table of interest. Any legal server table name is acceptable. The table name cannot contain a colon (:) or slice number.
The length, in bytes, of *tablename. If *tablename is null-terminated, pass tnamelen as CS_NULLTERM.
blk_init returns:
Returns |
Indicates |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
CS_PENDING |
Asynchronous network I/O is in effect. For more information, see the “Asynchronous Programming” topics page in the Open Client Client-Library/C Reference Manual. |
A common cause of failure is specifying a non-existent table.
/*
** BulkCopyIn()
** Ex_tabname is globally defined.
*/
CS_STATIC CS_RETCODE
BulkCopyIn(connection)
CS_CONNECTION *connection;
{
CS_BLKDESC *blkdesc;
CS_DATAFMT datafmt; /* variable descriptions */
Blk_Data *dptr; /* data for transfer */
CS_INT datalen[5]; /* variable data length */
CS_INT len;
CS_INT numrows;
/*
** Ready to start the bulk copy in now that all the
** connections have been made and have a table name.
** Start by getting the bulk descriptor and
** initializing.
*/
if (blk_alloc(connection, BLK_VERSION_100, &blkdesc)
!= CS_SUCCEED)
{
ex_error("BulkCopyIn: blk_alloc() failed");
return CS_FAIL;
}
if (blk_init(blkdesc, CS_BLK_IN,
Ex_tabname, strlen(Ex_tabname)) == CS_FAIL)
{
ex_error("BulkCopyIn: blk_init() failed");
return CS_FAIL;
}
/*
** Bind the variables to the columns and send the rows,
** and then clean up.
*/
...CODE DELETED.....
return CS_SUCCEED;
}
blk_init begins a bulk-copy operation.
blk_init is a client-side routine. However, it is necessary in both client-only and gateway applications.
Multiple CS_BLKDESC and CS_COMMAND structures can exist on the same connection, but only one CS_BLKDESC or CS_COMMAND structure can be active at the same time.
A bulk-copy operation begun with blk_init must be completed before the connection can be used for any other operation.
A bulk-copy operation cannot be started when the connection is being used to initiate, send, or process the results of other Client-Library or Bulk-Library commands.
When a bulk-copy operation is complete, an application must call blk_done with type as CS_BLK_ALL to mark the end of the bulk-copy operation and clean up internal Bulk-Library data structures.