jilltw has asked for the wisdom of the Perl Monks concerning the following question:

It's ALMOST working... I have a flat file (in $tmp_file) with 63 rows, 2 fields of character data per row. The database allows bcp. I get 63 rows of NULLS in my database table (tmp_site_term), which matches the quantity of rows in the file.

Any ideas why this is not working? I know in standard bcp to Sybase, I need a fomat file... is there such a thing for this perl module?

Here's my code:
use Sybase::BCP; $bcp = new Sybase::BCP $user, $pwd, $server, $appname; $bcp->config(INPUT => $tmp_file, OUTPUT => 'css..tmp_site_term', ERRORS => 'bcp_errors'); $bcp->run;

Replies are listed 'Best First'.
Re: Sybase::BCP
by mpeppler (Vicar) on Nov 02, 2004 at 17:15 UTC
    The default for this module is to split the input row into fields using \t as the delimiter. What is the format of your input file?

    Michael

      Hi, thanks for replying.

      The input file ($tmp_file) was built earlier in this same script by reading yet another file and extracting the needed fields. Here's the code that reads the original file and writes $tmp_file:
      open FILE,"<$file"; open OUTFILE, ">$tmp_file"; while (<FILE>) { s/^ +//; s/ +$//; s/ +/,/g; ($bin,$tid,$len)=split /,/; $bin = '0'x(6-length($bin)).$bin if length($bin) < 6; $tid=substr($tid,-$len,$len); print OUTFILE "$bin\t$tid\n"; } close OUTFILE;
      The $tmp_file has a tab character between the two fields, $bin and $tid.

      Also, the database table being BCP'd into has two columns, bin is varchar(12) and tid is varchar(24).
        OK - off hand that looks good. Can you load that file using the normal bcp command? And when you load it via Sybase::BCP do you get all NULLs, or just one of the columns?

        Michael