jcbyrne has asked for the wisdom of the Perl Monks concerning the following question:
Oracle8i Enterprise Edition Release 8.1.7.0.0 perl, version 5.005_03 built for alpha-dec_osf $DBI::VERSION = "1.13"; $DBD::Oracle::VERSION = '1.03'; My table has two columns FILE_NAME VARCHAR2(100) ZIPFILE BLOB The code I have tried is as follows:
#!/usr/bin/perl use strict; use CGI::Carp qw(fatalsToBrowser); use DBI; use DBD::Oracle qw(:ora_types); require "../cbt-lib.pl"; # has header/footer and oracle connect functi +ons &header("blob_test"); my $dbh = &oracleConnectAuth("WRITE"); my $file_name = 'test.zip'; $dbh->{LongReadLen} = 20000 * 1024; &put_blob($dbh,$file_name); &get_blob($dbh,$file_name); $dbh->disconnect; &footer; exit 0; sub put_blob { my ($dbh,$file_name) = @_; my $data; my $blob_data; open (INFILE, "<$file_name") || die "could not $file_name"; binmode INFILE, ":raw"; while(read(INFILE,$data,1024)) { $blob_data .= $data; } close INFILE || die "could not close INfile"; my $sqlstring = "delete from cbt_blob_test"; $dbh->do ($sqlstring) or die "delete:<br>$DBI::errstr<br>$sqlstring"; $sqlstring = "INSERT INTO CBT_BLOB_TEST (FILE_NAME,ZIPFILE) VALUES (?, +?)"; my $sth = $dbh->prepare ($sqlstring) or die "prepare:<br>$DBI::errstr< +br>$sqlstring"; $sth->bind_param(1, $file_name) or die "bind 1 +:<br>$DBI::errstr<br>$sqlstring"; $sth->bind_param(2, $blob_data, {ora_types=>ORA_BLOB} ) or die "bind 2 +:<br>$DBI::errstr<br>$sqlstring"; $sth->execute() or die "execute:\n$DBI::errstr\n$sqlstring"; $sth->finish; $dbh->commit; } sub get_blob { my ($dbh,$file_name) = @_; my $sqlstring = "SELECT ZIPFILE FROM CBT_BLOB_TEST WHERE FILE_NAME = ' +$file_name' "; print "$sqlstring<br>"; my $blobdata = &getDBdata ($sqlstring,$dbh); open (OUTFILE, ">blob_test_output") || die "could not open OUTfile"; binmode (OUTFILE); print OUTFILE $blobdata; close OUTFILE || die "could not close OUTfile"; }
The 'execute' statement in 'get_blob' returns the following error: ORA-01465: invalid hex number (DBD ERROR: OCIStmtExecute) I see a lot of questions about blobs and Oracle on the web, but have yet to find much useful code. Any assistance would be appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Storing/Retrieving Blobs from Oracle
by Ryszard (Priest) on Sep 07, 2001 at 05:11 UTC |