Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I don't know what Access is complaining about but here's some hints to clean up your code.

  • You don't need a 'use' statement for the DBD backend you will be using. DBI takes care of loading a driver based on the connect string you provide.
  • Prepare your statements outside the loop, execute them inside. Once prepared, a statement can be reused an unlimited number of times.
  • You can take the list returned by split and pass it directly to $sth->execute(). You don't have to use all of those nasty looking scalars (BTW, ++ for using placeholders).
  • You should add 'use strict' to the top of your script and declare your variables. This will help you catch a lot of errors at compile time.
# !/usr/bin/perl -w use strict; use DBI qw(:sql_types); my $dsn = "dbi:ODBC:Daily_Rec"; my $dbh = DBI->connect($dsn,'','', {RaiseError=>1,PrintError=>1,AutoCommit=>1} ); open(DAT, "c:/Temp/heldreceipts_TempFile.txt") or die "could not open Held Receipts file: $!"; my $query = qq{insert into Held_Receipts values (?,?,?,?,?,?,?,?)}; my $sth = $dbh->prepare($query) or die "cannot prepare query: $DBI::errstr"; while(<DAT>) { chomp; my @line = split /\|/; $sth->execute(@line) or die "Execute error: $DBI::errstr"; } $sth->finish(); $dbh->disconnect();

Update: I think TVSET's advice is good. If you can, attempt to run the statement through some other interface and see if it complains, too.

90% of every Perl application is already written.
dragonchild

In reply to Re: Extracting data from a pipe delimited text file into a table in Access by pfaut
in thread Extracting data from a pipe delimited text file into a table in Access by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-24 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found