Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I did a lot of searching on here but couldn't find a direct answer. How would I insert an image file to a DB2 blob via DBI? Thanks

Replies are listed 'Best First'.
Re: How to insert BLOB into DB2 using DBI?
by Tanktalus (Canon) on Jan 14, 2005 at 15:26 UTC

    Can you give us some hints of what you've tried? I would have assumed that normal replacements and binding would work - have you tried that?

    my $stmt = "INSERT INTO my.table (NAME,IMAGE) VALUES(?,?)"; my $sth = $dbh->prepare($stmt); my $rc = $sth->execute('filename.jpg', $contents_of_filename_jpg);
    Untested - but that's because I've not had a need for BLOBs yet. I have a plan for it, and I'm counting on this working ;-)

      Thanks, your code did work. Now how would I download the same data and write it to a file? Thanks

        When you SELECT that column, you should have the raw data in the returned row - just write it to the new file ... print FH $data should work.

        (So far, I doubt any of this is DB2 specific ;->)