cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ba...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/processor/xsp/library/sql esql.xsl
Date Thu, 28 Sep 2000 01:52:39 GMT
balld       00/09/27 18:52:35

  Modified:    .        changes.xml
               samples/sql esql.xml
               src/org/apache/cocoon/processor/xsp/library/sql esql.xsl
  Log:
  a couple of bugs fixed in esql, plus i added the first bit of prepared statem
  ent support. nothing but strings yet, but it works.
  
  Revision  Changes    Path
  1.117     +4 -1      xml-cocoon/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/changes.xml,v
  retrieving revision 1.116
  retrieving revision 1.117
  diff -u -r1.116 -r1.117
  --- changes.xml	2000/09/27 23:35:43	1.116
  +++ changes.xml	2000/09/28 01:52:32	1.117
  @@ -4,7 +4,7 @@
   
   <!--
     History of Cocoon changes
  -  $Id: changes.xml,v 1.116 2000/09/27 23:35:43 greenrd Exp $
  +  $Id: changes.xml,v 1.117 2000/09/28 01:52:32 balld Exp $
   -->
   
   <changes title="History of Changes">
  @@ -17,6 +17,9 @@
     </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="DB" type="update">
  +   a couple of bugs fixed in esql, plus i added the first bit of prepared statement support.
nothing but strings yet, but it works.
  +  </action>
     <action dev="RDG" type="update" due-to="Marco Pauck" due-to-email="?">
      Changed default WML output encoding to iso-8859-1.
     </action>
  
  
  
  1.3       +33 -0     xml-cocoon/samples/sql/esql.xml
  
  Index: esql.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/samples/sql/esql.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- esql.xml	2000/09/14 20:44:34	1.2
  +++ esql.xml	2000/09/28 01:52:34	1.3
  @@ -7,6 +7,7 @@
     language="java"
     xmlns:esql="http://apache.org/cocoon/SQL/v2"
     xmlns:xsp="http://www.apache.org/1999/XSP/Core"
  +  xmlns:request="http://www.apache.org/1999/XSP/Request"
   >
   
   <page>
  @@ -17,6 +18,38 @@
   <esql:username>test</esql:username>
   <esql:password>test</esql:password>
   <esql:query>select * from department_table</esql:query>
  +<esql:results>
  + <department>
  + <id><esql:get-string column="id"/></id>
  + <name><esql:get-string column="name"/></name>
  + <employees>
  + <esql:execute-query>
  +  <esql:query>select * from employee_table where department_id = <esql:get-string
column="id" ancestor="1"/></esql:query>
  +  <esql:results>
  +   <employee>
  +   <id><esql:get-string column="id"/></id>
  +   <name><esql:get-string column="name"/></name>
  +   </employee>
  +  </esql:results>
  + </esql:execute-query>
  + </employees>
  + </department>
  +</esql:results>
  +<esql:no-results>
  + <error>no results were found</error>
  +</esql:no-results>
  +<esql:error-results>
  + <message><esql:get-message/></message>
  + <stacktrace><esql:get-stacktrace/></stacktrace>
  +</esql:error-results>
  +</esql:execute-query>
  +
  +<esql:execute-query>
  +<esql:driver>postgresql.Driver</esql:driver>
  +<esql:dburl>jdbc:postgresql://localhost/test</esql:dburl>
  +<esql:username>test</esql:username>
  +<esql:password>test</esql:password>
  +<esql:statement>select * from department_table where name = <esql:parameter><request:get-parameter
