Skip to Content.
Sympa Menu

freetds - RE: [freetds] Status: bcp

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Thompson, Bill D (London)" <bill_d_thompson AT ml.com>
  • To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] Status: bcp
  • Date: Fri, 19 Dec 2003 14:07:17 -0000

James,

I think the best solution is your first one, namely "tds7_put_bcpcol()
mustn't check if its target is nullable".
This condition is already covered for freebcp, i.e when reading data from a
file. see _bcp_read_hostfile() :

if (bcpcol->data_size == 0) { /* Are we trying to insert a NULL ? */
if (!bcpcol->db_nullable) {
/* too bad if the column is not nullable */
hostcol->column_error = HOST_COL_NULL_ERROR;
*row_error = 1;
_bcp_err_handler(dbproc, SYBEBCNN);
}
}

we just need to put the same check into _bcp_get_prog_data().
That way the row is aborted before we get as far as writing to the wire...
I'd suggest the following modification at the bottom of
_bcp_get_prog_data()...

} else {

if (hostcol->tab_colnum) {
if (data_is_null) {
bcpcol->data_size = 0;
} else {
desttype = tds_get_conversion_type(bcpcol->db_type,
bcpcol->db_length);

if ((converted_data_size =
dbconvert(dbproc,
hostcol->datatype,
(BYTE *) dataptr, collen,
desttype, bcpcol->data, bcpcol->db_length))
== FAIL) {
return (FAIL);
}

bcpcol->data_size = converted_data_size;
}
}
}

+ if (bcpcol->data_size == 0) { /* Are we trying to insert a NULL ?
*/
+ if (!bcpcol->db_nullable) {
+ /* too bad if the column is not nullable */
+ _bcp_err_handler(dbproc, SYBEBCNN);
+ return (FAIL);
+ }
+ }
}
return SUCCEED;
}

Then we can remove the check from the tds7_put_bcpcol function.


Another couple things with your bcp test program

1) My ancient C compiler complains about "bcp.h" - it doesn't like newlines
in string literals:

2) your test table is not compatile with my Sybase. Null bit fields are not
supported for starters:

1> create table bill (col1 bit null )
2>
Msg 2718, Level 16, State 1:
Server 'LGQASYB6_2', Line 1:
Column or parameter #1: -- can't specify Null values on a column of type
BIT.
1>


BIll




> -----Original Message-----
> From: James K. Lowden [SMTP:jklowden AT schemamania.org]
> Sent: 19 December 2003 00:18
> To: FreeTDS Development Group
> Subject: Re: [freetds] Status: bcp
>
> On Thu, 18 Dec 2003, "Thompson, Bill D (London)" <bill_d_thompson AT ml.com>
> wrote:
> > if (_bcp_get_prog_data(dbproc) == SUCCEED) {
> >
> > if (IS_TDS7_PLUS(tds)) {
> > tds_put_byte(tds, row_token); /* 0xd1 */
> >
> > for (i = 0; i < dbproc->bcp.db_colcount; i++) {
> >
> > /* send the data for each column */
> > ret = tds7_put_bcpcol(tds, dbproc->bcp.db_columns[i]);
> >
> > if (ret == TDS_FAIL) {
> > _bcp_err_handler(dbproc, SYBEBCNN);
> +++ return FAIL;
> > }
> >
> > }
> > return SUCCEED;
> >
> > If the error condition is hit in tds7_put_bcpcol a BAD ROW will be
> > constructed (the bad column having neen nissed out....)
>
> I looked at fixing this, Bill, but it a problem is. It's easy to insert
> the line, above, but how to reset the TDS buffer? We've already plugged
> it with 0xd1 and N columns (well, i, really). For a really wide row, that
> could mean packets were already shipped to the server.
>
>
> The straightforward answer would be that tds7_put_bcpcol() mustn't check
> if its target is nullable. Just construct the row according to the data,
> and let the server reject them. Are the vendors' libraries any smarter
> than that?
>
> The alternative, which I like better, is to write bcp_exec atop bcp_bind,
> bcp_sendrow, and bcp_batch. These of course need tds names and should be
> in src/tds/bcp.c (which doesn't exist yet). But they define the core
> functionality of bcp. Everything else is setup and window dressing.
>
> Of course, writing bcp_exec in terms of bcp_bind means we build a row
> image in memory before writing it to the server all at once (with
> tds_put_n). That has ramification for blobs. Here's my suggestion:
> mmap(2). Use a memory mapped file to hold the row image. What do you
> think?
>
> --jkl
>
>
> _______________________________________________
> FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds





Archive powered by MHonArc 2.6.24.

Top of Page