is there a module to work with pickled objects storage in database?

Discussion in 'Python' started by krishnakant Mane, May 4, 2007.

  1. hello all,
    I am trying a very complex kind of a task in a project.
    I have a knowledge management system where I need to store a lot of
    objects (pickled). I have to store mostly lists and dictionaries into
    a rdbms.
    mostly I will be using mysql. I want to know if there is any module
    that can help me store a pickled object inside a blob field instead of
    a file. I know that pickle.dump() can store an object into a file but
    I can't find a way to transfer pickled objects into a database.
    I so far tried to read a dumpped file for pickled object and directly
    right the contents of the file to the blob field in my database.
    but that does not seam to give the right result.
    I first dump the object into the file through pickle.dump and then
    open the file in read mode.
    then I read the contents of the file and then store what ever comes
    out into the blob field.
    I know this is not right and there should be ways of storing a pickled
    object other than file.
    Please guide me on this issue.
    regards.
    Krishnakant.
     
    krishnakant Mane, May 4, 2007
    #1
    1. Advertising

  2. krishnakant Mane

    Paul Boddie Guest

    On 4 Mai, 12:18, "krishnakant Mane" <> wrote:
    >
    > I first dump the object into the file through pickle.dump and then
    > open the file in read mode.
    > then I read the contents of the file and then store what ever comes
    > out into the blob field.
    > I know this is not right and there should be ways of storing a pickled
    > object other than file.


    Try pickle.dumps to produce a string containing the pickled object.
    Obviously, you then need to supply the string to the database using
    the normal DB-API mechanisms. That said, although I haven't done much
    work with BLOBs in the DB-API, it would surprise me if it were not
    possible with some database modules to pass a file-like object as a
    parameter to the cursor's execute method, although I don't recall
    there being any classes whose objects act like files and produce
    pickled objects on demand.

    Paul
     
    Paul Boddie, May 4, 2007
    #2
    1. Advertising

  3. krishnakant Mane a écrit :
    > hello all,
    > I am trying a very complex kind of a task in a project.
    > I have a knowledge management system where I need to store a lot of
    > objects (pickled). I have to store mostly lists and dictionaries into
    > a rdbms.


    Which totally defeats the purpose of a rdbms.
     
    Bruno Desthuilliers, May 4, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Grow
    Replies:
    1
    Views:
    372
    Tim Keating
    Nov 16, 2004
  2. Bram Stolk
    Replies:
    0
    Views:
    280
    Bram Stolk
    Dec 12, 2005
  3. krishnakant Mane
    Replies:
    2
    Views:
    282
    Daniele Varrazzo
    May 7, 2007
  4. Jean-Paul Calderone

    Re: Pickled objects over the network

    Jean-Paul Calderone, Jul 18, 2007, in forum: Python
    Replies:
    3
    Views:
    764
    Irmen de Jong
    Jul 19, 2007
  5. Oltmans
    Replies:
    3
    Views:
    265
    Grant Edwards
    May 26, 2010
Loading...

Share This Page