Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Storing Objects in a Database

by btrott (Parson)
on Feb 19, 2000 at 01:33 UTC ( #3721=note: print w/replies, xml ) Need Help??

in reply to Storing Objects in a Database

Have you looked at Storable? It may help you.

It can store objects to the filesystem or to memory, then retrieve them, transforming them back into objects.

So perhaps you could freeze the object to a scalar, store it in a blob in your database, pull it back out, thaw it, then use it again? I don't know--I've only tested Storable using the filesystem, but it seems logical that you could do the same thing w/ a database.

You might be able to do something like this (untested):

use Storable qw/freeze thaw/; use DBI; use Foo; # replace this with your module name my $object = new Foo; my $dbh = DBI->connect('bar', 'foo', 'foo', 'Oracle') or die "Can't connect: ", DBI->errstr; # store it my $sth = $dbh->prepare(<<SQL) or die "Can't prepare: ", $dbh->errstr; insert into objects (id, content) values (?, ?) SQL $sth->execute("foo", freeze $object) or die "Can't execute: ", $dbh->errstr; $sth->finish; # now get it back my $retrieve = $dbh->prepare(<<SQL) or die "Can't prepare: ", $dbh->er +rstr; select content from objects where id = ? SQL $retrieve->execute("foo"); my $content = $retrieve->fetchrow; my $unthawed = thaw $content;
...and now use $unthawed just as you would your original object.

Does this sound like what you want?

Replies are listed 'Best First'.
RE: Re: Storing Objects in a Database
by chromatic (Archbishop) on Feb 19, 2000 at 04:38 UTC
    Yes, that sounds very good. In my initial perusal of the docpage, I didn't think about using freeze and thaw with DBI. Thank you very much!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://3721]
NodeReaper snacks on some Soylent Green

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2017-05-23 04:35 GMT
Find Nodes?
    Voting Booth?