Skip to Content.
Sympa Menu

freetds - Re: [freetds] Freebcp and column names with spaces

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Paul Rensing <paulrensing AT verizon.net>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Freebcp and column names with spaces
  • Date: Thu, 13 Jan 2005 16:17:03 -0500

I experimented a little, and asked our (real) DB people. Using double-
quotes does not work, but what does work is using square-brackets ("[]")
around the column names.

I have attached a patch file for bcp.c. This is against 0.62.4. I have
only tried it against MS SQLserver.

Paul Rensing

On Thu, 2005-01-13 at 14:59 -0500, Paul Rensing wrote:
> FreeTDS people,
>
> FreeTDS has been working very well for me. I am talking to a MS
> SQLServer (version 2003, I think) with the Python drivers, and it works
> well.
>
> However, now I am trying to use freebcp to improve the throughput to
> build a big table (SQL INSERT statements are just too slow). I started
> testing it and immediately found a problem.
>
> Many of my column names contain embedded spaces (please do tell me not
> to do that; there is a reason). The internals of freebcp do not quote
> the column names. The routine _bcp_build_bulk_insert_stmt in dblib/bcp.c
> simply copies in the column name without examining it.
>
> I did try turning the TDS version down to 4.2, and the freebcp run
> succeeded, but then my normal code does not run, plus it appears that
> some of the fields were mangled during the insert.
>
> Is this a bug? Can you just add quotes around the column name? Or, am I
> missing something?
>
> Thanks very much for the help.
>
> Paul Rensing
> paulrensing AT verizon.net

--
Paul Rensing <paulrensing AT verizon.net>
*** bcp.c~	Mon Jan  5 21:40:11 2004
--- bcp.c	Thu Jan 13 16:07:56 2005
***************
*** 1965,1971 ****
  		return FAIL;
  	}
  
! 	if (clause->cb < strlen(clause->pb) + strlen(bcpcol->db_name) + strlen(column_type) + ((first) ? 2 : 4)) {
  		unsigned char *temp = malloc(2 * clause->cb);
  
  		assert(temp);
--- 1965,1971 ----
  		return FAIL;
  	}
  
! 	if (clause->cb < strlen(clause->pb) + strlen(bcpcol->db_name) + strlen(column_type) + ((first) ? 4 : 6)) {
  		unsigned char *temp = malloc(2 * clause->cb);
  
  		assert(temp);
***************
*** 1979,1986 ****
  	if (!first)
  		strcat(clause->pb, ", ");
  
  	strcat(clause->pb, bcpcol->db_name);
! 	strcat(clause->pb, " ");
  	strcat(clause->pb, column_type);
  
  	return SUCCEED;
--- 1979,1987 ----
  	if (!first)
  		strcat(clause->pb, ", ");
  
+ 	strcat(clause->pb, "[");
  	strcat(clause->pb, bcpcol->db_name);
! 	strcat(clause->pb, "] ");
  	strcat(clause->pb, column_type);
  
  	return SUCCEED;



Archive powered by MHonArc 2.6.24.

Top of Page