blk_textxfer

Description

Transfers a column’s data in chunks during a bulk-copy operation.

Syntax

CS_RETCODE blk_textxfer(blkdesc, buffer, buflen,
               outlen)
 
 CS_BLKDESC     *blkdesc;
 CS_BYTE            *buffer;
 CS_INT                buflen;
 CS_INT              *outlen;

Parameters

blkdesc

A pointer to the CS_BLKDESC that is serving as a control block for the bulk-copy operation. blk_alloc allocates a CS_BLKDESC structure.

buffer

A pointer to the space from which blk_textxfer picks up the chunk of text, image, sensitivity, or boundary data.

buflen

The length, in bytes, of the *buffer data space.

outlen

A pointer to an integer variable. outlen is not used for a bulk-copy-in operation and should be passed as NULL.

For a bulk-copy-out operation, *outlen represents the length, in bytes, of the data copied to *buffer.

Returns

blk_textxfer returns:

Table 4-11: blk_textxfer return values

Returns

Indicates

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

CS_END_DATA

When copying data out from a database, blk_textxfer returns CS_END_DATA to indicate that a complete column value has been sent.

When copying data into a database, blk_textxfer returns CS_END_DATA when an amount of data equal to blk_bind’s *datalen has been sent.

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.

Examples

Example 1

         /*
           ** BulkCopyIn()
           **
           ** BLKDATA and DATA_END are defined in the bulk copy
           ** example program.
           */
 
           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 initializing.
                */
                ...CODE DELETED.....
 
                /* Bind columns and transfer rows */
                dptr = BLKDATA;
                while (dptr->pub_id != DATA_END)
                {
                     datafmt.datatype = CS_INT_TYPE;
                     datafmt.count = 1;
                     datafmt.maxlength = sizeof(CS_INT);
                     datalen[0] = CS_UNUSED;
 
                     if (blk_bind(blkdesc, 1, &datafmt, &dptr->pub_id, 
                          &datalen[0], NULL) != CS_SUCCEED)
                     {
                          ex_error("BulkCopyIn: blk_bind(1) failed");
                          return CS_FAIL;
                     }
                     datafmt.datatype = CS_CHAR_TYPE;
                     datafmt.maxlength = MAX_PUBNAME - 1;
                     datalen[1] = strlen(dptr->pub_name);
                     if (blk_bind(blkdesc, 2, &datafmt, dptr->pub_name,
                           &datalen[1], NULL) != CS_SUCCEED)
                     {
                          ex_error("BulkCopyIn: blk_bind(2) failed");
                          return CS_FAIL;
                     }
                     datafmt.maxlength = MAX_PUBCITY - 1;
                     datalen[2] = strlen(dptr->pub_city);
                     if (blk_bind(blkdesc, 3, &datafmt, dptr->pub_city,
                           &datalen[2], NULL) != CS_SUCCEED)
                     {
                          ex_error("BulkCopyIn: blk_bind(3) failed");
                          return CS_FAIL;
                     }
                     datafmt.maxlength = MAX_PUBST - 1;
                     datalen[3] = strlen(dptr->pub_st);
                     if (blk_bind(blkdesc, 4, &datafmt, dptr->pub_st,
                           &datalen[3], NULL) != CS_SUCCEED)
                     {
                          ex_error("BulkCopyIn: blk_bind(4) failed");
                          return CS_FAIL;
                     }
                     datafmt.datatype = CS_TEXT_TYPE;
                     datafmt.maxlength = MAX_BIO - 1;
                     datalen[4] = strlen((char *)dptr->pub_bio);
                     if (blk_bind(blkdesc, 5, &datafmt, NULL,
                           &datalen[4], NULL) != CS_SUCCEED)
                     {
                          ex_error("BulkCopyIn: blk_bind(5) failed");
                          return CS_FAIL;
                     }
                     if (blk_rowxfer (blkdesc) == CS_FAIL)
                     {
                          ex_error("BulkCopyIn: EX_BLK - Failed on \
                               blk_rowxfer.");
                          return CS_FAIL;
                     }
                     if (blk_textxfer(blkdesc, dptr->pub_bio,
                          datalen[4], &len) == CS_FAIL)
                     {
                          ex_error("BulkCopyIn: blk_rowxfer() failed");
                          return CS_FAIL;
                     }
                     dptr++;
                }
                /* ALL the rows sent so clear up */
                ...CODE DELETED.....
 
                return CS_SUCCEED;
           }

Usage


Using blk_textxfer for bulk-copy-in operations


Using blk_textxfer for Bulk-Copy-Out operations

See also

blk_bind, blk_rowxfer_mult