Ok, this is the same code that you posted to the list.
1) I tested the "read" syntax you have, and it should work but apparently
is not. Try printing the contents of $buf to see what's in it.
2) Try the changes I suggested, and post further replies to the list.
____________________________
Jeff Seger
Fairchild Semiconductor
[EMAIL PROTECTED]
____________________________
[EMAIL PROTECTED]
08/26/2003 09:23 AM
To: Jeffrey Seger/Corporate/[EMAIL PROTECTED]
cc:
Subject: Re: Trying to store a file into the Oracle
Here is my code
------------------------------------------------------
#!/usr/local/bin/perl
use DBI;
$LONG_RAW_TYPE=24; # Oracle type id for blobs
$dbh = DBI->connect( "DBI:Oracle:host=195.251.192.218;sid=$sid",
$username,
$password)
or die "Connecting : $DBI::errstr\n ";
open(BLOB, "john.doc");
$bytes = 0;
$bytes = read(BLOB, $buf, 500000);
print STDERR "Read $bytes bytes...\n";
close(BLOB);
$stmt = $db->prepare("INSERT INTO hr.documents VALUES
('1','john.doc','$bytes')") || die "\nPrepare error: $DBI::err ....
$DBI::errstr\n";
# Bind variable. Note that long raw (blob) values must
have their
attrib explicitly specified
$attrib{'ora_type'} = $LONG_RAW_TYPE;
$stmt->bind_param("john.doc", $buf, \%attrib);
$stmt->execute() || die "\nExecute error: $DBI::err ....
$DBI::errstr\n";
print STDERR "Complete.\n";
-----------------------------------------------------------------
and that is my error message
------------------------------------------------------------
Read 6 bytes...
Can't call method "prepare" on an undefined value at
C:/progs/dika/blob/insert_b
lob_test.pl line 26.
---------------------------------------------------------------
Quoting [EMAIL PROTECTED]:
> when you read the file in, you stored its contents in $buf (or at least
> the first 500000 bytes of it):
>
> > open(BLOB, "john.doc");
> > $bytes = 0;
> > $bytes = read(BLOB, $buf, 500000);
>
> As I said, I am not an expert in dealing with blobs, and am not sure if
a
> standard placeholder will work, so I suggest that you check back with
the
> list after trying the changes I've suggested.
>
>
> ____________________________
> Jeff Seger
> Fairchild Semiconductor
> [EMAIL PROTECTED]
> ____________________________
>
>
>
>
>
> [EMAIL PROTECTED]
> 08/26/2003 08:51 AM
>
>
> To: Jeffrey Seger/Corporate/[EMAIL PROTECTED]
> cc:
> Subject: Re: Trying to store a file into the Oracle
>
>
> > $stmt->execute ('1','john.doc',$buf);
>
> What the $buf means?
>
> What does this consist of? I suppose that it contains the data of the
file
> in a
> binary form, but the problem is how to get the binary form of the file?
>
> I have seen 1-2 scripts using the read() function.
>
> I tried to use it also with no success.
>
>
>
>
> Quoting [EMAIL PROTECTED]:
>
> > To start with, you are trying to insert the size of your file rather
> than
> > the actual content of it:
> >
> > $stmt = $db->prepare("INSERT INTO hr.documents
> > (documentid ,
> > document_name, document) VALUES ('1','john.doc','$bytes')") || die
> > "\nPrepare
> > error: $DBI::err .... $DBI::errstr\n";
> >
> > Next, I would change that prepare to use place holders:
> >
> > $stmt = $db->prepare(
> > "INSERT INTO hr.documents (documentid , document_name,
document)
> > VALUES (?,?,?)"
> > ) || die "\nPrepare error: $DBI::err ....
> > $DBI::errstr\n";
> >
> > Then execute it with the appropriate values:
> >
> > $stmt->execute ('1','john.doc',$buf);
> >
> > Now I have not worked with blobs and perl before, but these are a few
> key
> > things that jumped out at me. Perhaps one of the blob gurus out there
> can
> > speak more to the need to bind.
> >
> >
> > ____________________________
> > Jeff Seger
> > Fairchild Semiconductor
> > [EMAIL PROTECTED]
> > ____________________________
> >
> >
> >
> >
> >
> > [EMAIL PROTECTED]
> > 08/25/2003 11:47 AM
> >
> >
> > To: dbi-users <[EMAIL PROTECTED]>
> > cc:
> > Subject: Trying to store a file into the Oracle
> >
> >
> > Here is my code but i receive the message that only 6 byes have been
> read
> > What is wrong? Could anyone enlighten me?
> > -------------------------------------------------------------------
> > use DBI;
> >
> >
> > $LONG_RAW_TYPE=24; # Oracle type id for blobs
> >
> >
> > $dbh = DBI->connect( "DBI:Oracle:host=$host;sid=$sid", $username,
> > $password)
> > or die "Connecting : $DBI::errstr\n
";
> >
> >
> >
> >
> >
> >
> > open(BLOB, "john.doc");
> > $bytes = 0;
> > $bytes = read(BLOB, $buf, 500000);
> >
> > print STDERR "Read $bytes bytes...\n";
> > close(BLOB);
> >
> > $stmt = $db->prepare("INSERT INTO hr.documents
> > (documentid ,
> > document_name, document) VALUES ('1','john.doc','$bytes')") || die
> > "\nPrepare
> > error: $DBI::err .... $DBI::errstr\n";
> >
> > # Bind variable. Note that long raw (blob) values
must
>
> > have their
> > attrib explicitly specified
> > $attrib{'ora_type'} = $LONG_RAW_TYPE;
> > $stmt->bind_param("john.doc", $buf, \%attrib);
> >
> > $stmt->execute() || die "\nExecute error: $DBI::err
> ....
> > $DBI::errstr\n";
> >
> > print STDERR "Complete.\n";
> >
-----------------------------------------------------------------------
> >
> >
> >
> >
> >
>
>
>
>
>
>
>