Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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?


In reply to Re: Storing Objects in a Database by btrott
in thread Storing Objects in a Database by chromatic

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-24 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found