Search code examples
coldfusioncoldfusion-8

Getting CLOB data from ColdFusion 8


I am trying to retrieve CLOB data from our Oracle database. the code is the following:

<cfstoredproc datasource="#request.site.datasource#" procedure="GETPAGESWITHMETADATA" result="myResults">
    <cfprocparam cfsqltype="CF_SQL_VARCHAR" type="in" value="News">
    <cfprocparam cfsqltype="CF_SQL_VARCHAR" type="in" value="News Pages">
    <cfprocparam cfsqltype="CF_SQL_CLOB" type="out" variable="XML">
    <cfprocresult name="rs1">
</cfstoredproc>
<cfdump var="#myResults#">
<cfoutput>#XML#</cfoutput>
<cfcatch type="any">
    <cfdump var="#cfcatch#">
</cfcatch>
</cftry>

Basically, the output of the stored procedure is:

select dbms_xmlquery.getxml(queryCtx) INTO XML from dual;

I checked the data sources on the server and the "Enable long text retrieval (CLOB)." option is checked for every data source.

Surprisingly, instead of getting the XML result on screen, I get a very short string: [C@74897f5e

It looks like a handle id instead of the content itself.

How can I retrieve the complete content of the XML?

For reference, the data source is using macromedia drivers with TNS name: Driver class: macromedia.jdbc.MacromediaDriver


Solution

  • As @MarkAKruger suggested, returning a table from the procedure solved the issue. The following PL/SQL code did the trick:

    create or replace
    PACKAGE PCK_Commonspot
    AS
    type t_clob IS record (metadata CLOB) ;
    type t_clob_tab IS TABLE OF t_clob;
    FUNCTION GetPagesWithMetadataAsRS(FormName varchar2, CategoryName varchar2)
        RETURN t_clob_tab pipelined;
    END PCK_Commonspot;
    

    The package body contains the following code:

    FUNCTION GetPagesWithMetadataAsRS(FormName varchar2, CategoryName varchar2)
        RETURN t_clob_tab pipelined
    IS
        r t_clob;
     BEGIN
        GETPAGESWITHMETADATA(FormName, CategoryName, r.metadata) ;
        pipe row(r) ;
        RETURN;
    END;
    

    The function GETPAGESWITHMETADATA is the one returning a CLOB into r.metadata Here, the trick is around returning a piped table.

    It becomes super nice on the ColdFusion side because the call is really simple:

    <cfquery name="Test" datasource="myDS" maxrows="1">
        SELECT * FROM TABLE(PCK_Commonspot.GetPagesWithMetadataAsRS('abc','def'))
    </cfquery>
    <cfset XML = Xmlparse(Test.Metadata)>
    

    Thanks Mark!