PRB: When to Use bcp_columns() and bcp_colfmt()

Last reviewed: April 25, 1997
Article ID: Q70675

The information in this article applies to:

  - Microsoft SQL Server version 4.2 for OS/2

SYMPTOMS

Using the default data formats of the bcp_init() function does not work correctly while trying to bulk copy a file that exactly matches the following table column for column:

   dbfcmd (dbproc, "CREATE TABLE %s ", argv[1]);
   dbcmd  (dbproc, "(col1       char(11) NULL,");
   dbcmd  (dbproc, " col2 char(40) NULL,");

CAUSE

Columns that allow nulls are being used. According to page 219 of the "Microsoft SQL Server Programmer's Reference for C" version 1.11 manual, the default data formats for columns that allow nulls are as follows:

   If a given database column's date is variable length or can
   contain null values, the operating system file's data column is
   prefixed by a... 1 byte length value...

WORKAROUND

Because nulls are being used in the table definition, the 1-byte prefix length must be included in the data file, or the following code fragment, which uses nondefault (that is, no prefix) formatting, can be used instead:

   if ( ! (bcp_columns(dbproc,13) )  ) exit(0);
               //        file data pre data       term tab
               //dbproc, col# type len leng term  len  col#
   bcp_colfmt  (dbproc , 1  , 0 , 0 , 11 , "\0" , -1 , 1  );
   bcp_colfmt  (dbproc , 2  , 0 , 0 , 40 , "\0" , -1 , 2  );


Additional query words:
Keywords : kbtool SSrvBCP
Version : 4.2
Platform : OS/2


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 25, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.