> 
> 
> I was just looking at the 'longbin.pl' test script that is 
> bundled with 
> DBD::ODBC, which has raised a few questions:
> 
> 1.  To place a blob in an Access database, as per the example 
> script, is 
> it necessary to use the Digest::MD5 module, or is it's use an 
> optional 
> step that is ultimately suggested?

Neither, actually.  The MD5 algorithm is good for *testing* that you got
what you put in, but I'd not necessarily use that in production code.  I
only used it to make sure, in the example, the inserted data is the same
as the retrieved data.  The steps are:
        The MD5 hash is created on the source data
        Then the data is inserted
        The data is selected from the database
        The second MD5 hash is created on the retrieved data
        and then they are compared to ensure accuracy of the data.

The issue I was having was verifying correctness and that example is
good to use when designing the system and testing with arbitrary binary
inserts.  I used some graphics files to test.  For example, I found that
under Access, I had to do something special (tell Access what type the
data being bound was) to ensure data > 64K worked.  So -- it's a good
sanity test for your application during development, not necessarily
during production.  
 
> 2.  Unlike a text field or an integer field (etc.), a blob 
> field has both a file 
> name and file data.  When reading the data, as per the example, I see 
> that the SELECT statement gets just 'picture'.  At what point does it 
> parse the file name from the file data?

Actually, in this example, I didn't insert the file name, thus it wasn't
in the database.  I simply inserted the data to test inserting long
binary objects with different databases.  If you want/need to store the
file name too, then add that as another column.  

> 
> Having not ever used the Digest::MD5 module, I suspect that 
> it is what 
> handles all of this, but I just wanted qualified verification 
> before I dove 
> in and got too deep.

Nope.  That's not what it does.  [Over simplifying here -- sorry if this
comes across the wrong way] Digest::MD5 creates a special value based
upon the data passed into it.  If you pass the same data through the MD5
algorithm, you'll get the same value from it.  If you pass different
data, you'll get a different value.  I was simply using this instead of
a byte-by-byte comparison of the data.  If you'll notice a lot of FTP
sites and file repositories have a file and a .md5 file in the same
directory.  So you have: foo.tar.gz and foo.tar.gz.md5.  The .md5 file
is just the MD5 digest of the file itself.  This is to allow you, after
you download it, to compare the file to what's on the server.  If the
MD5 values don't match, you didn't get the file correctly (or it's been
altered since the MD5 value was generated). 

While I wouldn't necessarily use MD5 in my production code, there are
some good reasons to use it: you want to verify what you put in is what
you get out.  I.e. nothing has corrupted the data since you put it in.
There are security and other reasons you might want to do this.  I had
an example where I was sending data over a slow, unreliable link, so I
built some perl scripts to send the data in smaller size chunks and the
"other side" got both the data and the MD5 hash.  If they didn't match,
the "other side" requested a new version of that file.  This is just
plain handy for a lot of things -- but may not be what you want.

Also -- _typically_, I don't recommend storing image files in the
database itself.  For some applications, it's fine, but if performance
is your issue, then storing the files on the file system and storing a
filename in the database is just faster, for *most* applications.  Keep
in mind, that I'm saying "typically" and "most"....these are not hard
"rules" per say, just things I've learned over the years.  
Regards,

Jeff



Reply via email to