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




Reply via email to