[freetds] ctlib bulk text copy segmentation fault

Patrick Dunnigan patrick.dunnigan at centivia.com
Mon Mar 7 15:53:32 EST 2005


I checked out RC10 and had the same problem.

I've gone further into the debugging and found what i think is the root 
cause. During the blk_init, there is a piece of code that looks like it 
initializes memory buffers for each column in the data, out to it's max 
length. I was able to get the bulk text insert to work when I changed the 
size of the allocation. Once I changed the number to something under 1 gig I 
was able to successfully insert the data (my data by the way was only 100 
bytes or less during testing this out).

             blk.c   blk_init  ----->

                if (is_numeric_type(curcol->column_type)) {
                        curcol->bcp_column_data = 
tds_alloc_bcp_column_data(sizeof(TDS_NUMERIC));
                        ((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);   <---- Line I 
commented out
                        curcol->bcp_column_data = 
tds_alloc_bcp_column_data(1048576*1007); 
<---- Max number I could allocate
                }


Now, I have 1 gig of RAM in this machine (I believe, see meminfo below) so 
that may be why it's barfing above the 1048576*1007 limit. But many machines 
will not have 2 gig (size of the SQL Server TEXT) free to allocate.

As a workaround, since I know the size of the data I'm going to transfer, 
I'm going to try allocation the sizeof the data going in as opposed to the 
size of the database column by adding a parameter onto blk_init (....., int 
datasize) . Please let me know of your opinion on this temp measure.

Thanks,
Patrick


----- Original Message ----- 
From: "Thompson, Bill D (London)" <bill_d_thompson at ml.com>
To: "FreeTDS Development Group" <freetds at lists.ibiblio.org>
Sent: Monday, March 07, 2005 1:04 PM
Subject: RE: [freetds] ctlib bulk text copy segmentation fault


Hi Patrick,

Thanks for your well researched and documented bug report.

I think it IS a bug. BCP of text data should indeed be possible,
although it is a (sometimes problematic) special case.

I'll look into the causes and advise (probably tomorrow)

Bill

-----Original Message-----
From: freetds-bounces at lists.ibiblio.org
[mailto:freetds-bounces at lists.ibiblio.org] On Behalf Of Patrick Dunnigan
Sent: 07 March 2005 17:17
To: freetds at lists.ibiblio.org
Subject: [freetds] ctlib bulk text copy segmentation fault


Hi All,
I am attempting to do a bulk copy IN in a SQL Server 2000 table that has
two columns, an INT and a TEXT using freeTDS  0.63RC9 on RH 7.3 using
TDS 8.

The binds seem to be returning properly. When I call the blk_rowxfer
function it produces a "segmentation fault". I have traced it down to
the cs_convert call performed inside _blk_get_col_data (as below) in
blk.c for the second column in the database table - the TEXT field.
Further the segmentation fault occurs because of the 6th parameter:
bindcol->bcp_column_data->data.

result = cs_convert(ctx, &srcfmt, (CS_VOID *) src, &destfmt, (CS_VOID *)
bindcol->bcp_column_data->data, &destlen);

Now when I do nothing but change the fieldtype in SQL Server to say
VARCHAR, the bulk copy works without modifying my bind parameters (which
are set to the Text variety. If I change the database field type back to
TEXT, it fails.

I know it's the bindcol->bcp_column_data->data parameter (pointer to the
destination data buffer) because I created a stub function with  printf
and return statement only inside and removed each parameter until it
successfully called the function and returned.

With this parameter in the cs_convert call, it does a segmentation fault
just by simply calling the function. The blk_bind for this column
appears to be functioning properly and is returning with a CS_SUCCEED.

Therefore my questions for the community are as such:
- Are bulk text inserts even possible with freeTDS and MSSQL?
- I've been through the examples and on the web, examples of TEXT bulk
copies are sparse. Any guidence?
- What other info can I provide? I can provide the code if needed, I
basically took the bulk copy in example from src/ctlib/unittests and
modified it for the text operation.

Thanks
Patrick
_______________________________________________
FreeTDS mailing list
FreeTDS at lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds
--------------------------------------------------------

If you are not an intended recipient of this e-mail, please notify the 
sender, delete it and do not read, act upon, print, disclose, copy, retain 
or redistribute it. Click here for important additional terms relating to 
this e-mail.     http://www.ml.com/email_terms/
--------------------------------------------------------

_______________________________________________
FreeTDS mailing list
FreeTDS at lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds




More information about the FreeTDS mailing list