Dear All,
(NT4 SP6 Activeperl 5.6.0 build 623)

I am wanting to load data from a text file into a database (Access).  The
files contain a number of columns (up to 80 in some cases).  As a result I
am trying to do the following.

<Code>

use strict;
use DBI qw(:sql_types);
use DBD::ODBC;

my $dsn = "Test";
my $dbh = DBI->connect("dbi:ODBC:$dsn");
my $sth = $dbh->prepare(qq{insert into table1 (iID,sString,dDate) values
(?,?,?)});
$sth->bind_param(1,1,SQL_INTEGER);
$sth->bind_param(1,1,SQL_VARCHAR);
$sth->bind_param(1,1,SQL_DATE);

while(<DATA>){
  my @Fields = split(/,/);
  $sth->execute(@Fields);
}

__DATA__
,No ID,2002-03-03

</Code>

When I run this I get
DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access
Driver]Invalid
character value for cast specification (null) (SQL-22005)(DBD:
st_execute/SQLExec
ute err=-1) at N:\perl\test.pl line 14, <DATA> line 1.

i.e. $Fields[0] is not undef

I am trying to avoid doing the following on 80 columns

....
my ($col1,$col2,.....) = split(/,/);
$col1 = undef unless($col1);
....

I realise that this is not strictly a DBI problem, really 'split' should
return undef's, shouldn't it?  Anyway I wondered if anybody else has come
across this problem and solved it.

Cheers,

Michael

Reply via email to