Hi-
I'm working with DBI to set up a suite to test Oracle datatypes. My scripts
for BLOB's/CLOB's work fine, but I'm running into problems with RAW datatypes.
I'm trying to insert 5-6 .GIF files. I think they insert o.k., but when
I select them back out, they have different file sizes and appear to have
been corrupted somehow. How should I specify a RAW datatype within my scripts,
whether select or insert?
***** insert snippet:
my $max_len = 20000;
#
#Load Filenames into Scalar
#
opendir(DIR, "/RAWdata") || die "Cannot open gif:$!\n";
my @filenames = grep !/^\./, readdir(DIR);
close(DIR);
my $file;
#
#Go through list of filenames in a directory
#Add the name, length, and binary data to the table
#
foreach my $title (@filenames) {
open(FILE, "/RAWdata/$title") || die "Cannot open $title : $!\n";
binmode FILE;
my $file_len = read FILE, $file, $max_len;
#Prepare Insert Statement
my $sth = $dbh->prepare("INSERT into RAH values (?,?,?)" );
#Bind Variables to columns.
$sth->bind_param(1,$title);
$sth->bind_param(2,$file_len);
$sth->bind_param(3,$file, {ora_type => ORA_RAW} );
#Insert.
my $rv = $sth->execute();
close(FILE);
}
***** select snippet:
$dbh->{LongReadLen} = '20000';
opendir(DIR, "/RAWdata") || die "Cannot open gif:$!\n";
my @filenames = grep !/^\./, readdir(DIR);
close(DIR);
my $title;
#
#Select out RAW's based on their filename - R_NAME
#
foreach my $title (@filenames) {
my $sth = $dbh->prepare("SELECT R_RAW from RAH where R_NAME='$t
+itle'");
$sth->execute();
#
#Put selected RAW into an array, write it to a file using the filename
+ you
#got from the RAWdata directory.
#
my @jpg = $sth->fetchrow_array();
open(FILE, ">$title") || die "Cannot open file for writing: $!\
+n";
print FILE @jpg;
close(FILE);
$sth->finish();
Edit kudra,
2001-10-19
Replaced br with code