Transferring data out of the database to a flat file

Data can be copied out from a database only into an operating system (host) file. Bulk copy does not allow the transfer of data from a database into program variables.

When transferring data out to a host file from a database table, the chief advantage of bulk copy over SQL select is that it allows very specific output file formats to be specified. Bulk copy is not significantly faster than SQL select.

To copy data out from a database, a DB-Library/C application must perform the following steps:

  1. Call dblogin to acquire a LOGINREC structure for later use with dbopen.

  2. Call dbopen to establish a connection with Adaptive Server.

  3. Call bcp_init to initialize the bulk copy operation. To copy data out from the database, direction must be passed as DB_OUT.

  4. Call bcp_control to set the batch size and change control parameter default settings.

  5. Call bcp_columns to set the total number of columns found in the host file.

  6. Call bcp_colfmt once for each column in the host file. If the host file matches the database table exactly, an application does not have to call bcp_colfmt.

  7. Call bcp_exec to start the copy out.