Re: Cannot insert large files in MySQL from PERL

From: Michael A Chase tech (mchase_at_ix.netcom.com)
Date: 12/14/04


Date: Mon, 13 Dec 2004 18:26:13 -0800
To: OIT <lmaster1@broward.org>

On 12/13/2004 09:33 AM, OIT said:

> I am trying to save windump network trace files in MySQL. The following
> piece works, and am able to insert into MySQL, but only a small piece of
> this 50MB file is in there!!!

Is that a binary or text file? quote() is not likely to work correctly
on binary data.

> Does anybody know what would be truncating my file?
>
> open($fh, '12-6-2004---15-49-29' ) or die $!;
> read( $fh, $var, -s $fh);
>
> $sql = "INSERT INTO traces values (" . "'" . "$begin_datetime" . "'" . ","
> . "'" . "$end_datetime" . "'" . "," . "?" . "," . "'" . "$device_name" .
> "'" . "," . "'" . "$device_port" . "'" . ")" . ";" ;

$sql = "INSERT INTO traces values ('$begin_datetime','$end_datetime'," .
   "?,'$device_name','$device_port');";

It is not necessary to split the string up that much, all those dots
make my eyes cross and also make it hard to tell if the SQL is valid.

You should probably also pass the other values via placehloders.

> $sth = $dbh->prepare($sql);
> $file1=$dbh->quote("$var");
> $sth->bind_param( 1, $file1, SQL_LONGVARCHAR);

If you use a placeholder to pass the value, you shouldn't quote() it.

-- 
Mac :})
** I usually forward private questions to the appropriate mail list. **
Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.


Relevant Pages

  • Re: Cannot insert large files in MySQL from PERL
    ... >> I am trying to save windump network trace files in MySQL. ... > You should probably also pass the other values via placehloders. ... > Give a hobbit a ring and he eats fish for an age. ...
    (perl.dbi.users)
  • Re: Cannot insert large files in MySQL from PERL
    ... >> I am trying to save windump network trace files in MySQL. ... > You should probably also pass the other values via placehloders. ... > Give a hobbit a ring and he eats fish for an age. ...
    (perl.dbi.users)
  • Re: Cannot insert large files in MySQL from PERL
    ... I removed the quote, and set the max-packet allowed parameter as follows: ... >> I am trying to save windump network trace files in MySQL. ... > Give a hobbit a ring and he eats fish for an age. ...
    (perl.dbi.users)
  • Re: UNSUBSCRIBING
    ... Eventually the list admin ... I think it's been three months since the last such request. ... Give a hobbit a ring and he eats fish for an age. ...
    (perl.dbi.users)
  • Re: DBD-Oracle question for Win2000
    ... provides pre-compiled packages to install using PPM. ... Give a hobbit a ring and he eats fish for an age. ...
    (perl.dbi.users)