Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Problems with storable and Sqlite

by antirice (Priest)
on Nov 18, 2005 at 06:09 UTC ( [id://509699]=note: print w/replies, xml ) Need Help??


in reply to Problems with storable and Sqlite

I've faced this problem before and the only solution I found to work besides encoding the data was to prepare the statement and specifically bind the data as a blob. So now your code would look like this:

#!/usr/bin/perl use warnings; use strict; use Storable qw(freeze thaw); use DBI "SQL_BLOB"; my $dbh = DBI->connect("dbi:SQLite:dbname=testlib.db","","",{RaiseErro +r => 1}); my @books=( { 'ISBN' => '0596004788', 'Title' => 'Learning Perl Objects, References, and Mod +ules' }, { 'ISBN' => '0596001320', 'Title' => 'Learning Perl, Third Edition' }, { 'ISBN' => '0596003137', 'Title' => 'Perl Cookbook, Second Edition' }, ); my $book_list = freeze(\@books); my $sth = $dbh->prepare("INSERT INTO BOOKS (BOOK) values (?)"); $sth->bind_param(1,$book_list,SQL_BLOB); $sth->execute; $sth->finish; $sth = $dbh->prepare( 'select * from BOOKS' ); $sth->execute(); my $book= $sth->fetchrow_array ; my $new_list = thaw($book); foreach(@{$new_list}) { print "$_->{'ISBN'} $_->{'Title'}\n"; } __END__ 0596004788 Learning Perl Objects, References, and Modules 0596001320 Learning Perl, Third Edition 0596003137 Perl Cookbook, Second Edition

Replies are listed 'Best First'.
Re^2: Problems with storable and Sqlite
by Anonymous Monk on Nov 18, 2005 at 11:57 UTC
    Thank you very much thats exactly what I want to do. I don't think I would have figured that out on my own, everything after the line use strict; are things that I've only learned in the past few hours.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://509699]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-19 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found