No subject
Fri May 2 19:13:14 EDT 2003
the protocol (inbound) is basically an instruction header followed by a
marked series of fields, where the marker indicates a size. The target
columns (and rows) are applied in order, and any failure to match buffer to
column leads to rejection of anything that follows until a new sequence is
begun. Do I have that right?
Bracketing:
I'd like to support batches, and to rewrite _bcp_exec_in in terms of
bcp_sendrow. To do that, (assuming it's possible) I have to understand how
to bracket calls to the TDS. _bcp_exec_in seems to boil down to:
1. out_flag = 0x07
2a. tds_put_smallint(tds,row_size);
2b. tds_put_n(tds,rowbuffer,row_size);
3. tds_flush_packet
4. look for TDS_DONE_TOKEN
5. tds_process_end
Is there a smaller unit of work than that? IOW, does every chunk of data
sent begin with 0x07 and end with tds_process_end? Is it tds_process_end
that actually commits the rows to the server?
Can I repeat these six steps every 1000 rows, say, or does something have to
be reinitialized?
Looking at tds/write.c, it looks like the author had in mind a sequence more
like:
1. tds_init_write_buf
2. tds_put_bulk_data (per column per row)
3. tds_flush_packet
4. look for TDS_DONE_TOKEN
5. tds_process_end
except that tds_put_bulk_data doesn't call tds_put_smallint. Is it broken?
TDS State:
If bcp_sendrow were implemented similar to the above, it would leave the TDS
in a partially written state. A call to dbsqlexec, for instance, before
calling bcp_done would confuse the TDS. That's probably OK, but it should
be possible to cancel a batch dbcancel. I don't know how to cancel flushed
packets.
One solution would be to have bcp_sendrow buffer all its data (pending
bcp_batch or bcp_done) without talking to the TDS. If I knew how to
properly construct a TDS buffer of bulk rows, bcp_batch could make just one
call to tds_put_bulk_data, then flush the packet and wait for
TDS_DONE_TOKEN. Is that right, and if so, is there any way besides reading
the tds source code to learn how to do that?
Thanks for any guidance.
--jkl
-----Original Message-----
From: Brian Bruns [mailto:camber at ais.org]
Sent: September 1, 2000 8:02 AM
To: TDS Development Group
Subject: [freetds] Re: bcp from program variables
I wrote the original bcp stuff under contract, so I did little more than
what was necessary to fulfill that. I'd be happy to try and remember all
the gory details though. If you have specific questions, just post them
on the list and I'll try to answer.
Brian
On Thu, 31 Aug 2000, Lowden, James K wrote:
> Hello,
>
> A perusal of bcp.c told me I should have looked more closely at the code
> before asking for advice on how to use bcp_sendrow et. al. The code is
> obviously stubbed out.
>
> I've taken a crack at filling in the stubs. There are a couple of errors
in
> the functional prototypes, and bcp_batch in particular needs tds support.
> Most of the functionality can be borrowed from the existing static
> functions.
>
> I've got it working up to the very end, when my version of bcp_done (taken
> directly from the tail of _bcp_exec_in) chokes on an error token (170)
> instead of TDS_DONE_TOKEN. Almost certainly, the problem lies in the
> sequence of calls to the tds layer or in the bindings (always the most
> tedious part of db-lib programming).
>
> Does anyone there want to see this functionality added to the dblib code?
> Would someone be willing to discuss some of the details off-line? I'm
> hoping to implement the db-lib functions by talking to someone who knows
the
> tds api. Or who can point me to documents not posted on the web site.
>
> My lawyer says he's never free but he's always reasonable. Me, just this
> once, I'm offering both. Any takers? It *could* be fun.
>
> --jkl
>
>
>
>
>
---
You are currently subscribed to freetds as: LowdenJK at bernstein.com
To unsubscribe, forward this message to
$subst('Email.Unsub')
------_=_NextPart_001_01C0143B.69CF1E42
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2651.65">
<TITLE>Re: bcp from program variables</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2>Specifics are no problem. I apologize, though, =
because it's hard to be brief and clear. </FONT>
</P>
<P><FONT SIZE=3D2>From what little I once knew about TDS and what I've =
gleaned from the code, the protocol (inbound) is basically an =
instruction header followed by a marked series of fields, where the =
marker indicates a size. The target columns (and rows) are =
applied in order, and any failure to match buffer to column leads to =
rejection of anything that follows until a new sequence is begun. =
Do I have that right? </FONT></P>
<P><FONT SIZE=3D2>Bracketing:</FONT>
</P>
<P><FONT SIZE=3D2>I'd like to support batches, and to rewrite =
_bcp_exec_in in terms of bcp_sendrow. To do that, (assuming it's =
possible) I have to understand how to bracket calls to the TDS. =
_bcp_exec_in seems to boil down to:</FONT></P>
<P> <FONT =
SIZE=3D2>1. out_flag =3D 0x07</FONT>
<BR> <FONT =
SIZE=3D2>2a. =
tds_put_smallint(tds,row_size);</FONT>
<BR> <FONT =
SIZE=3D2>2b. =
tds_put_n(tds,rowbuffer,row_size);</FONT>
<BR> <FONT =
SIZE=3D2>3. tds_flush_packet</FONT>
<BR> <FONT =
SIZE=3D2>4. look for =
TDS_DONE_TOKEN</FONT>
<BR> <FONT =
SIZE=3D2>5. tds_process_end</FONT>
</P>
<P><FONT SIZE=3D2>Is there a smaller unit of work than that? IOW, =
does every chunk of data sent begin with 0x07 and end with =
tds_process_end? Is it tds_process_end that actually commits the =
rows to the server? </FONT></P>
<P><FONT SIZE=3D2>Can I repeat these six steps every 1000 rows, say, or =
does something have to be reinitialized?</FONT>
</P>
<P><FONT SIZE=3D2>Looking at tds/write.c, it looks like the author had =
in mind a sequence more like:</FONT>
</P>
<P> <FONT =
SIZE=3D2>1. tds_init_write_buf</FONT>
<BR> <FONT =
SIZE=3D2>2. tds_put_bulk_data (per column =
per row)</FONT>
<BR> <FONT =
SIZE=3D2>3. tds_flush_packet</FONT>
<BR> <FONT =
SIZE=3D2>4. look for =
TDS_DONE_TOKEN</FONT>
<BR> <FONT =
SIZE=3D2>5. tds_process_end</FONT>
</P>
<P><FONT SIZE=3D2>except that tds_put_bulk_data doesn't call =
tds_put_smallint. Is it broken? </FONT>
</P>
<P><FONT SIZE=3D2>TDS State:</FONT>
</P>
<P><FONT SIZE=3D2>If bcp_sendrow were implemented similar to the above, =
it would leave the TDS in a partially written state. A call to =
dbsqlexec, for instance, before calling bcp_done would confuse the =
TDS. That's probably OK, but it should be possible to cancel a =
batch dbcancel. I don't know how to cancel flushed packets. =
</FONT></P>
<P><FONT SIZE=3D2>One solution would be to have bcp_sendrow buffer all =
its data (pending bcp_batch or bcp_done) without talking to the =
TDS. If I knew how to properly construct a TDS buffer of bulk =
rows, bcp_batch could make just one call to tds_put_bulk_data, then =
flush the packet and wait for TDS_DONE_TOKEN. Is that right, and =
if so, is there any way besides reading the tds source code to learn =
how to do that?</FONT></P>
<P><FONT SIZE=3D2>Thanks for any guidance.</FONT>
</P>
<P><FONT SIZE=3D2>--jkl</FONT>
<BR> =20
<BR> =20
<BR><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: Brian Bruns [<A =
HREF=3D"mailto:camber at ais.org">mailto:camber at ais.org</A>]</FONT>
<BR><FONT SIZE=3D2>Sent: September 1, 2000 8:02 AM</FONT>
<BR><FONT SIZE=3D2>To: TDS Development Group</FONT>
<BR><FONT SIZE=3D2>Subject: [freetds] Re: bcp from program =
variables</FONT>
</P>
<BR>
<BR>
<P><FONT SIZE=3D2>I wrote the original bcp stuff under contract, so I =
did little more than</FONT>
<BR><FONT SIZE=3D2>what was necessary to fulfill that. I'd be =
happy to try and remember all</FONT>
<BR><FONT SIZE=3D2>the gory details though. If you have specific =
questions, just post them</FONT>
<BR><FONT SIZE=3D2>on the list and I'll try to answer.</FONT>
</P>
<P><FONT SIZE=3D2>Brian</FONT>
</P>
<P><FONT SIZE=3D2>On Thu, 31 Aug 2000, Lowden, James K wrote:</FONT>
</P>
<P><FONT SIZE=3D2>> Hello, </FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> A perusal of bcp.c told me I should have looked =
more closely at the code</FONT>
<BR><FONT SIZE=3D2>> before asking for advice on how to use =
bcp_sendrow et. al. The code is</FONT>
<BR><FONT SIZE=3D2>> obviously stubbed out. </FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> I've taken a crack at filling in the =
stubs. There are a couple of errors in</FONT>
<BR><FONT SIZE=3D2>> the functional prototypes, and bcp_batch in =
particular needs tds support.</FONT>
<BR><FONT SIZE=3D2>> Most of the functionality can be borrowed from =
the existing static</FONT>
<BR><FONT SIZE=3D2>> functions. </FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> I've got it working up to the very end, when my =
version of bcp_done (taken</FONT>
<BR><FONT SIZE=3D2>> directly from the tail of _bcp_exec_in) chokes =
on an error token (170)</FONT>
<BR><FONT SIZE=3D2>> instead of TDS_DONE_TOKEN. Almost =
certainly, the problem lies in the</FONT>
<BR><FONT SIZE=3D2>> sequence of calls to the tds layer or in the =
bindings (always the most</FONT>
<BR><FONT SIZE=3D2>> tedious part of db-lib programming). =
</FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> Does anyone there want to see this =
functionality added to the dblib code?</FONT>
<BR><FONT SIZE=3D2>> Would someone be willing to discuss some of the =
details off-line? I'm</FONT>
<BR><FONT SIZE=3D2>> hoping to implement the db-lib functions by =
talking to someone who knows the</FONT>
<BR><FONT SIZE=3D2>> tds api. Or who can point me to documents =
not posted on the web site. </FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> My lawyer says he's never free but he's always =
reasonable. Me, just this</FONT>
<BR><FONT SIZE=3D2>> once, I'm offering both. Any =
takers? It *could* be fun.</FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> --jkl</FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> </FONT>
<BR><FONT SIZE=3D2>> </FONT>
</P>
<BR>
<P><FONT SIZE=3D2>---</FONT>
<BR><FONT SIZE=3D2>You are currently subscribed to freetds as: =
LowdenJK at bernstein.com</FONT>
<BR><FONT SIZE=3D2>To unsubscribe, forward this message to =
$subst('Email.Unsub')</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C0143B.69CF1E42--
More information about the FreeTDS
mailing list