I am having a problem with blobs, I seem to insert ok but only get three (3) 
bytes when I query it back. yes I am setting LongReadLen. any ideas?

thanks

Jim 

I'm using sqlite 3.2.7, 1.09 and of the perl module also code and test results 
are below.

also when I use the command line sqlite3 I also only get 3 characters back.


-- test perl code

#!/usr/bin/perl -w
#
use Carp;
use DBI;
use strict;

my %attr = (PrintError => 1,
            RaiseError => 0,
            AutoCommit => 0);
my $dbh = DBI->connect("dbi:SQLite:slurp.db","","",\%attr);
if (!defined($dbh))
{
  croak("could not connect to db");
}
{
  my $sth = $dbh->prepare("drop table foo");
  if (defined $sth)
  {
    $sth->execute();
    $sth->finish;
  }
}
{
  my $sth = $dbh->prepare("create table foo (nm, val, primary key (nm))");
  $sth->execute();
  $sth->finish;
}

undef $/;
my ($fn) = @ARGV; # name of big file
open (IN, $fn);
my $data = <IN>;  # slurp complete file into variable
close IN;

print "original slurped file size $fn=".length($data)."\n";;
{
  my $sth = $dbh->prepare(qq{
      INSERT or replace INTO foo (nm, val) VALUES (?, ?)
    });
  $sth->execute($fn, $data);
  $sth->finish;
}

undef $data; # JUST TO FREE SOME SPACE
$dbh->{LongReadLen} = $dbh->selectrow_array(qq{
      SELECT MAX(LENGTH(val))
      FROM foo
  });

{
  my $sth = $dbh->prepare("select nm, val from foo where nm = ?");
  my $stat = $sth->execute($fn);
  my ($nm, $out) = $sth->fetchrow_array;
  $sth->finish;
  
  print "size of $nm BLOB returned from query ".length($out)."\n";
  open (NEW1, ">out_".$fn);
  binmode NEW1;
  print NEW1 $out;
  close NEW1;
}
$dbh->commit;
$dbh->disconnect;



--- results of running slurp_test.pl ----

[EMAIL PROTECTED] dev]# time ./slurp_test.pl gorp.foo; ls -l *.foo slurp.db
original slurped file size gorp.foo=4166070
size of gorp.foo BLOB returned from query 3

real  0m0.317s
user  0m0.070s
sys   0m0.150s
-rw-r--r--    1 root     root      4166070 Nov 30 10:33 gorp.foo
-rw-r--r--    1 root     root            3 Nov 30 14:22 out_gorp.foo
-rw-r--r--    1 root     root      4185088 Nov 30 14:22 slurp.db



Reply via email to