Problem storing a hash in DB using Storable::nfreeze in Perl
Posted
by Sam
on Stack Overflow
See other posts from Stack Overflow
or by Sam
Published on 2010-04-16T13:57:23Z
Indexed on
2010/04/17
13:23 UTC
Read the original article
Hit count: 339
I want to insert a hash in the db using Storable::nfreeze but the data is not inserted properly.
My code is as follows:
%rec=();
$rec{'name'} = 'my name';
$rec{'address'} = 'my address';
my $order1 = new Order();
$order1->set_session(\%rec);
$self->createOrder($order1);
sub createOrder {
my $self = $_[0];
my $order = $_[1];
# Retrieve the fields to insert into the database.
my $st = $dbh->prepare("insert into order (session,.......) values(?,........)");
my $session = %{$order->get_session()};
$st->execute(&Storable::nfreeze(\%session),.....);
$st->finish();
}
sub getOrder
{
...
my $session = &Storable::thaw( $ref->{'session'} );
.....
}
The thaw
is working fine because I tested it withe some rows that have been inserted correctly, but when I try to get a row that was inserted using the createOrder
subroutine, I get an error saying:
Storable binary image v36.65 more recent than I am (v2.7) at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/thaw.al) line 415
The error comes from the line that have thaw
. The nfreeze
did not store the hash properly.
Can someone point me to what I'm doing wrong in the createOrder
subroutine?
I know the module version have nothing to do with the problem.
© Stack Overflow or respective owner