Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have written the below Perl script to extract data from a pipe delimited text file to an Access database.
I am currently running this script from a batch file which has a single statement: perl perlscript2.txt where perlscript2.txt is the pipe delimited text file which looks like this:
I keep getting an error message: 'DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement'1009087|10/02/03|abbcdef|1124567|5679.34 1998023|12/06/02|rrrasdd|7468758|300.78
My code looks like this:
# !/usr/bin/perl -w use DBI qw(:sql_types); use DBD::ODBC; $dsn = "dbi:ODBC:Daily_Rec"; $dbh = DBI->connect($dsn,' ',' ', {RaiseError=>1,PrintError=>1,AutoCommit=>1} ); open(DAT, "c:/Temp/heldreceipts_TempFile.txt") || die "could not open Held Receipts file"; while(<DAT>) { chomp; @line = split(/\|/, $_); $var1=$line[0]; $var2=$line[1]; $var3=$line[2]; $var4=$line[3]; $var5=$line[4]; $var6=$line[5]; $var7=$line[6]; $var8=$line[7]; $query=qq{insert into Held_Receipts values (?,?,?,?,?,?,?,?)}; $sth = $dbh->prepare($query) or die "cannot prepare query"; $sth->execute($var1, $var2, $var3, $var4, $var5, $var6, $var7, $var8) or $DBI::err and die $DBI::errstr; } $sth->finish(); $dbh->disconnect();
when I print out $dbh i get HASH along with numbers in brackets (which means the $dbh part works fine right?).
Any help on resolving this issue will be greatly appreciated!!! Thanks!
update (broquaint): added <code> tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting data from a pipe delimited text file into a table in Access
by pfaut (Priest) on May 03, 2003 at 02:01 UTC | |
by Anonymous Monk on May 05, 2003 at 13:14 UTC | |
|
Re: Extracting data from a pipe delimited text file into a table in Access
by TVSET (Chaplain) on May 03, 2003 at 01:48 UTC | |
by Anonymous Monk on May 05, 2003 at 13:04 UTC | |
|
Re: Extracting data from a pipe delimited text file into a table in Access
by cciulla (Friar) on May 05, 2003 at 15:28 UTC | |
by Anonymous Monk on May 05, 2003 at 17:16 UTC | |
by cciulla (Friar) on May 05, 2003 at 18:17 UTC |