views:

595

answers:

1

Could someone please give me a Perl example on how to load an image file into a blob in SQLite?

+2  A: 

Well ... I wouldn't recommend storing images in any database (I prefer to store images in the filesystem and the paths to the image in the db) but ... that scenario is right in the documentation for DBD::SQLite

use DBI qw(:sql_types);
my $dbh = DBI->connect("dbi:SQLite:dbfile","","");

my $blob = `cat foo.jpg`;
my $sth = $dbh->prepare("INSERT INTO mytable VALUES (1, ?)");
$sth->bind_param(1, $blob, SQL_BLOB);
$sth->execute();
derby
...but the filesystem *is* a database :)
ysth
...and not as easily cacheable.
Stefan Mai
i know the `cat foo.jpg` is not the best idiom for reading a file into memory ... but the example is straight from the SQLite docs.
derby