You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by bu...@apache.org on 2002/03/27 12:02:11 UTC

DO NOT REPLY [Bug 7507] New: - [PATCH] esql - support CLOB in get-xml

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7507>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7507

[PATCH] esql - support CLOB in get-xml

           Summary: [PATCH] esql - support CLOB in get-xml
           Product: Cocoon 2
           Version: 2.0.2
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Critical
          Priority: Other
         Component: general components
        AssignedTo: cocoon-dev@xml.apache.org
        ReportedBy: tomasz.bech@bull.com.pl


Patch was already posted to cocoon-dev as: "patch for EQSL - clob support in
esql:get-xml"
It was for version 2.0.1 and I found that 2.0.2 doesn't have this extention so I
put it here.
The main change is to instead of calling directy the ResultSet.getString (in
get-encoded-string), put a
wrapper which reads clob as string (if column is clob type) or in other case
standard getString (look at getStringOrClob function). The implementation is in
xsl but it would be better to move it to  EsqlHelper class (your decision).

Remark: I implemented own reading of clob because getAscii was somehow
producing converted/strange string.
     It works only when encoding for get-xml is not specified!!! I'm not
sure how to implement it in other case.

Test: code deeply tested and used more that 2 months. But tested only on
Oracle jdbc (shoudn't be worse for other driver).

Sorry for missing 'diff -u of CVS' (not able to establish CVS on my side), so
standard diff -wc (WARNING: DONE ON VERSION $Id: esql.xsl,v 1.4 2002/01/28
09:37:16 of the files) (Full file can be found on cocoon-dev)

***************
*** 215,220 ****
--- 215,228 ----
        <xsp:include>java.io.StringWriter</xsp:include>
        <xsp:include>java.io.PrintWriter</xsp:include>
  	
	<xsp:include>java.io.BufferedInputStream</xsp:include>
+ <!--
+ TB - added
+ -->
+ 	
	<xsp:include>java.io.BufferedReader</xsp:include>
+ 	
	<xsp:include>java.io.Reader</xsp:include>
+ <!--
+ TB - end
+ -->
  	
	<xsp:include>java.io.InputStream</xsp:include>
  	
	<xsp:include>java.util.Set</xsp:include>
        <xsp:include>java.util.List</xsp:include>
***************
*** 278,283 ****
--- 286,321 ----
          </xsl:choose>
        </xsl:if>
  
+ <!--
+ TB - added
+ -->
+ 	
	private final String getStringOrClob(ResultSet set, String column) throws
java.lang.Exception {
+ 	
		Reader reader = null;
+ 	
		char[] buffer = null;
+ 
+ 	
		if (set.getMetaData().getColumnType(set.findColumn(column))==java.sql.Types.CLOB) {
+ 	
				Clob dbClob = set.getClob(column);
+ 	
				int length = (int) dbClob.length();
+ 	
				reader = new BufferedReader(dbClob.getCharacterStream());
+ 	
				buffer = new char[length];
+ 	
				reader.read(buffer);
+ 	
				reader.close();
+ 	
				if (reader != null)
+ 	
						reader.close();
+ 	
				if (buffer == null)
+ 	
						return "";
+ 	
				return new String(buffer);
+ 	
		}
+ 	
		else
+ 	
		{
+ 	
			return set.getString(column);
+ 	
		}
+ 	
	}
+ <!--
+ TB - end
+ -->
+ 
  	
	<xsl:choose>
  	
		<xsl:when test="$environment = 'Cocoon1'">
  	
		</xsl:when>
***************
*** 895,900 ****
--- 933,949 ----
  	<xsp:expr>EsqlHelper.getAscii(<xsl:call-template name="get-resultset"/>,
<xsl:call-template name="get-column"/>)</xsp:expr>
  </xsl:template>
  
+ <!--
+ TB - added
+ -->
+ <xspdoc:desc>returns the value of the given column as string (column can be
string or clob</xspdoc:desc>
+ <xsl:template match="esql:row-results//esql:get-clob" name="get-clob">
+ 	<xsp:expr>this.getStringOrClob(<xsl:call-template name="get-resultset"/>,
<xsl:call-template name="get-column"/>)</xsp:expr>
+ </xsl:template>
+ <!--
+ TB - end
+ -->
+ 
   <xspdoc:desc>returns the value of the given column interpeted as an xml fragment.
   The fragment is parsed by the default xsp parser and the document element is
returned.
   If a root attribute exists, its value is taken to be the name of an element
to wrap around the contents of
***************
*** 1077,1083 ****
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$encoding = 'default'">
!       <xsl:value-of select="$resultset"/>.getString(<xsl:value-of
select="$column-spec"/>)
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$resultset"/>.getBytes(<xsl:value-of
select="$column-spec"/>)
--- 1126,1136 ----
    </xsl:variable>
  	<xsl:choose>
  		<xsl:when test="$encoding = 'default'">
! <!-- TB modified
! -->
! 	
	this.getStringOrClob(<xsl:value-of select="$resultset"/>, <xsl:value-of
select="$column-spec"/>)
! <!-- TB end
! -->
  		</xsl:when>
  		<xsl:otherwise>
        <xsl:value-of select="$resultset"/>.getBytes(<xsl:value-of
select="$column-spec"/>)

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org