blk_init

Description

Initiates a bulk-copy operation.

Syntax

CS_RETCODE blk_init(blkdesc, direction, tablename,
               tnamelen)
 
 CS_BLKDESC    *blkdesc;
 CS_INT               direction;
 CS_CHAR          *tablename;
 CS_INT             tnamelen;

Parameters

blkdesc

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.

direction

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.

tablename

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.

tnamelen

The length, in bytes, of *tablename. If *tablename is null-terminated, pass tnamelen as CS_NULLTERM.

Returns

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.

Examples

Example 1

/*
 ** 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;
 }

Usage

See also

blk_alloc, blk_bind, blk_done, blk_rowxfer_mult