in reply to How to insert BLOB into DB2 using DBI?

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 ;-)

Replies are listed 'Best First'.
Re^2: How to insert BLOB into DB2 using DBI?
by Anonymous Monk on Jan 14, 2005 at 15:38 UTC
    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 ;->)

        Not quite, you need to set the value for LongReadLen otherwise you might not get all of the data back.

        rdfield

        Actually, it's not working. My code is:
        open(INFILE,"X:\\\\ongoing\\bioinformatics\\db2\\image\\picture1.wmf") +; binmode(INFILE); $img_data = <INFILE>; close(INFILE); my $stmt = "INSERT INTO project_figures (pjfg_id, pjfg_name, pjfg_imag +e) VALUES(?,?,?)"; my $sth = $dbh->prepare($stmt); my $rc = $sth->execute(1,'picture1.wmf', $img_data);
        And I get
        DBD::ODBC::st execute failed: [IBM][CLI Driver] CLI0110E Invalid outp +ut or indicator buffer specified. SQLSTATE=22002 (SQL-22002)(DBD: st_ +execute/SQLExecute err=-1) at insert_image.pl line 24. DBD::ODBC::st execute failed: [IBM][CLI Driver] CLI0110E Invalid outp +ut or indicator buffer specified. SQLSTATE=22002 (SQL-22002)(DBD: st_ +execute/SQLExecute err=-1) at insert_image.pl line 24.