in reply to Re: Sybase::BCP
in thread Sybase::BCP

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).

Replies are listed 'Best First'.
Re^3: Sybase::BCP
by mpeppler (Vicar) on Nov 03, 2004 at 14:44 UTC
    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

      I did a bcp of the file (/tmp/css.txt) into the DB from the Unix command line & the file loaded properly, all 63 rows as they should be. This was walking through the interactive BCP utility, and I saved off the format file it created.

      When I use the perl script with Sybase::BCP, then isql from the command line to do "select * from tmp_site_term" all I see are NULLS in both columns.

      Thanks.
        OK - two more things for you to test:

        First, try the same thing with Sybase::BLK instead of Sybase::BCP. BLK uses the CT-lib based API which is required if your target table has any new features (such as row-level locking). The Sybase::BLK module has the same syntax as Sybase::BCP.

        Second, try loading the data via bcp using this command line:

        bcp db..table in tmpfile -c -Uuser -Ppwd -Ssrv
        (obviously using correct values for "db", "table", etc.) That should mimic what Sybase::BLK will try to do (i.e. split on the tab and use \n for the row separator).

        Michael

        update Sybase::BLK is part of sybperl, so you should already have it installed...