Menu

Problems with fetching CLOB as ref cursor

rovshan
2011-09-05
2012-09-26
  • rovshan

    rovshan - 2011-09-05

    Hi,

    First of all I wanted to say a big thank you to the author of OCILIB for
    creating such a useful and intuitive library! I'm currently working on a
    project where OCILIB makes my daily work much easier.

    Currently I encountered one issue that I wanted to ask help for.

    I use following PL/SQL block to get table DDL:

    declare
        h1      NUMBER;         -- handle returned by OPEN
        th      NUMBER;         -- handle returned by ADD_TRANSFORM for DDL
        ddl     CLOB;           -- DDL
    begin
    
     h1 := DBMS_METADATA.OPEN(:object_type);
     DBMS_METADATA.SET_FILTER(h1,'NAME', :object_name);
     DBMS_METADATA.SET_FILTER(h1,'SCHEMA', :owner);
    
     th := DBMS_METADATA.ADD_TRANSFORM(h1,'DDL');
    
     if :p_pretty = 'y' then
       DBMS_METADATA.SET_TRANSFORM_PARAM (th, 'PRETTY', TRUE);
     elsif :p_pretty = 'n' then
       DBMS_METADATA.SET_TRANSFORM_PARAM (th, 'PRETTY', FALSE);
     end if;
    
     /*rest of transformations similar to above if statement*/
    
     ddl := DBMS_METADATA.FETCH_CLOB(h1);
    
     DBMS_METADATA.CLOSE(h1);
    
     open :rs_out for select ddl from dual;
    end;
    

    Then in OCILIB I use

    ociBoundStatement=OCI_StatementCreate(ociConnection);
    OCI_BindStatement(ociStatement, L":rs_out", ociBoundStatement);
    ...execute...
    OCI_Resultset *ociResultSet=OCI_GetResultset(ociBoundStatement);
    

    to get the resultset (:rs_out).

    After this I use a loop and call

    toQString(OCI_GetString(ociResultset, colIx))
    

    to get CLOB as a string (toQString is my function that converts the string to
    QString).

    On Linux everything works right, but on Windows it crashes approximately every
    3 times out of 5. When I run it in debugger it crashes every time. Debugger
    says there is a heap corruption and visual studio shows some assembly code
    inside OCI_GetString. Also when I change CLOB to VARCHAR2 in PL/SQL block it
    works right both on Linux and Windows. Because of this I thought if it works
    with VARCHAR2 may be it is a bug related to CLOB handing on Windows. If you
    encountered this issue or know the solution any help would be of great use for
    me. If I'm asking a dummy question please, direct me in the right direction (I
    tried with OCILIB 3.9.2 with Unicode build)

    Thanks in advance!
    Rovshan

     
  • Vincent Rogier

    Vincent Rogier - 2011-09-05

    hi,

    I'll hve a loot this evening and let you know.

    regards,

    vince

     
  • Vincent Rogier

    Vincent Rogier - 2011-09-05

    Hi,

    I found the problem. I'll make fix asap.

    Send me your email that i can send you a win32 package to test.

    vince

     
  • Vincent Rogier

    Vincent Rogier - 2011-09-05

    Hi,

    in lob.c, comment or remove the lines 433-436 :

    // if (OCILib.nls_utf8 == FALSE)
    // {
    // byte_offset *= sizeof(odtext);
    // }

    it will work then as expected...

    Regards

    vince

     
  • Nobody/Anonymous

    My email address is: rovshanb at gmail dot com

    I will compile it and post the outcome here.

    Thank you very very much!!!

     
  • rovshan

    rovshan - 2011-09-06

    Yes it worked!

    Thank you very much for your time and efforts and for giving this great
    library to us for free!