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
2009-06-15 19:45:26
...but the filesystem *is* a database :)
ysth
2009-06-15 23:40:42
...and not as easily cacheable.
Stefan Mai
2009-06-23 13:13:46
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
2009-07-01 13:53:48