freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
[freetds] [PATCH bcp.c:_bcp_read_hostfile] don't trim trailing spaces when all spaces
- From: "Craig A. Berry" <craigberry AT mac.com>
- To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
- Subject: [freetds] [PATCH bcp.c:_bcp_read_hostfile] don't trim trailing spaces when all spaces
- Date: Sun, 18 Dec 2005 22:37:32 -0600
When bulking in character data, we currently trim trailing spaces, which
in general seems like the right thing to do with one exception. The
exception is when a field is all spaces; I don't think we should trim
those to nothing because then we end up inserting nulls in what may or
may not be nullable fields. The attached patch changes behavior so that
we only trim trailing spaces when one or more characters is not a space.
The behavior I'm proposing appears to be consistent with what I'm seeing
in an old Sybase client. I have not done any comparison with Microsoft
clients, but I think we can justify the change on the principle of
round-trip integrity. We should be able to bulk out a table, truncate
it, bulk it back in, and get the same thing we started with. If there
are non-nullable fields containing all spaces, that will not be true
before the patch, but it will be true after. Granted, application
validation logic that allows all spaces in a non-nullable field is
arguably lousy, but that's not a battle that bcp should be fighting.
--- src/dblib/bcp.c_orig Sun Dec 18 22:12:58 2005
+++ src/dblib/bcp.c Sun Dec 18 22:12:58 2005
@@ -1081,7 +1081,7 @@ _bcp_read_hostfile(DBPROCESS * dbproc, F
TDS_INT desttype;
BYTE *coldata;
- int i, collen, data_is_null;
+ int i, j, collen, data_is_null;
/* for each host file column defined by calls to bcp_colfmt */
@@ -1362,9 +1362,16 @@ _bcp_read_hostfile(DBPROCESS * dbproc, F
collen, (unsigned long
int) ftello(hostfile) - collen);
}
- /* trim trailing blanks from character data */
+ /* trim trailing blanks from character data
(unless it's all blanks) */
if (desttype == SYBCHAR || desttype ==
SYBVARCHAR) {
- bcpcol->bcp_column_data->datalen =
rtrim((char *) bcpcol->bcp_column_data->data,
bcpcol->bcp_column_data->datalen);
+ for (j = 0; j <
bcpcol->bcp_column_data->datalen; j++) {
+ if
(bcpcol->bcp_column_data->data[j] != ' ')
+ break;
+ }
+ if (j <
bcpcol->bcp_column_data->datalen) {
+
bcpcol->bcp_column_data->datalen = rtrim((char *)
bcpcol->bcp_column_data->data,
+
bcpcol->bcp_column_data->datalen);
+ }
}
}
if (!hostcol->column_error) {
- [freetds] [PATCH bcp.c:_bcp_read_hostfile] don't trim trailing spaces when all spaces, Craig A. Berry, 12/18/2005
Archive powered by MHonArc 2.6.24.