[freetds] fieldterm and rowterm for freebcp

Craig A. Berry craigberry at mac.com
Tue Feb 11 19:44:40 EST 2003


freebcp was going to a lot of trouble to collect the -t and -r options, but 
it nevertheless had \t and \n hard-wired as the column and row terminators, 
respectively.  The patch below makes it send what it got to bcp_colfmt() and 
also protects against the case where an option was specified but not given a 
value.

--- src/apps/freebcp.c;-0       Tue Feb  4 07:28:28 2003
+++ src/apps/freebcp.c  Tue Feb 11 19:23:49 2003
@@ -379,11 +379,11 @@
        if (pdata->cflag) {
                /* Fill in some default values */
 
-               if (!pdata->tflag) {    /* field terminator not specified */
+               if (!pdata->tflag || !pdata->fieldterm) {       /* field terminator not specified */
                        pdata->fieldterm = (char *) malloc(2);
                        strcpy(pdata->fieldterm, "\t");
                }
-               if (!pdata->rflag) {    /* row terminator not specified */
+               if (!pdata->rflag || !pdata->rowterm) {         /* row terminator not specified */
                        pdata->rowterm = (char *) malloc(2);
                        strcpy(pdata->rowterm, "\n");
                }
@@ -480,13 +480,15 @@
                }
 
                for (i = 1; i <= li_numcols - 1; i++) {
-                       if (bcp_colfmt(dbproc, i, SYBCHAR, 0, -1, (const BYTE *) "\t", sizeof(char), i) == FAIL) {
+                       if (bcp_colfmt(dbproc, i, SYBCHAR, 0, -1, (const BYTE *) pdata->fieldterm, 
+                                       strlen(pdata->fieldterm), i) == FAIL) {
                                printf("Error in bcp_colfmt col %d\n", i);
                                return FALSE;
                        }
                }
 
-               if (bcp_colfmt(dbproc, li_numcols, SYBCHAR, 0, -1, (const BYTE *) "\n", sizeof(char), li_numcols) == FAIL) {
+               if (bcp_colfmt(dbproc, li_numcols, SYBCHAR, 0, -1, (const BYTE *) pdata->rowterm, 
+                               strlen(pdata->rowterm), li_numcols) == FAIL) {
                        printf("Error in bcp_colfmt col %d\n", li_numcols);
                        return FALSE;
                }
[end of patch]




More information about the FreeTDS mailing list