haul 2002/06/04 02:37:18 Modified: src/java/org/apache/cocoon/components/language/markup/xsp Tag: cocoon_2_0_3_branch EsqlConnection.java EsqlHelper.java EsqlQuery.java src/java/org/apache/cocoon/components/language/markup/xsp/java Tag: cocoon_2_0_3_branch esql.xsl Log: Catch up with bug fixes from HEAD Revision Changes Path No revision No revision 1.6.2.1 +7 -2 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlConnection.java Index: EsqlConnection.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlConnection.java,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -r1.6 -r1.6.2.1 --- EsqlConnection.java 28 Mar 2002 16:14:37 -0000 1.6 +++ EsqlConnection.java 4 Jun 2002 09:37:17 -0000 1.6.2.1 @@ -60,7 +60,7 @@ * * based on the orginal esql.xsl * @author <a href="mailto:[EMAIL PROTECTED]">Torsten Curdt</a> - * @version CVS $Id: EsqlConnection.java,v 1.6 2002/03/28 16:14:37 tcurdt Exp $ + * @version CVS $Id: EsqlConnection.java,v 1.6.2.1 2002/06/04 09:37:17 haul Exp $ */ public class EsqlConnection implements Connection { @@ -80,7 +80,12 @@ } public String getUrl() { - return(url); + if (this.url == null) + try { + this.url=this.connection.getMetaData().getURL(); + } catch (SQLException e) { + }; + return this.url; } public void setUrl( String url ) { 1.7.2.1 +79 -30 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlHelper.java Index: EsqlHelper.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlHelper.java,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -u -r1.7 -r1.7.2.1 --- EsqlHelper.java 22 Feb 2002 07:00:08 -0000 1.7 +++ EsqlHelper.java 4 Jun 2002 09:37:17 -0000 1.7.2.1 @@ -51,9 +51,12 @@ package org.apache.cocoon.components.language.markup.xsp; import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.Reader; import java.sql.ResultSet; import java.io.InputStream; import java.sql.Clob; +import java.sql.Types; /** * This is a helper class to remove redundant code in @@ -61,46 +64,88 @@ * * based on the orginal esql.xsl * @author <a href="mailto:[EMAIL PROTECTED]">Torsten Curdt</a> - * @version CVS $Id: EsqlHelper.java,v 1.7 2002/02/22 07:00:08 cziegeler Exp $ + * @version CVS $Id: EsqlHelper.java,v 1.7.2.1 2002/06/04 09:37:17 haul Exp $ */ public class EsqlHelper { - public final static String getAscii(ResultSet set, String column) { - InputStream asciiStream = null; - byte[] buffer = null; + /** returns Unicode encoded string from CLOB or String column + */ + public final static String getStringOrClob(ResultSet set, String column) throws RuntimeException { + + String result = null; try { - Clob dbClob = set.getClob(column); - int length = (int) dbClob.length(); - asciiStream = new BufferedInputStream(dbClob.getAsciiStream()); - buffer = new byte[length]; - asciiStream.read(buffer); - asciiStream.close(); + result = EsqlHelper.getStringOrClob(set,set.findColumn(column)); } catch (Exception e) { throw new RuntimeException("Error getting clob data: " + e.getMessage()); - } finally { - if (asciiStream != null) try {asciiStream.close();} catch (Exception ase) { - throw new RuntimeException("Error closing clob stream: " + ase.getMessage()); + } + return result; + } + + + /** returns Unicode encoded string from CLOB or String column + */ + public final static String getStringOrClob(ResultSet set, int column) throws java.lang.Exception { + + Reader reader = null; + char[] buffer = null; + + try { + if (set.getMetaData().getColumnType(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); } + } catch ( Exception e) { + throw new RuntimeException("Error getting clob data: " + e.getMessage()); } + } - if (buffer == null) return ""; - return new String(buffer); + /** returns ascii string from CLOB or String column + */ + public final static String getAscii(ResultSet set, String column) throws RuntimeException { + + String result = null; + try { + result = EsqlHelper.getAscii(set,set.findColumn(column)); + } catch (Exception e) { + throw new RuntimeException("Error getting clob data: " + e.getMessage()); + } + return result; } + + /** returns ascii string from CLOB or String column + */ public final static String getAscii(ResultSet set, int column) { InputStream asciiStream = null; - byte[] buffer = null; + String result = null; try { - Clob dbClob = set.getClob(column); - int length = (int) dbClob.length(); - asciiStream = new BufferedInputStream(dbClob.getAsciiStream()); - buffer = new byte[length]; - asciiStream.read(buffer); - asciiStream.close(); + if (set.getMetaData().getColumnType(column) == Types.CLOB) { + byte[] buffer = null; + Clob dbClob = set.getClob(column); + int length = (int) dbClob.length(); + asciiStream = new BufferedInputStream(dbClob.getAsciiStream()); + buffer = new byte[length]; + asciiStream.read(buffer); + asciiStream.close(); + result = (buffer!=null? new String(buffer) : null); + } else { + result = set.getString(column); + } } catch (Exception e) { throw new RuntimeException("Error getting clob data: " + e.getMessage()); } finally { @@ -108,17 +153,21 @@ throw new RuntimeException("Error closing clob stream: " + ase.getMessage()); } } - - if (buffer == null) return ""; - - return new String(buffer); + + + return result; } public final static String getStringFromByteArray(byte[] bytes, String encoding) { - try { - return new String(bytes,encoding); - } catch (java.io.UnsupportedEncodingException uee) { - throw new RuntimeException("Unsupported Encoding Exception: " + uee.getMessage()); + if (bytes != null) { + try { + return new String(bytes,encoding); + } catch (java.io.UnsupportedEncodingException uee) { + throw new RuntimeException("Unsupported Encoding Exception: " + uee.getMessage()); + } + } + else { + return(""); } } 1.11.2.4 +99 -9 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlQuery.java Index: EsqlQuery.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlQuery.java,v retrieving revision 1.11.2.3 retrieving revision 1.11.2.4 diff -u -r1.11.2.3 -r1.11.2.4 --- EsqlQuery.java 19 Apr 2002 18:19:52 -0000 1.11.2.3 +++ EsqlQuery.java 4 Jun 2002 09:37:17 -0000 1.11.2.4 @@ -57,6 +57,7 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; +import java.util.ArrayList; /** * This helper class takes care of contstructing queries @@ -65,22 +66,30 @@ * * based on the orginal esql.xsl * @author <a href="mailto:[EMAIL PROTECTED]">Torsten Curdt</a> - * @version CVS $Id: EsqlQuery.java,v 1.11.2.3 2002/04/19 18:19:52 froehlich Exp $ + * @version CVS $Id: EsqlQuery.java,v 1.11.2.4 2002/06/04 09:37:17 haul Exp $ */ public class EsqlQuery { + private static final int UPDATE_COUNT_UNSET = -2; + private Connection connection = null; private Statement statement = null; private PreparedStatement preparedStatement = null; private ResultSet resultSet = null; private ResultSetMetaData resultSetMetaData = null; + private int updateCount = EsqlQuery.UPDATE_COUNT_UNSET; + private int updateCountCount = 0; + private int resultCount = 0; private boolean hasResultSet = false; private boolean resultSetValid = false; private int position = -1; private int maxRows = -1; private int skipRows = 0; private boolean keepgoing = true; - private java.util.Hashtable groupingVars = new java.util.Hashtable(); + + private ArrayList groups = null; + private int groupLevel = -1; + private int changeLevel = -1; private String query; private int limitMethod; @@ -100,6 +109,17 @@ this.hasResultSet = (this.resultSet != null); } + + class EsqlGroup { + public String var = null; + public Object value = null; + + EsqlGroup ( String var, Object value ) { + this.var = var; + this.value = value; + } + } + public int getSkipRows() { return(skipRows); } @@ -211,13 +231,48 @@ keepgoing = still; } - public Object setGroupingVar( String key, Object value) { - return groupingVars.put(key,value); - } + public void groupLevelPlusPlus() { + this.groupLevel++; + } - public Object getGroupingVar( String key) { - return groupingVars.get(key); - } + public void groupLevelMinusMinus() { + this.groupLevel--; + } + + public boolean groupLevelExists() { + return (this.groups != null && this.groups.get(this.groupLevel) != null); + } + + public void setGroupingVar( String key ) throws SQLException { + if (this.groups == null) + this.groups = new ArrayList(1); + this.groups.ensureCapacity(this.groupLevel); + this.groups.add(this.groupLevel, new EsqlGroup(key, this.getResultSet().getObject(key))); + } + + public boolean hasGroupingVarChanged() throws SQLException { + if (this.changeLevel != -1) { + if (this.changeLevel < this.groupLevel) { + return true; + } else { + this.changeLevel = -1; + return true; + } + } else { + boolean result = false; + // need to check the complete hierarchy of nested groups for changes + for (int i = 0; i <= this.groupLevel; i++) { + Object tmp = this.getResultSet().getObject(((EsqlGroup)this.groups.get(i)).var); + if (!tmp.equals(((EsqlGroup)this.groups.get(i)).value)) { + ((EsqlGroup)this.groups.get(i)).value = tmp; + result = true; + if (this.changeLevel == -1 && this.groupLevel != i) + this.changeLevel = i; + } + } + return result; + } + } public ResultSetMetaData getResultSetMetaData() { return(resultSetMetaData); @@ -238,9 +293,44 @@ return(statement); } + public int getUpdateCount() throws SQLException { + return this.updateCount; + } + + public int getUpdateCountCount() { + return this.updateCountCount; + } + + public int getResultCount() { + return this.resultCount; + } + + /** + * retrieve next result, check whether it is an result set or an + * update count. Set instance vars accordingly and update + * counters. + */ public boolean getMoreResults() throws SQLException { - return (statement!=null? statement.getMoreResults() : false); + if (this.statement==null) + return false; + this.hasResultSet = this.statement.getMoreResults(); + this.resultSetValid=false; + this.adjustCounts(); + return (this.hasResultSet || (this.updateCount>-1)); } + + + /** + * update counters for result sets and update counts + */ + protected void adjustCounts() throws SQLException { + this.updateCount=this.statement.getUpdateCount(); + if (this.hasResultSet) { + this.resultCount++; + } else { + this.updateCountCount++; + } + }; public boolean execute() throws SQLException { return this.execute(false); No revision No revision 1.13.2.5 +149 -162 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/esql.xsl Index: esql.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/esql.xsl,v retrieving revision 1.13.2.4 retrieving revision 1.13.2.5 diff -u -r1.13.2.4 -r1.13.2.5 --- esql.xsl 7 May 2002 08:09:13 -0000 1.13.2.4 +++ esql.xsl 4 Jun 2002 09:37:17 -0000 1.13.2.5 @@ -1,6 +1,6 @@ <?xml version="1.0"?> -<!-- $Id: esql.xsl,v 1.13.2.4 2002/05/07 08:09:13 haul Exp $--> +<!-- $Id: esql.xsl,v 1.13.2.5 2002/06/04 09:37:17 haul Exp $--> <!-- ============================================================================ @@ -56,7 +56,7 @@ * ESQL Logicsheet * * @author ? - * @version CVS $Revision: 1.13.2.4 $ $Date: 2002/05/07 08:09:13 $ + * @version CVS $Revision: 1.13.2.5 $ $Date: 2002/06/04 09:37:17 $ --> <xsl:stylesheet version="1.0" @@ -358,6 +358,87 @@ <xsl:template match="esql:connection/esql:use-limit-clause"/> <xsl:template match="esql:connection/esql:property"/> + +<!-- set one parameter of a prepared or callable statement and use correct method for type --> +<xsl:template name="set-query-parameter"> + <xsl:choose> + <xsl:when test="@type"> + <xsl:variable name="type"><xsl:value-of select="concat(translate(substring(@type,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),substring(@type,2))"/></xsl:variable> + <xsl:text>set</xsl:text><xsl:value-of select="$type"/>(<xsl:value-of select="position()"/>,<xsl:call-template name="get-nested-content"><xsl:with-param name="content" select="."/></xsl:call-template>);<xsl:text> + </xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>setString(</xsl:text><xsl:value-of select="position()"/>,String.valueOf(<xsl:call-template name="get-nested-string"><xsl:with-param name="content" select="."/></xsl:call-template>));<xsl:text> + </xsl:text> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xspdoc:desc> internal. set one parameter of a callable statement </xspdoc:desc> +<xsl:template name="set-call-parameter"> + <xsl:if test="@direction='out' or @direction='inout'"> + <xsl:text>_esql_query.getCallableStatement().</xsl:text> + registerOutParameter(<xsl:value-of select="position()"/>, Types.<xsl:call-template name="get-Sql-Type"><xsl:with-param name="type"><xsl:value-of select="@type"/></xsl:with-param></xsl:call-template><xsl:if test="@typename">, <xsl:value-of select="@typename"/> </xsl:if>); + </xsl:if> + <xsl:if test="not(@direction) or @direction='inout' or @direction='in'"> + <xsl:text>_esql_query.getCallableStatement().</xsl:text> + <xsl:call-template name="set-query-parameter"/> + </xsl:if> +</xsl:template> + + + +<xspdoc:desc> internal. set one parameter of a prepared statement </xspdoc:desc> +<xsl:template name="set-parameter"> + <xsl:text>_esql_query.getPreparedStatement().</xsl:text> + <xsl:call-template name="set-query-parameter"/> +</xsl:template> + +<xsl:template name="do-results"> + do { + if (_esql_query.hasResultSet()) { + _esql_query.getResultRows(); + if (_esql_query.nextRow()) { + switch (_esql_query.getResultCount()) { + <xsl:for-each select="esql:results"> + case <xsl:value-of select="position()"/>: <xsl:if test="position()=last()"><xsl:text> + default: </xsl:text></xsl:if><xsl:apply-templates select="."/> + break; + </xsl:for-each> + } + } else { + switch (_esql_query.getUpdateCountCount()) { + <xsl:for-each select="esql:no-results"> + case <xsl:value-of select="position()"/>: <xsl:if test="position()=last()"><xsl:text> + default: </xsl:text></xsl:if><xsl:apply-templates select="."/> + break; + </xsl:for-each> + } + } + _esql_query.getResultSet().close(); + } else { + if (_esql_query.getUpdateCount() >= 0) { + switch (_esql_query.getUpdateCountCount()) { + <xsl:for-each select="esql:update-results"> + case <xsl:value-of select="position()"/>: <xsl:if test="position()=last()"><xsl:text> + default: </xsl:text></xsl:if><xsl:apply-templates select="."/> + break; + </xsl:for-each> + } + } else { + switch (_esql_query.getUpdateCountCount()) { + <xsl:for-each select="esql:no-results"> + case <xsl:value-of select="position()"/>: <xsl:if test="position()=last()"><xsl:text> + default: </xsl:text></xsl:if><xsl:apply-templates select="."/> + break; + </xsl:for-each> + } + } + } + } while(_esql_query.getMoreResults()); +</xsl:template> + + <xsl:template match="esql:connection//esql:execute-query"> <xsl:variable name="query"><xsl:choose><xsl:when test="esql:query"><xsl:call-template name="get-nested-string"><xsl:with-param name="content" select="esql:query"/></xsl:call-template></xsl:when><xsl:when test="esql:call"><xsl:call-template name="get-nested-string"><xsl:with-param name="content" select="esql:call"/></xsl:call-template></xsl:when></xsl:choose></xsl:variable> @@ -385,117 +466,45 @@ try { <xsl:choose> <xsl:when test="esql:call"> - try { _esql_query.prepareCall(); - } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>) { - throw new RuntimeException("Error preparing statement: " + _esql_query.getQueryString() + ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>.getMessage()); - } <xsl:for-each select="esql:call//esql:parameter"> - try { - <xsl:if test="@direction='out' or @direction='inout'"> - <xsl:text>_esql_query.getCallableStatement().</xsl:text> - registerOutParameter(<xsl:value-of select="position()"/>, Types.<xsl:call-template name="get-Sql-Type"><xsl:with-param name="type"><xsl:value-of select="@type"/></xsl:with-param></xsl:call-template><xsl:if test="@typename">, <xsl:value-of select="@typename"/> </xsl:if>); - </xsl:if> - <xsl:if test="not(@direction) or @direction='inout' or @direction='in'"> - <xsl:text>_esql_query.getCallableStatement().</xsl:text> - <xsl:choose> - <xsl:when test="@type"> - <xsl:variable name="type"><xsl:value-of select="concat(translate(substring(@type,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),substring(@type,2))"/></xsl:variable> - <xsl:text>set</xsl:text><xsl:value-of select="$type"/>(<xsl:value-of select="position()"/>,<xsl:call-template name="get-nested-content"><xsl:with-param name="content" select="."/></xsl:call-template>);<xsl:text> -</xsl:text> - </xsl:when> - <xsl:otherwise> - <xsl:text>setString(</xsl:text><xsl:value-of select="position()"/>,String.valueOf(<xsl:call-template name="get-nested-string"><xsl:with-param name="content" select="."/></xsl:call-template>));<xsl:text> -</xsl:text> - </xsl:otherwise> - </xsl:choose> - </xsl:if> - } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>) { - throw new RuntimeException("Error setting parameter on statement: " + _esql_query.getQueryString() + ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>); - } + <xsl:call-template name="set-call-parameter"/> </xsl:for-each> - try { <xsl:choose> <xsl:when test="esql:call[@needs-query='true' or @needs-query='yes']">_esql_query.execute(true);</xsl:when> <xsl:when test="esql:call[@resultset-from-object]">_esql_query.execute(<xsl:copy-of select="esql:call[@resultset-from-object]"/>);</xsl:when> <xsl:otherwise>_esql_query.execute();</xsl:otherwise> </xsl:choose> - } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>) { - throw new RuntimeException("Error executing prepared statement: " + _esql_query.getQueryString() + ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>); - } </xsl:when> <xsl:when test="esql:query//esql:parameter"> - try { _esql_query.prepareStatement(); - } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>) { - throw new RuntimeException("Error preparing statement: " + _esql_query.getQueryString() + ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>.getMessage()); - } <xsl:for-each select="esql:query//esql:parameter"> - try { - <xsl:text>_esql_query.getPreparedStatement().</xsl:text> - <xsl:choose> - <xsl:when test="@type"> - <xsl:variable name="type"><xsl:value-of select="concat(translate(substring(@type,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),substring(@type,2))"/></xsl:variable> - <xsl:text>set</xsl:text><xsl:value-of select="$type"/>(<xsl:value-of select="position()"/>,<xsl:call-template name="get-nested-content"><xsl:with-param name="content" select="."/></xsl:call-template>);<xsl:text> -</xsl:text> - </xsl:when> - <xsl:otherwise> - <xsl:text>setString(</xsl:text><xsl:value-of select="position()"/>,String.valueOf(<xsl:call-template name="get-nested-string"><xsl:with-param name="content" select="."/></xsl:call-template>));<xsl:text> -</xsl:text> - </xsl:otherwise> - </xsl:choose> - } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>) { - throw new RuntimeException("Error setting parameter on statement: " + _esql_query.getQueryString() + ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>); - } + <xsl:call-template name="set-parameter"/> </xsl:for-each> - try { _esql_query.execute(); - } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>) { - throw new RuntimeException("Error executing prepared statement: " + _esql_query.getQueryString() + ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>); - } </xsl:when> <xsl:otherwise> _esql_query.createStatement(); - try { - _esql_query.execute(); - } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>) { - throw new RuntimeException("Error executing statement: " + _esql_query.getQueryString() + ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>); - } + _esql_query.execute(); </xsl:otherwise> </xsl:choose> getLogger().debug("esql query: " + _esql_query.getQueryString()); + + <xsl:call-template name="do-results"/> + <xsl:if test="esql:call"> // call results <xsp:content> <xsl:apply-templates select="esql:call-results"/> </xsp:content> </xsl:if> - if (_esql_query.hasResultSet()) { - do { - _esql_query.getResultRows(); - if (_esql_query.nextRow()) { - <xsl:apply-templates select="esql:results"/> - } - else { - <xsl:apply-templates select="esql:no-results"/> - } - _esql_query.getResultSet().close(); - - } while(_esql_query.getMoreResults()); - } else { - if (_esql_query.getStatement().getUpdateCount() >= 0) { - <xsl:apply-templates select="esql:update-results/*"/> - } - else{ - <xsl:apply-templates select="esql:no-results"/> - } - } _esql_query.getStatement().close(); + } catch (SQLException _esql_exception_<xsl:value-of select="generate-id(.)"/>) { - try { <xsl:choose> <xsl:when test="esql:error-results"> + try { _esql_exception = _esql_exception_<xsl:value-of select="generate-id(.)"/>; _esql_exception_writer = new StringWriter(); _esql_exception.printStackTrace(new PrintWriter(_esql_exception_writer)); @@ -503,14 +512,17 @@ if (!_esql_connection.getAutoCommit()) { _esql_connection.rollback(); } + } catch (Exception _esql_exception_<xsl:value-of select="generate-id(.)"/>_2) {} </xsl:when> <xsl:otherwise> + try { if (!_esql_connection.getAutoCommit()) { _esql_connection.rollback(); } + } catch (Exception _esql_exception_<xsl:value-of select="generate-id(.)"/>_2) {} + throw new RuntimeException("Error executing statement: " + _esql_query.getQueryString() + ": "+_esql_exception_<xsl:value-of select="generate-id(.)"/>); </xsl:otherwise> </xsl:choose> - } catch (Exception _esql_exception_<xsl:value-of select="generate-id(.)"/>_2) {} } if (_esql_queries.empty()) { _esql_query = null; @@ -555,24 +567,18 @@ </xsl:template> <xsl:template match="esql:update-results//esql:get-update-count"> - <xsp:expr>_esql_query.getStatement().getUpdateCount()</xsp:expr> + <xsp:expr>_esql_query.getUpdateCount()</xsp:expr> </xsl:template> <xsl:template match="esql:results//esql:row-results"> <xsl:variable name="group" select=".//esql:group"/> <xsp:logic> - - //create booleans for group change watches and strings for old values. - <xsl:apply-templates select=".//esql:group" mode="vars"/> - do { <xsp:content> <xsl:apply-templates/> </xsp:content> - <xsl:if test="count($group) < 1"> - <xsl:call-template name="nextRow"/> - </xsl:if> + <xsl:call-template name="nextRow"/> } while ( _esql_query.keepGoing() ); if (_esql_query.getSkipRows() > 0 ) { @@ -587,17 +593,23 @@ +<xspdoc:desc>Only advance one row if no nested groups exist in this query. Ignore nested queries.</xspdoc:desc> <xsl:template name="nextRow"> + <xsl:if test="not(.//esql:group) or generate-id(.//esql:group)=generate-id(.//esql:execute-query//esql:group)"> + <xsp:logic> //checking out early? if (_esql_query.getMaxRows() != -1 && _esql_query.getCurrentRow() - _esql_query.getSkipRows() == _esql_query.getMaxRows()) { _esql_query.setKeepGoing( false ); } else { //if not, advance normally _esql_query.setKeepGoing( _esql_query.nextRow() ); } + </xsp:logic> + </xsl:if> </xsl:template> + <xsl:template match="esql:results//esql:previous-results"/> @@ -609,67 +621,41 @@ -<xsl:template match="esql:group" mode="vars"> - _esql_query.setGroupingVar("<xsl:value-of select="@group-on"/>Changed", new Boolean(true)); -</xsl:template> - - - -<xspdoc:desc>Allows header and footer elements around groups of consecutive records with identical values in column named by @group-on. Facilitates a single query with joins to be used in lieu of some nested queries.</xspdoc:desc> -<xsl:template match="esql:group|esql:group//esql:group[.//esql:member]" priority="3"> -<xsp:logic> - if (((Boolean)_esql_query.getGroupingVar("<xsl:value-of select="@group-on"/>Changed")).booleanValue()){ - //header contents - <xsp:content> - <xsl:apply-templates> - <xsl:with-param name="group-on" select="@group-on"/> - </xsl:apply-templates> - </xsp:content> - } -</xsp:logic> -</xsl:template> - - -<xsl:template match="esql:group//node()[.//esql:member]"> - <xsl:param name="group-on"/> - <xsl:copy> - <xsl:apply-templates select="@*|*|text()"> - <xsl:with-param name="group-on" select="$group-on"/> - </xsl:apply-templates> - </xsl:copy> +<xspdoc:desc>Allows header elements around groups of consecutive records with identical values in column named by @group-on. Facilitates a single query with joins to be used in lieu of some nested queries.</xspdoc:desc> +<xsl:template match="esql:group//esql:member"> + <xsp:logic> + do { + <xsp:content> + <xsl:apply-templates/> + </xsp:content> + <xsl:call-template name="nextRow"/> + } while (_esql_query.keepGoing() && !_esql_query.hasGroupingVarChanged()); + </xsp:logic> </xsl:template> +<xspdoc:desc>Used in conjunction with and nested inside esql:group. Formatting for individual records goes within esql:member. Header stuff goes in between group and member.</xspdoc:desc> +<xsl:template match="esql:group"> + <xsl:variable name="group"> + <xsl:call-template name="get-column"> + <xsl:with-param name="name">group-on</xsl:with-param> + </xsl:call-template> + </xsl:variable> -<xspdoc:desc>Used in conjunction with and nested inside esql:group. Formatting for individual records goes within esql:member. Header and footer stuff goes in between group and member.</xspdoc:desc> -<xsl:template match="esql:member|esql:group//esql:member[.//esql:member]"> - <xsl:param name="group-on"/> - <xsl:variable name="group" select=".//esql:group"/> <xsp:logic> - } - _esql_query.setGroupingVar("<xsl:value-of select="$group-on"/>Old", _esql_query.getResultSet().getString("<xsl:value-of select="$group-on"/>")); + _esql_query.groupLevelPlusPlus(); + if (!_esql_query.groupLevelExists()) { + _esql_query.setGroupingVar(<xsl:copy-of select="$group"/>); + } <xsp:content> - <xsl:apply-templates> - <xsl:with-param name="group-on" select="$group-on"/> - </xsl:apply-templates> + <xsl:apply-templates/> </xsp:content> - - <xsl:if test="count($group) < 1"> - <xsl:call-template name="nextRow"/> - </xsl:if> - if ( _esql_query.keepGoing() ) { - _esql_query.setGroupingVar("<xsl:value-of select="$group-on"/>Changed", new Boolean(!((String)_esql_query.getGroupingVar("<xsl:value-of select="$group-on"/>Old")).equals(_esql_query.getResultSet().getString("<xsl:value-of select="$group-on"/>")))); - } else { - _esql_query.setGroupingVar("<xsl:value-of select="$group-on"/>Changed", new Boolean(true)); - } - if (((Boolean)_esql_query.getGroupingVar("<xsl:value-of select="$group-on"/>Changed")).booleanValue()) { - //footer contents + _esql_query.groupLevelMinusMinus(); </xsp:logic> </xsl:template> - <xsl:template match="esql:results//esql:more-results"/> <xsl:template match="esql:results//esql:more-results" mode="more"> @@ -863,7 +849,12 @@ <xsp:expr><xsl:call-template name="get-resultset"/>.getShort(<xsl:call-template name="get-column"/>)</xsp:expr> </xsl:template> -<xspdoc:desc>returns the value of the given column as a clob</xspdoc:desc> +<xspdoc:desc>returns the value of the given column as unicode string (column can be string or clob</xspdoc:desc> +<xsl:template match="esql:row-results//esql:get-clob" name="get-clob"> + <xsp:expr>EsqlHelper.getStringOrClob(<xsl:call-template name="get-resultset"/>,<xsl:call-template name="get-column"/>)</xsp:expr> +</xsl:template> + +<xspdoc:desc>returns the value of the given column as a clob as ascii string with optinal encoding</xspdoc:desc> <xsl:template match="esql:row-results//esql:get-ascii|esql:call-results//esql:get-ascii"> <xsp:expr>EsqlHelper.getAscii(<xsl:call-template name="get-resultset"/>, <xsl:call-template name="get-column"/>)</xsp:expr> </xsl:template> @@ -955,30 +946,21 @@ <xsl:template match="esql:result"/> -<xspdoc:desc>creates a nested query like block that uses the result set obtained from a column as current result set. Only row-results and no-results are supported as nested elements (i.e. more-results is not supported).</xspdoc:desc> +<xspdoc:desc>creates a nested query like block that uses the result set obtained from a column as current result set. This version is deprecated, please use <esql:use-result> instead.</xspdoc:desc> <xsl:template match="esql:row-results//esql:results[child::esql:result]|esql:call-results//esql:results[child::esql:result]"> + <xsl:call-template name="use-results"/> +</xsl:template> + +<xspdoc:desc>creates a nested query like block that uses the result set obtained from a column as current result set.</xspdoc:desc> +<xsl:template name="use-results" match="esql:use-results[child::esql:result]"> <xsp:logic> // nested result set if (_esql_query != null) { _esql_queries.push(_esql_query); } - _esql_query = new EsqlQuery((ResultSet) <xsl:apply-templates select="esql:result/*"/>); + _esql_query = new EsqlQuery((ResultSet) <xsl:apply-templates select="esql:result/*"/>); { - if (_esql_query.hasResultSet()) { - do { - _esql_query.getResultRows(); - - if (_esql_query.nextRow()) { - <xsl:apply-templates select="esql:row-results"/> - } else { - <xsl:apply-templates select="esql:no-results"/> - } - _esql_query.getResultSet().close(); - - } while(_esql_query.getMoreResults()); - } else { - <xsl:apply-templates select="esql:no-results"/> - } + <xsl:call-template name="do-results"/> } if (_esql_queries.empty()) { _esql_query = null; @@ -1022,9 +1004,10 @@ <xspdoc:desc>used internally to determine which column is the given column. if a column attribute exists and its value is a number, it is taken to be the column's position. if the value is not a number, it is taken to be the column's name. if a column attribute does not exist, an esql:column element is assumed to exist and to render as a string (after all of the xsp instructions have been evaluated), which is taken to be the column's name.</xspdoc:desc> <xsl:template name="get-column"> + <xsl:param name="name">column</xsl:param> <xsl:variable name="column"> <xsl:call-template name="get-parameter"> - <xsl:with-param name="name">column</xsl:with-param> + <xsl:with-param name="name"><xsl:value-of select="$name"/></xsl:with-param> <xsl:with-param name="required">true</xsl:with-param> </xsl:call-template> </xsl:variable> @@ -1063,11 +1046,9 @@ <xsl:otherwise>default</xsl:otherwise> </xsl:choose> </xsl:variable> - <xsl:value-of select="$resultset"/>.getBytes(<xsl:value-of select="$column-spec"/>) - == null ? "<xsl:value-of select="$null"/>" : <xsl:choose> <xsl:when test="$encoding = 'default'"> - <xsl:value-of select="$resultset"/>.getString(<xsl:value-of select="$column-spec"/>) + EsqlHelper.getAscii(<xsl:value-of select="$resultset"/>,<xsl:value-of select="$column-spec"/>) </xsl:when> <xsl:otherwise> EsqlHelper.getStringFromByteArray(<xsl:value-of select="$resultset"/>.getBytes @@ -1104,6 +1085,12 @@ <xsl:param name="message"/> <xsl:message terminate="yes"><xsl:value-of select="$message"/></xsl:message> </xsl:template> + +<!-- + swallow esql:param tags +--> +<xsl:template match="esql:param"/> + <xsl:template match="@*|node()" priority="-1"> <xsl:copy>
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]