Skip to Content.
Sympa Menu

freetds - Re: [freetds] A couple of bugs in 0.91 with dblib bcp library

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Thompson, William" <bill.d.thompson AT baml.com>
  • To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] A couple of bugs in 0.91 with dblib bcp library
  • Date: Mon, 23 May 2011 09:54:10 +0100

Hi Guys,

Thanks for your input on this. Of course you're right on the bcp_done() front.
I'll try and eliminate the extra call to bcp_done() from my application.
It was of course lazy programming in the first place, not mine I'll add.

Another small issue which kind of follows on from the _bcp_get_term_var()
issue though:
I've fixed the problem, but I'm not sure if it's the *right* fix, and I'm
puzzled by what's happening.
perhaps someone can shed some light...

So we have the following code (with some debug additions of mine) in
_bcp_get_col_data():

dataptr = (BYTE *) bindcol->column_varaddr;

data_is_null = 0;
collen = 0;

/* If a prefix length specified, read the correct amount of data. */

if (bindcol->bcp_prefix_len > 0) {
...
}
printf("BILL after bcp_prefix_len (%d) column_bindlen = %d, collen =
%d\n",
bindcol->bcp_prefix_len, bindcol->column_bindlen, collen);

/* if (Max) column length specified take that into consideration. */
if (!data_is_null && bindcol->column_bindlen >= 0) {
if (bindcol->column_bindlen == 0)
data_is_null = 1;
else {
if (collen)
collen = (int) ((bindcol->column_bindlen <
(TDS_UINT)collen) ? bindcol->column_bindlen : (TDS_UINT)collen);
else
collen = (int) bindcol->column_bindlen;
}
}
printf("BILL 2 bcp_prefix_len (%d) column_bindlen = %d, collen =
%d\n",
bindcol->bcp_prefix_len, bindcol->column_bindlen, collen);

desttype = tds_get_conversion_type(bindcol->column_type,
bindcol->column_size);

/* Fixed Length data - this overrides anything else specified */
coltype = bindcol->column_bindtype == 0 ? desttype :
bindcol->column_bindtype;
if (is_fixed_type(coltype)) {
collen = tds_get_size_by_type(coltype);
}
printf("BILL 3 bcp_prefix_len (%d) column_bindlen = %d, collen =
%d\n",
bindcol->bcp_prefix_len, bindcol->column_bindlen, collen);

/* read the data, finally */
if (bindcol->bcp_term_len > 0) { /* terminated field */
bytes_read = _bcp_get_term_var(dataptr, (BYTE
*)bindcol->bcp_terminator, bindcol->bcp_term_len);
printf("BILL bytes read = %d\n", bytes_read);

/* CHANGED */ if (collen > 0) /* FROM if (collen) */
collen = (bytes_read < collen) ? bytes_read : collen;
else
collen = bytes_read;

if (collen == 0)
data_is_null = 1;
}

if (data_is_null) {
bindcol->bcp_column_data->datalen = 0;
bindcol->bcp_column_data->is_null = 1;
} else {
if ((converted_data_size =
dbconvert(dbproc, coltype,
(BYTE *) dataptr, collen,
desttype, bindcol->bcp_column_data->data,
bindcol->column_size)) == FAIL) {
printf("here %d\n", collen);
return TDS_FAIL;
}

bindcol->bcp_column_data->datalen = converted_data_size;
bindcol->bcp_column_data->is_null = 0;
assert(converted_data_size > 0);
}

With the prior fix in place in _bcp_get_term_var, I get the following debug
output, in a case where a character field was being processed, and it
consisted entirely of '\0's...

BILL after bcp_prefix_len (0) column_bindlen = -1, collen = 0
BILL 2 bcp_prefix_len (0) column_bindlen = -1, collen = -1
BILL 3 bcp_prefix_len (0) column_bindlen = -1, collen = -1
BILL bytes read = 0

My original problem was that dbconvert() (at the end of this snippet) was
getting called with collen = -1 and was failing.
I fixed that by changing the line marked "CHANGED" above. So far so good.
It now works, and the field gets rightly treated as NULL and dbconvert is not
called.
I'm pretty sure this fix is correct, as the intent of that block of code is
reasonably clear, namely:

"if I've been given a collen for the data, but the length of the data I've
read is less than that collen, then I'll set collen to reflect the actual
length of the data I'm going to process"

However, I'm now puzzled about my debug output "BILL 2"...
How on earth did collen get set to -1, when the only possible place it could
get set is within the code following this if statment:

if (!data_is_null && bindcol->column_bindlen >= 0) {

when just before this statement, column_bindlen is demonstrably -1 ???

Has anyone got any ideas ? have I missed something blindingly obvious ?

----------------------------------------------------------------------
This message w/attachments (message) is intended solely for the use of the
intended recipient(s) and may contain information that is privileged,
confidential or proprietary. If you are not an intended recipient, please
notify the sender, and then please delete and destroy all copies and
attachments, and be advised that any review or dissemination of, or the
taking of any action in reliance on, the information contained in or attached
to this message is prohibited.
Unless specifically indicated, this message is not an offer to sell or a
solicitation of any investment products or other financial product or
service, an official confirmation of any transaction, or an official
statement of Sender. Subject to applicable law, Sender may intercept,
monitor, review and retain e-communications (EC) traveling through its
networks/systems and may produce any such EC to regulators, law enforcement,
in litigation and as required by law.
The laws of the country of each sender/recipient may impact the handling of
EC, and EC may be archived, supervised and produced in countries other than
the country in which you are located. This message cannot be guaranteed to be
secure or free of errors or viruses.

References to "Sender" are references to any subsidiary of Bank of America
Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are
Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a
Condition to Any Banking Service or Activity * Are Not Insured by Any Federal
Government Agency. Attachments that are part of this EC may have additional
important disclosures and disclaimers, which you should read. This message is
subject to terms available at the following link:
http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you
consent to the foregoing.




Archive powered by MHonArc 2.6.24.

Top of Page