name="name"/></esql:parameter></esql:statement>
   <esql:results>
    <department>
    <id><esql:get-string column="id"/></id>
  
  
  
  1.16      +35 -11    xml-cocoon/src/org/apache/cocoon/processor/xsp/library/sql/esql.xsl
  
  Index: esql.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/library/sql/esql.xsl,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- esql.xsl	2000/09/15 05:07:35	1.15
  +++ esql.xsl	2000/09/28 01:52:35	1.16
  @@ -1,5 +1,5 @@
   <?xml version="1.0"?>
  -<!-- $Id: esql.xsl,v 1.15 2000/09/15 05:07:35 balld Exp $-->
  +<!-- $Id: esql.xsl,v 1.16 2000/09/28 01:52:35 balld Exp $-->
   <!--
   
    ============================================================================
  @@ -96,6 +96,7 @@
   			<xsp:include>java.sql.DriverManager</xsp:include>
   			<xsp:include>java.sql.Connection</xsp:include>
   			<xsp:include>java.sql.Statement</xsp:include>
  +			<xsp:include>java.sql.PreparedStatement</xsp:include>
   			<xsp:include>java.sql.ResultSet</xsp:include>
   			<xsp:include>java.sql.ResultSetMetaData</xsp:include>
   			<xsp:include>java.sql.SQLException</xsp:include>
  @@ -112,6 +113,7 @@
                     boolean close_connection = true;
   		  String query;
                     Statement statement;
  +		  PreparedStatement prepared_statement;
                     ResultSet resultset;
                     ResultSetMetaData resultset_metadata;
                     int count;
  @@ -187,6 +189,11 @@
   			<xsl:with-param name="content" select="esql:query"/>
   		</xsl:call-template>
   	</xsl:variable>
  +	<xsl:variable name="statement">
  +		<xsl:call-template name="get-nested-string">
  +			<xsl:with-param name="content" select="esql:statement"/>
  +		</xsl:call-template>
  +	</xsl:variable>
   	<xsp:logic>
   	 void _esql_execute_query_<xsl:value-of select="generate-id(.)"/>(
   	 HttpServletRequest request,
  @@ -240,9 +247,20 @@
   		  </xsl:choose>
   		 </xsl:otherwise>
   	        </xsl:choose>
  -	       _esql_session.statement = _esql_session.connection.createStatement();
  -	       _esql_session.query = String.valueOf(<xsl:copy-of select="$query"/>);
  -	       _esql_session.resultset = _esql_session.statement.executeQuery(_esql_session.query);
  +	       <xsl:choose>
  +	        <xsl:when test="esql:query">
  +	         _esql_session.query = String.valueOf(<xsl:copy-of select="$query"/>);
  +	         _esql_session.statement = _esql_session.connection.createStatement();
  +	         _esql_session.resultset = _esql_session.statement.executeQuery(_esql_session.query);
  +		</xsl:when>
  +		<xsl:when test="esql:statement">
  +		 _esql_session.prepared_statement = _esql_session.connection.prepareStatement(String.valueOf(<xsl:copy-of
select="$statement"/>));
  +		 <xsl:for-each select=".//esql:parameter">
  +		  _esql_session.prepared_statement.setString(<xsl:value-of select="position()"/>,String.valueOf(<xsl:call-template
name="get-nested-string"><xsl:with-param name="content" select="."/></xsl:call-template>));
  +		 </xsl:for-each>
  +	         _esql_session.resultset = _esql_session.prepared_statement.executeQuery();
  +		</xsl:when>
  +	       </xsl:choose>
   	       _esql_session.resultset_metadata = _esql_session.resultset.getMetaData();
   	       _esql_session.count = 0;
   	       if (_esql_session.skip_rows &gt; 0) {
  @@ -263,7 +281,11 @@
   		_esql_session.count++;
   	       }
   	       _esql_session.resultset.close();
  -	       _esql_session.statement.close();
  +	       if (_esql_session.statement != null) {
  +	         _esql_session.statement.close();
  +	       } else if (_esql_session.prepared_statement != null) {
  +	         _esql_session.prepared_statement.close();
  +	       }
   	       if (!_esql_results) {
                   <xsl:apply-templates select="esql:no-results/*"/>
   	       }
  @@ -290,6 +312,8 @@
   	</xsp:logic>
   </xsl:template>
   
  +<xsl:template match="esql:statement//esql:parameter">"?"</xsl:template>
  +
   <xspdoc:desc>if the query has results, this element's children will be instantiated
for each row in the result set</xspdoc:desc>
   <xsl:template match="esql:execute-query/esql:results">
    <xsl:apply-templates/>
  @@ -427,19 +451,19 @@
    <xsp:expr>_esql_session.count</xsp:expr>
   </xsl:template>
   
  - <xspdoc:desc>returns the name of the given column</xspdoc:desc>
  + <xspdoc:desc>returns the name of the given column. the column mus tbe specified
by number, not name.</xspdoc:desc>
   <xsl:template match="esql:results//esql:get-column-name">
  - <xsp:expr>_esql_session.resultset_metadata.getColumnName(<xsl:call-template name="get-column"/>)</xsp:expr>
  + <xsp:expr><xsl:call-template name="get-resultset"/>.getMetaData().getColumnName(<xsl:value-of
select="@column"/>)</xsp:expr>
   </xsl:template>
   
  - <xspdoc:desc>returns the label of the given column</xspdoc:desc>
  + <xspdoc:desc>returns the label of the given column. the column mus tbe specified
by number, not name.</xspdoc:desc>
   <xsl:template match="esql:results//esql:get-column-label">
  - <xsp:expr>_esql_session.resultset_metadata.getColumnLabel(<xsl:call-template
name="get-column"/>)</xsp:expr>
  + <xsp:expr><xsl:call-template name="get-resultset"/>.getMetaData().getColumnLabel(<xsl:value-of
select="@column"/>)</xsp:expr>
   </xsl:template>
   
  - <xspdoc:desc>returns the name of the type of the given column</xspdoc:desc>
  + <xspdoc:desc>returns the name of the type of the given column. the column must be
specified by number, not name.</xspdoc:desc>
   <xsl:template match="esql:results//esql:get-column-type-name">
  - <xsp:expr>_esql_session.resultset_metadata.getColumnTypeName(<xsl:call-template
name="get-column"/>)</xsp:expr>
  + <xsp:expr><xsl:call-template name="get-resultset"/>.getMetaData().getColumnTypeName(<xsl:value-of
select="@column"/>)</xsp:expr>
   </xsl:template>
   
    <xspdoc:desc>returns the message of the current exception</xspdoc:desc>
  
  
  

Mime
View raw message