Update: The wrappers mentioned below are released as: DBIx::BulkUtil. Sybase bcp, Oracle sqlldr, and SybaseIQ "LOAD TABLE" are covered.
Go ahead and use bcp, you can even call it from perl. I have wrappers around bcp and sqlldr. No, sorry, I can't share them. Well, here's a bit of the bcp method:
sub bcp_in {
my $self = shift;
my $opts = (ref $_[-1]) ? pop @_ : {};
my ( $table, $file, $dir ) = @_;
# bcp_out is just bcp_in called with $dir = 'out'
$file ||= "$table.bcp";
$dir ||= 'in';
...snip
my $pid = open(my $fh, "-|");
confess "Can't fork: $!" unless defined $pid;
# UTF-8 doesn't work on HP - default is roman8
unless ($pid) {
# Enclose in block so we don't get exec warning
my $commit_size = $opts->{CommitSize} || 1000;
my @max_errors = $opts->{MaxErrors} ? (-m => $opts->{MaxErrors} )
+ : ();
my @header_opt = ($opts->{Header} && $dir eq 'in') ? (-F => $opts-
+>{Header}+1) : ();
{exec("bcp", $bcp_table, $dir, $file,
-U => $user,
-P => $self->{PASSWORD},
# -J => "utf8",
-S => $server,
"-c",
-t => $delimiter,
-r => $row_delimiter,
-b => $commit_size,
@header_opt,
@id_opt,
@max_errors,
)};
warn "Could not exec bcp: $!\n";
exit 1;
}
my $rows;
local ($_, $.);
while (<$fh>) {
print;
$rows = $1 if /^(\d+) rows copied/;
}
close $fh;
confess "BCP error" unless defined $rows;
return $rows;
}
|