David Wheeler wrote:

On Thursday, October 24, 2002, at 12:52  PM, Rudy Lippan wrote:

> Because the loop looked something like:
>
> for (qw(this is a test)) {
>      $data .= $dbi->quote($_);
> }
>
> so you would end up with: 'this''is''a''test', and since '' is just an
> escaped qoute, q{this'is'a'test} gets inserted into the db.


Oh, duh. The proper solution then should have been:

  while (my $rd = read $fh, $data2, 65536) {
      $data .= $data2;
      $datasize += $rd;
  }
  $data = $dbh->quote($data);

Sorry about that.

David

These fixes were needed, but there's more to it than that. Since the file I was inserting wasn't as big as 64k, the loop didn't execute more than once and yet the data inserted using $dbh->quote was 2 bytes larger than it should've been. A hex dump shows the intruders are one single quote at the beginning and one at the end of the file.

I have examined the output of $dbh->quote by writing it to a file (print $file $data) and I found that the intruding quotes were indeed added by $dbh->quote, instead of later by another session of quoting.

Crist�v�o

Reply via email to