Skip to Content.
Sympa Menu

freetds - [freetds] [PATCH] bcp columns too small

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Craig A. Berry" <craigberry AT mac.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] [PATCH] bcp columns too small
  • Date: Fri, 21 Jan 2005 22:48:13 -0600

I encountered a bug doing a bcp in with RC9's freebcp where a character
column in the client's charset occupies more space than the same column
in the server's charset. In my case, I've set the client charset to
UTF-8 and the server's is ISO-8859-1.

When dbconvert is called from _bcp_read_hostfile, it space fills up to
the length of curcol->column_size, which is determined from the client's
charset, but the data area is only allocated according to the server's
charset (curcol->on_server.column_size). So, for example, a char(6)
field in ISO-8859-1 could take up to 24 bytes in UTF-8. We only allocate
6 bytes (or 6 + 1?), but later space fill all 24 bytes, including 18
bytes that belong to something else. This obviously causes a memory
accesss error if we're lucky, or corrupted data if we're not.

The attached patch deals with the problem by modifying the way column
memory is allocated. It simply allocates based on whichever column size
is larger, server or client.

--- src/dblib/bcp.c;-0 Wed Jan 5 19:40:03 2005
+++ src/dblib/bcp.c Fri Jan 21 19:00:05 2005
@@ -200,7 +200,11 @@
((TDS_NUMERIC *)
curcol->bcp_column_data->data)->precision = curcol->column_prec;
((TDS_NUMERIC *)
curcol->bcp_column_data->data)->scale = curcol->column_scale;
} else {
- curcol->bcp_column_data =
tds_alloc_bcp_column_data(curcol->on_server.column_size);
+ curcol->bcp_column_data =
+ tds_alloc_bcp_column_data(
+ curcol->on_server.column_size
< curcol->column_size
+ ? curcol->column_size
+ :
curcol->on_server.column_size );
}
}



  • [freetds] [PATCH] bcp columns too small, Craig A. Berry, 01/21/2005

Archive powered by MHonArc 2.6.24.

Top of Page