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

This is partial code, which does not work. I am not sure how to added the text line to access table. Any help?
my $line; while ($line = <lbc*.txt>){ open (LOGFILE, "$line") || die "Can't open LOGFILE \n"; while(<LOGFILE>) { my($tdater, $filen, $ttot, $ttot2, $logfilen, $tots, $diff) = split(/\|/); chomp ($tdater); chomp ($filen); chomp ($ttot); chomp ($ttot2); chomp ($logfilen); chomp ($tots); chomp ($diff); print ("$tdater", "$filen", "\n"); my $theyear = 2000 + substr $tdater,6,2; my $themo = substr $tdater, 0, 2; my $thedt = substr $tdater, 3, 2; my $thedate = $theyear . "/" . $themo . "/" . $thedt; my $quer1="INSERT into logfile ('Date Send', 'Certificate file', 'No of Certificate', PDFNO, 'log + file', 'Notice sent', Difference) VALUES ({d '$thedate'}, '$filen', '$ttot', '$ttot2', '$logfile +n', '$tots', '$diff')"; my $query = q! INSERT INTO logfile ("Date Send", "Certificate file") VALUES ({d '$thedate'}, $filen) !; if ( $db->Sql($query)) { print "error executing query [ \"$query\" ]\n"; print "Error: " . Win32::ODBC::Error() . "\n"; } } close(LOGFILE); }

Replies are listed 'Best First'.
Re: Add Text record to access table?
by dreadpiratepeter (Priest) on Feb 15, 2002 at 17:04 UTC
    I have the same comment as I had about your last post. What DB library are you using? It doesn't look like DBI.
    In DBI you would use placeholders to do what you want.

    -pete
    Entropy is not what is used to be.
Re: Add Text record to access table?
by Rich36 (Chaplain) on Feb 15, 2002 at 17:35 UTC
    What error are you getting?
    And what exactly is this {d '$thedate'} in the code? I wonder if that's causing a problem in the SQL.
    Rich36
    There's more than one way to screw it up...

Re: Add Text record to access table?
by manoorani (Novice) on Feb 15, 2002 at 17:06 UTC
    I am using ODBC.
      You might want to look at DBI with DBD::ODBC. Many database do not allow the insertion of text and blob fields with straight insert statements (Informix, for one). In DBI one can use placeholders when inserting to do so. Placeholder will also automatically quote fields properly, removing another hassle.
      Assuming (and in all fairness I have not used it) that DBD::ODBC is as complete a driver as the others I have used (mysql, oracle, informix), you should find that it does what you want.
      It would lokk roughly like:
      my $dbh = DBI->connect(connect params...) or die "connect failed: $ +DBI::errstr"; $dbh->do("insert into table (a,b,c) values(?,?,?)",{}, 3,$x,$long_text_field_or_blob_data) or die "do failed: $DB +I::errstr";

      All the quoting and blob magic needed is done by the DBD driver.

      -pete
      Entropy is not what is used to be.
        What is connect param?
        Thanks pete, that helped.