in reply to Oracle BLOBs DBD::Oracle

Please post some code.

Replies are listed 'Best First'.
Re: Re: Oracle BLOBs DBD::Oracle
by PerliKnight (Acolyte) on Apr 08, 2003 at 12:14 UTC

    OK, here is it. It's a bit mixed up as I've been trying different things.

    Getting the impression this doesn't work though, despite what the documentation says.

    # perform the connection using the Oracle driver my $dbh = DBI->connect("dbi:Oracle:$database", "$username", "$password +", { PrintError => 0, RaiseError => 0 }) or die "Can't connect to the database: $DBI::errstr\n"; print "INFO: connected to $database OK, updating picture_table with $p +hoto\n"; # prepare update statement print "INFO: reading $photo to blob\n"; open (BLOB, "<$photo") or die "Can't open $photo: $!"; binmode BLOB; { local($/) = undef; $blob = <BLOB>; } close (BLOB); $quotedblob = $dbh->quote($blob); # THIS ALL WORKS BAR THE BLOB UPLOAD...!!!! #my $sth = $dbh->prepare ("update ssi_pri_photos set recorded = sysdat +e, recorded_by = 'David', photograph = '$blob' where person_number = +'$person_id'"); #my $sth = $dbh->prepare ("select recorded_by from ssi_pri_photos"); my $sth = $dbh->prepare ("update ssi_pri_photos set recorded = sysdate +, recorded_by = 'David', photograph = ? where person_number = $person +_id"); $sth->bind_param(1, $quotedblob, SQL_LONGVARBINARY); # execute the statement in the database $sth->execute or die "Can't execute SQL statement: $DBI::errstr\n";

    Thanks to everyone for the suggestions so far, by the way.

    Thanks,
    David

      First, BLOB support with Oracle and DBI definitely works, and many people have used it successfully.

      I see a few things in your code. First, don't quote $blob. Second, you have to use bind variables when working with BLOBs. Don't try to just put $blob into the statement as a quoted string. Finally, "SQL_LONGVARBINARY" looks fishy to me. I have always used code that looks like this:

      $sth->bind_param(1, $serialized, {ora_type => ORA_BLOB, ora_field => ' +data' });

        Still not working. Do you have a working example I could see?

        Code now looks like and gets can't call bind_param on an undefined value but I don't know what it's on about.

        # prepare update statement print "INFO: reading $photo to blob\n"; open (BLOB, "<$photo") or die "Can't open $photo: $!"; binmode BLOB; local($/) = undef; $blob = <BLOB>; close (BLOB); my $sth = $dbh->prepare ("update ssi_pri_photos set recorded = sysdate +, recorded_by = 'David', photograph = ? where number = $id"); $sth->bind_param(1, $blob, {ora_type => ORA_BLOB, ora_field => 'photog +raph'});

        I've tried putting in 113 for ORA_BLOB too but that didn't make any difference.

        Any ideas?

        Thanks,
        David