|
|
sybperl-l Archive
Up Prev Next
From: mpeppler at itf dot ch (Michael Peppler)
Subject: BCP module
Date: Feb 16 1996 12:20PM
Hi...
I'm considering writing a (sort of) generalized bcp module for sybperl,
and I was wondering if you folks might have any comments...
It would go something like this:
#!/usr/local/bin/perl
use Sybase::Bcp;
$bhd = new Sybase::Bcp user, password;
# General configuration
$bhd->config(DATE => 'MMDDYYY', # default conversion pattern for date/time
NULL => '^$', # How are NULLs represented in the file
INPUT => 'file-name',
OUTPUT => 'table-name',
ERRORS => "bcp.err',
FIELDS => 10, # There are 10 columns in this file
SEPARATOR => '|'); # And they are separated using '|'
$bhd->describe(2, {TYPE => DATE }); # Tell bcp that field 2 is a DATE field
# The default parsing defined above
# would be applied.
$bhd->describe(3, {CALLBACK => \&munge_field_3});
# Tell bcp to call &munge_field_3 with the
# the content of the third field before
# sending the row.
$bhd->run;
__END__
By allowing callbacks before submitting data any conversions can be
made. Allowing a date conversion pattern makes it possible to import
dates that may be specified in incomplete or non standard form.
The run() method does all the parsing, etc. and re-tries failed batches
so that only the actual rows that cause problems (such as duplicate
keys) are not loaded (and are stored in the ERRORS file.)
Comments?
Michael
|