Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> insert blob data with pro*c

insert blob data with pro*c

From: mic0355 <mic0355_at_hotmail-dot-com.no-spam.invalid>
Date: Fri, 18 Nov 2005 02:11:40 -0600
Message-ID: <F8SdnfRpePchEeDeRVn_vA@giganews.com>


I got a sample code for inserting a BLOB data from the web. Here is the code:

#include <oci.h>
#define MAXBUFLEN 5000
OCIBlobLocator *blob ;
FILE *fp ;
unsigned int amt, offset = 1 ;
unsigned filelen, remainder, nbytes ;
boolean last ;
unsigned char buffer[MAXBUFLEN] ;
EXEC SQL VAR buffer IS RAW(MAXBUFLEN);

EXEC SQL ALLOCATE :blob ;
EXEC SQL INSERT INTO lob_table (a_blob) VALUES (EMPTY_BLOB())

   RETURNING a_blob INTO :blob ;

fp = fopen((const char *)"image.gif", (const char *)"r") ;
(void) fseek(fp, 0L, SEEK_END) ;

filelen = (unsigned int)ftell(fp) ;
amt = filelen ;

if (filelen > MAXBUFLEN)

    nbytes = MAXBUFLEN ;
else

    nbytes = filelen ;

(void) fseek(fp, 0L, SEEK_SET) ;
(void) fread((void *)buffer, (size_t)nbytes, (size_t)1, fp) ;
remainder = filelen - nbytes ;

if (remainder == 0)
{

    EXEC SQL LOB WRITE ONE :amt

             FROM :buffer INTO :blob AT :offset ; }
else
{

    EXEC SQL LOB WRITE FIRST :amt

             FROM :buffer INTO :blob AT :offset ;

    last = FALSE ;
    EXEC SQL WHENEVER SQLERROR DO break ;     do
    {

        if (remainder > MAXBUFLEN)
            nbytes = MAXBUFLEN ;
        else
        {
            nbytes = remainder ;
            last = TRUE ;
        }
        if  fread((void *)buffer, (size_t)nbytes, (size_t)1, fp) !=
1)
            last = TRUE ;
        if (last)
        {  
            EXEC SQL LOB WRITE LAST :amt
                     FROM :buffer INTO :blob  ;
        }
        else
        {
            EXEC SQL LOB WRITE NEXT :amt
                     FROM :buffer INTO :blob  ;
        }
        remainder -= nbytes ;

    }while (!last && !feof(fp)) ;
}
:

But i got an error (SQL CODE :24810) when writing a BLOB with size > 5000. why does this error happen? and how to solve it? thanks Received on Fri Nov 18 2005 - 02:11:40 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US