Skip to Content.
Sympa Menu

freetds - [freetds] [PATCH] support for no terminator in bcp format file

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Xavier <xavier+freetds AT diwi.org>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] [PATCH] support for no terminator in bcp format file
  • Date: Sat, 6 Dec 2008 13:31:01 -0800


bcp_colfmt requires a null pointer when specifying no terminator, and
currently barfs when zero length is supplied with non-null pointer (as
is
the case when specifying an empty string for terminator in the format
file).

The attached patch fixes the parsing of the bcp format file to pass a
null
pointer when an empty string was specified as terminator.

NB: a nice side effect of this is the possibility to use a named pipe as
input to freebcp

When specifying a prefix length and no terminator for all columns in the
format file, freebcp will not perform any fseek on the input stream,
allowing the use of named pipes.


- Xavier
diff -ur freetds-cvs/src/dblib/bcp.c freetds/src/dblib/bcp.c
--- freetds-cvs/src/dblib/bcp.c	2008-11-25 14:58:28.000000000 -0800
+++ freetds/src/dblib/bcp.c	2008-12-06 12:04:37.000000000 -0800
@@ -2894,13 +2894,16 @@
 
 			if (*tok != '\"')
 				return (FALSE);
-
-			if ((ci->terminator = malloc(i)) == NULL) {
-				dbperror(dbproc, SYBEMEM, errno);
-				return FALSE;
+				
+			if(i > 0) {
+				if ((ci->terminator = malloc(i)) == NULL) {
+					dbperror(dbproc, SYBEMEM, errno);
+					return FALSE;
+				}
+				memcpy(ci->terminator, term, i);
 			}
-			
-			memcpy(ci->terminator, term, i);
+			else ci->terminator = NULL;
+
 			ci->term_len = i;
 
 			whichcol = TAB_COLNUM;


  • [freetds] [PATCH] support for no terminator in bcp format file, Xavier, 12/06/2008

Archive powered by MHonArc 2.6.24.

Top of Page