his is an extension of the DB-API 2.0 specification.
This object provides an interface to the Sybase bulkcopy functionality.
CS_BLK_INthen the sequence passed as the data argument is sent as one row to the server. If the direction is
CS_BLK_OUTthen one row will be returned from the server. If there are no more rows,
done()must be called (or the
Bulkcopyobject destroyed) to flush any outstanding cached rows to the DB. In addition, any other operation on the associated
Connectionobject will fail until done is called.
Bulkcopyobject should be created with the
CS_BLK_OUTdirection argument. Intermixed use of the iterator returned from __iter__ and the rowxfer to retrieve rows is supported; both use the same underlying function and will return all rows without missing or duplicating any row.
An example of using the
Bulkcopy class follows:
from Sybase import * c = connect('server', 'user', 'password', bulkcopy=1, auto_commit=1); c.execute("Create table #b(a int, b varchar(10), c float)") b = c.bulkcopy('#b') # CS_BLK_IN is default for r in range(32): b.rowxfer([r, ("xxx%d" % r), r * 0.1]) if r % 5 == 4: ret = b.batch() print "post batch, batch was", ret, "count = ", b.totalcount ret = b.done() print "post done, last batch was", ret, "count = ", b.totalcount for r in c.bulkcopy('#b', out=1): print r