Menu

BFILE problem

2010-11-12
2012-09-26
  • Nobody/Anonymous

    Hi Vincent,

    I use the below code to retreive the data, as provide from http://orclib.sour
    ceforge.net/doc/html/group__g__file.html

    The cause an error when clear the memory . Please help.

    What is the difference bewteen OCI_CFILE and OCI_BFILE ?
    What Oracle datatype is mapping to OCI_CFILE or when to use OCI_CFILE for
    retreive the data ?

    Regards
    Alvin

    CREATE TABLE my_bfile_table( code NUMBER, value BFILE);

    char buffer;
    OCI_File file = OCI_GetFile(rs, index);
    CHECK_ERR(OCI_FileOpen(file));
    int size = OCI_FileGetSize(file);
    char
    data = new char;
    int n;
    while (n = OCI_FileRead(file, buffer, sizeof(buffer)-1))
    {
    buffer = '\0';
    if (strlen(data) == 0)
    strcpy(data,buffer);
    else
    strcat(data,buffer);
    }
    OCI_FileClose(file);
    -- process .. (no doing anything)
    delete data; --- HEAP CORRUPTION DETECTED: after %hs block

     
  • Vincent Rogier

    Vincent Rogier - 2010-11-12

    Hi,

    In fact OCI_CFILE and OCI_BFILE are the same.
    OCI folks created this distinction but never used it.

    in the code, check that strcat does not do buffer overwrite. Check the buffer
    length

    declare your array data with [size+1] instead of [size]
    

    regards

    vincent

     
  • Vincent Rogier

    Vincent Rogier - 2010-11-12

    hum, got some trouble with the bbcode formatting
    use size+1 instead of size in your array allocation

     
  • Nobody/Anonymous

    Hi vincent,
    Sorry, mistake for copy the source,it become this error code

    char buffer;
    OCI_File file = OCI_GetFile(rs, index);
    CHECK_ERR(OCI_FileOpen(file));
    int size = OCI_FileGetSize(file);
    char
    data = new char;
    Using size OR size + 1, also face the same problem.

    For Oracle Database Express Edition 10g Release 2 (10.2),
    It can't exit the While loop. The "n" alway return buffer size (256-1)

    For Oracle 9i, It hit error on delete data; --- HEAP CORRUPTION DETECTED:
    after %hs block
    Will try it again, next monday at company for Oracle 9i.

    Environment:
    OCI_CHARSET_WIDE
    Window XP

    Regards
    Teh

     
  • Nobody/Anonymous

    Testing for correct : new char with size
    char *data = new char;

    char *data = new char[size+1];
    
     
  • Vincent Rogier

    Vincent Rogier - 2010-11-12

    remember that OCI_FileRead () reads binary data like fread().
    It does not add a terminal '\0'. So using that buffer with strcat and strcpy
    is wrong if you don't set yourself the trailing '\0'

     
  • Nobody/Anonymous

    Hi Vincent,

    Thank a lot for advice.
    The binary contain terminal '\0' , strcat/strcpy just copy partial of data.

    Regards
    Alvin