how to store binary file data to a database blob

David Stockwell winexpert at hotmail.com
Thu May 27 13:49:43 EDT 2004


Hi Ivan,

Yep ur right.   I'm hoping to avoid the politics of this.  Basically I've 
been told to store it in the db and that's what will happen.   The thought 
is that its easier to let the DB manage the data than it is to have to worry 
about some external process or person munging the data file stored on the 
filesystem at some location.

With the db approach, if the db is munged you lose it all (up to the 
recovery point, backup, etc).   With the file approach you could get just as 
hosed or worse, if the db loses its 'pointers' via fieldname contents to the 
files on the disk.

So with all that in mind, we're storing blobs in our database.

I have found out that I need to do something like this:
insert a record (with no data)
ask the DCOracle driver to hand me a 'pseudo file object for that record's 
blob'
write the data to the pseudo file
...

David
-------
Tracfone: http://cellphone.duneram.com/index.html
Cam: http://www.duneram.com/cam/index.html
Tax: http://www.duneram.com/index.html




    From: Ivan Voras <iv at an.voras.fer.hr>
To: python-list at python.org
Subject: Re: how to store binary file data to a database blob
Date: Thu, 27 May 2004 17:39:33 +0200

Benjamin Niemann wrote:

    using the % operator. This works at least for arbitrary strings (and 
that's the way to handle strings, if you don't like SQL injections ;)
But I never tried this with blobs - perhaps they need some special treatment 
(thinking e.g. of laaarge files)...

It is generally NOT a good idea to write large binary strings to a (sql 
relational) database, even if it has blobs. A much more robust (and faster) 
solution is to save general data about the blob in the database (its size, 
name, whatever, etc.) and the actual data in a separate file in the 
filesystem (or maybe in a "db" database (BDB, GDBM...), if you really like 
them).

YMMV, mostly depending on the size of blobs. :)
--
http://mail.python.org/mailman/listinfo/python-list

_

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963





More information about the Python-list mailing list