On Tue, Jul 13, 2004 at 03:26:13PM +0200, Michael Peppler wrote:
> [ Posted this to the sybperl-l mailing list a little while ago. I guess 
>   there may be some users of DBD::Sybase here that would be interested 
>   in this. Note that this will probably NOT work with FreeTDS unless 
>   their BLK API is fully functional.]
> 
> I've just uploaded DBD::Sybase 1.04.2 to
> http://www.peppler.org/downloads/
> 
> This is a test version that includes support for using the BLK
> (bulk-load) API from DBI's prepare/execute calls.

Great. Thanks Michael.

> Sample code:
> 
>   my $dbh = DBI->connect('dbi:Sybase:server=MY_SERVER;bulkLogin=1',
> $user, $pwd);
>   my $sth = $dbh->prepare('insert the_table values(?, ?, ?, ?, ?)",
>                           syb_bcp_attribs => { identity_flag => 0,
>                                                identity_column => 0 }});
>   while(<DATA>) {
>     chomp;
>     my @row = split(/\|/, $_);   # assume a pipe-delimited file...
>     $sth->execute(@row);
>   }
>   $dbh->commit;
>   print "Sent ", $sth->rows, " to the server\n";
>   $sth->finish;

> AutoCommit is ignored for this operation (it is always off).

Could you make it warn if AutoCommit is on, and include $dbh->begin_work
in your examples? That would make the code more portable.

> Calling $dbh->commit will commit any non-committed rows, and will fail if any
> row in the batch fails (i.e. duplicate insert error).
> Calling $dbh->rollback will cancel the current batch, *and* will cancel
> the BCP operation (i.e. no further rows can be inserted).

So the $sth isn't usable any more. Okay.

> $sth->rows returns the number of rows committed for the latest call to
> $dbh->commit().
> $sth->execute() will fail if there are any data conversion errors.

> $sth->finish will rollback any non-committed rows.

What's the role of finish() here? Is it needed?

Tim.

Reply via email to