cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject cvs commit: xml-cocoon2/src/documentation/xdocs/userdocs/xsp esql.xml
Date Sun, 17 Nov 2002 19:10:07 GMT
haul        2002/11/17 11:10:07

  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
               src/java/org/apache/cocoon/acting Tag: cocoon_2_0_3_branch
                        DatabaseAuthenticatorAction.java
               src/java/org/apache/cocoon/acting/modular Tag:
                        cocoon_2_0_3_branch DatabaseAction.java
                        TestAction.java
               src/documentation/xdocs/userdocs/xsp Tag:
                        cocoon_2_0_3_branch esql.xml
  Log:
    <action dev="CH" type="update">
     Changed SimpleFormTransformer to use InputModules.
    </action>
    <action dev="CH" type="update">
     Changed InputModules to return Iterator instead of Enumeration. New abstract
     "meta" module to make new meta modules easier. Stripped "meta" from defaults
     module. Added JXPathMetaModule. Added extension classes and packages to all
     modules that are based on JXPath.
    </action>
    <action dev="CH" type="update">
     Improved support for CLOB and BLOB columns in modular database actions.
    </action>
    <action dev="CH" type="add">
     New chaining InputModule that allows to use additional modules when an attribute is not
     present or null.
    </action>
    <action dev="CH" type="update">
     Changed defaults of InputModule names in many places to new names.
    </action>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.6.2.4   +2 -2      xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/Attic/EsqlConnection.java
  
  Index: EsqlConnection.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/Attic/EsqlConnection.java,v
  retrieving revision 1.6.2.3
  retrieving revision 1.6.2.4
  diff -u -r1.6.2.3 -r1.6.2.4
  --- EsqlConnection.java	28 Jun 2002 08:16:42 -0000	1.6.2.3
  +++ EsqlConnection.java	17 Nov 2002 19:10:06 -0000	1.6.2.4
  @@ -100,7 +100,7 @@
     }
   
     public String getUrl() {
  -    if (this.url == null) 
  +    if (this.url == null)
         try {
           this.url=this.connection.getMetaData().getURL();
         } catch (SQLException e) {
  
  
  
  1.7.2.3   +47 -24    xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/Attic/EsqlHelper.java
  
  Index: EsqlHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/Attic/EsqlHelper.java,v
  retrieving revision 1.7.2.2
  retrieving revision 1.7.2.3
  diff -u -r1.7.2.2 -r1.7.2.3
  --- EsqlHelper.java	5 Jul 2002 14:43:14 -0000	1.7.2.2
  +++ EsqlHelper.java	17 Nov 2002 19:10:06 -0000	1.7.2.3
  @@ -115,10 +115,11 @@
   
       /** returns byte array from BLOB
        */
  -    public final static byte[] getBlob(CallableStatement cs, int column) throws java.lang.Exception
{
  +    public final static byte[] getBlob(CallableStatement cs, int column, String defaultString)
throws java.lang.Exception {
           
           InputStream reader = null;
           byte[] buffer = null;
  +	byte[] result = null;
       
           try {
               Blob dbBlob = cs.getBlob(column);
  @@ -129,21 +130,23 @@
               reader.close();
               if (reader != null)
                   reader.close();
  -            if (buffer == null)
  -                return null;
  -            return buffer;
  +	    if(buffer != null) result = buffer;
  +	    else if(defaultString != null && !defaultString.equals("_null_"))
  +		result = defaultString.getBytes();
  +	    else result = null;
           } catch ( Exception e) {
               throw new RuntimeException("Error getting blob data: " + e.getMessage());
           }
  +	return result;
       }
   
       /** returns Unicode encoded string from CLOB or String column 
        */
  -    public final static String getStringOrClob(ResultSet set, String column) throws RuntimeException
{
  +    public final static String getStringOrClob(ResultSet set, String column, String defaultString)
throws RuntimeException {
           
           String result = null;
           try {
  -            result = EsqlHelper.getStringOrClob(set,set.findColumn(column));
  +            result = EsqlHelper.getStringOrClob(set,set.findColumn(column), defaultString);
           } catch (Exception e) {
               throw new RuntimeException("Error getting clob data: " + e.getMessage());
           }
  @@ -153,10 +156,11 @@
   
       /** returns Unicode encoded string from CLOB or String column 
        */
  -    public final static String getStringOrClob(ResultSet set, int column) throws java.lang.Exception
{
  +    public final static String getStringOrClob(ResultSet set, int column, String defaultString)
throws java.lang.Exception {
           
           Reader reader = null;
           char[] buffer = null;
  +	String result = null;
       
           try {
               if (set.getMetaData().getColumnType(column)==java.sql.Types.CLOB) {
  @@ -168,23 +172,29 @@
                   reader.close();
                   if (reader != null)
                       reader.close();
  -                if (buffer == null)
  -                    return "";
  -                return new String(buffer);
  +		if(buffer != null) result = new String(buffer);
  +		else if(defaultString != null && !defaultString.equals("_null_"))
  +		    result = defaultString;
  +		else result = null;
               } else {           
  -                return set.getString(column);
  +                result = set.getString(column);
  +		if(result == null &&
  +		   defaultString != null && !defaultString.equals("_null_"))
  +		    result = defaultString;
               }
           } catch ( Exception e) {
               throw new RuntimeException("Error getting clob data: " + e.getMessage());
           }
  +	return result;
       }
   
       /** returns Unicode encoded string from CLOB or String column 
        */
  -    public final static String getStringOrClob(CallableStatement cs, int column) throws
java.lang.Exception {
  +    public final static String getStringOrClob(CallableStatement cs, int column, String
defaultString) throws java.lang.Exception {
           
           Reader reader = null;
           char[] buffer = null;
  +	String result = null;
       
           try {
               Clob dbClob = cs.getClob(column);
  @@ -195,22 +205,24 @@
               reader.close();
               if (reader != null)
                   reader.close();
  -            if (buffer == null)
  -                return "";
  -            return new String(buffer);
  +	    if(buffer != null) result = new String(buffer);
  +	    else if(defaultString != null && !defaultString.equals("_null_"))
  +		result = defaultString;
  +	    else result = null;
           } 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, String column) throws RuntimeException
{
  +      public final static String getAscii(ResultSet set, String column, String defaultString)
throws RuntimeException {
   
             String result = null;
             try {
  -              result = EsqlHelper.getAscii(set,set.findColumn(column));
  +              result = EsqlHelper.getAscii(set,set.findColumn(column),defaultString);
             } catch (Exception e) {
                 throw new RuntimeException("Error getting clob data: " + e.getMessage());
             }
  @@ -220,7 +232,7 @@
   
       /** returns ascii string from CLOB or String column 
        */
  -      public final static String getAscii(ResultSet set, int column) {
  +      public final static String getAscii(ResultSet set, int column, String defaultString)
{
           InputStream asciiStream = null;
           String result = null;
   
  @@ -233,9 +245,15 @@
                   buffer = new byte[length];
                   asciiStream.read(buffer);
                   asciiStream.close();
  -                result = (buffer!=null? new String(buffer) : null);
  +		if(buffer != null) result = new String(buffer);
  +		else if(defaultString != null && !defaultString.equals("_null_"))
  +		    result = defaultString;
  +		else result = null;
               } else {
                   result = set.getString(column);
  +		if(result == null &&
  +                   defaultString != null && !defaultString.equals("_null_"))
  +		    result = defaultString;
               }
           } catch (Exception e) {
               throw new RuntimeException("Error getting clob data: " + e.getMessage());
  @@ -250,7 +268,7 @@
   
       /** returns ascii string from CLOB or String column 
        */
  -    public final static String getAscii(CallableStatement cs, int column) {
  +    public final static String getAscii(CallableStatement cs, int column, String defaultString)
{
           InputStream asciiStream = null;
           String result = null;
   
  @@ -262,7 +280,10 @@
               buffer = new byte[length];
               asciiStream.read(buffer);
               asciiStream.close();
  -            result = (buffer!=null? new String(buffer) : null);
  +	    if(buffer != null) result = new String(buffer);
  +	    else if(defaultString != null && !defaultString.equals("_null_"))
  +		result = defaultString;
  +	    else result = null;
           } catch (Exception e) {
               throw new RuntimeException("Error getting clob data: " + e.getMessage());
           } finally {
  @@ -274,7 +295,7 @@
           return result;
         }
   
  -      public final static String getStringFromByteArray(byte[] bytes, String encoding)
{
  +      public final static String getStringFromByteArray(byte[] bytes, String encoding,
String defaultString) {
           if (bytes != null) {
               try {
                   return new String(bytes,encoding);
  @@ -283,7 +304,9 @@
               }
           }
           else {
  -            return("");
  +	    if(defaultString != null && !defaultString.equals("_null_"))
  +		  return defaultString;
  +            else return null; /* before was "" but null is more consequent */
           }
         }
   
  
  
  
  1.11.2.10 +1 -14     xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/Attic/EsqlQuery.java
  
  Index: EsqlQuery.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/Attic/EsqlQuery.java,v
  retrieving revision 1.11.2.9
  retrieving revision 1.11.2.10
  diff -u -r1.11.2.9 -r1.11.2.10
  --- EsqlQuery.java	6 Sep 2002 10:00:21 -0000	1.11.2.9
  +++ EsqlQuery.java	17 Nov 2002 19:10:06 -0000	1.11.2.10
  @@ -194,10 +194,6 @@
           // Same error with TYPE_SCROLL_SENSITIVE.
           preparedStatement = connection.prepareStatement( getQueryString(),
                                                            ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
  -        if (maxRows > -1) {
  -            // if all JDBC driver's honoured this the code to quit after maxRows could
be removed
  -            preparedStatement.setMaxRows(skipRows + maxRows +1); // need this to determine
if there's more
  -        }
           break;
       case EsqlConnection.LIMIT_METHOD_NOLIMIT:
       default:
  @@ -205,9 +201,6 @@
           // which is not such a good name as its really another way of limiting using JDBC.
           // Produce non-scrollable ResultSet and skip rows with multiple ResultSet.next().
           preparedStatement = connection.prepareStatement(getQueryString() );
  -        if (maxRows > -1) {
  -            preparedStatement.setMaxRows(skipRows + maxRows +1); // need this to determine
if there's more
  -        }
           break;
       }
       statement = preparedStatement;
  @@ -223,16 +216,10 @@
           break;
       case EsqlConnection.LIMIT_METHOD_JDBC:
           preparedStatement = connection.prepareCall( getQueryString(), ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
  -        if (maxRows > -1) {
  -            preparedStatement.setMaxRows(skipRows + maxRows +1); // need this to determine
if there's more
  -        }
           break;
       case EsqlConnection.LIMIT_METHOD_NOLIMIT:
        default:
           preparedStatement = connection.prepareCall( getQueryString() );
  -        if (maxRows > -1) {
  -            preparedStatement.setMaxRows(skipRows + maxRows +1); // need this to determine
if there's more
  -        }
       };
       statement = preparedStatement;
       return((CallableStatement)preparedStatement);
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.13.2.10 +20 -8     xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/Attic/esql.xsl
  
  Index: esql.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/Attic/esql.xsl,v
  retrieving revision 1.13.2.9
  retrieving revision 1.13.2.10
  diff -u -r1.13.2.9 -r1.13.2.10
  --- esql.xsl	6 Sep 2002 09:59:31 -0000	1.13.2.9
  +++ esql.xsl	17 Nov 2002 19:10:06 -0000	1.13.2.10
  @@ -876,12 +876,24 @@
   
   <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|esql:call-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:param name="null">
  +   <xsl:choose>
  +    <xsl:when test="@null"><xsl:value-of select="@null"/></xsl:when>
  +    <xsl:otherwise>_null_</xsl:otherwise>
  +   </xsl:choose>
  +  </xsl:param>
  +  <xsp:expr>EsqlHelper.getStringOrClob(<xsl:call-template name="get-resultset"/>,<xsl:call-template
name="get-column"/>, "<xsl:value-of select="$null"/>")</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:param name="null">
  +   <xsl:choose>
  +    <xsl:when test="@null"><xsl:value-of select="@null"/></xsl:when>
  +    <xsl:otherwise>_null_</xsl:otherwise>
  +   </xsl:choose>
  +  </xsl:param>
  +  <xsp:expr>EsqlHelper.getAscii(<xsl:call-template name="get-resultset"/>,
<xsl:call-template name="get-column"/>, "<xsl:value-of select="$null"/>")</xsp:expr>
   </xsl:template>
   
    <xspdoc:desc>returns the value of the given column interpeted as an xml fragment.
  @@ -944,12 +956,12 @@
     <xsp:expr>_esql_query.getCurrentRow()</xsp:expr>
   </xsl:template>
   
  -<xspdoc:desc>returns the name of the given column. the column mus tbe specified by
number, not name.</xspdoc:desc>
  +<xspdoc:desc>returns the name of the given column. the column must be specified by
number, not name.</xspdoc:desc>
   <xsl:template match="esql:results//esql:get-column-name">
     <xsp:expr><xsl:call-template name="get-resultset"/>.getMetaData().getColumnName(<xsl:call-template
name="get-column"/>)</xsp:expr>
   </xsl:template>
   
  -<xspdoc:desc>returns the label of the given column. the column mus tbe specified
by number, not name.</xspdoc:desc>
  +<xspdoc:desc>returns the label of the given column. the column must be specified
by number, not name.</xspdoc:desc>
   <xsl:template match="esql:results//esql:get-column-label">
     <xsp:expr><xsl:call-template name="get-resultset"/>.getMetaData().getColumnLabel(<xsl:call-template
name="get-column"/>)</xsp:expr>
   </xsl:template>
  @@ -1088,11 +1100,11 @@
     </xsl:variable>
     <xsl:choose>
       <xsl:when test="$encoding = 'default'">
  -      EsqlHelper.getAscii(<xsl:value-of select="$resultset"/>,<xsl:value-of select="$column-spec"/>)
  +      EsqlHelper.getAscii(<xsl:value-of select="$resultset"/>,<xsl:value-of select="$column-spec"/>,"<xsl:value-of
select="$null"/>")
       </xsl:when>
       <xsl:otherwise>
         EsqlHelper.getStringFromByteArray(<xsl:value-of select="$resultset"/>.getBytes
  -        (<xsl:value-of select="$column-spec"/>), <xsl:value-of select="$encoding"/>)
  +        (<xsl:value-of select="$column-spec"/>), <xsl:value-of select="$encoding"/>,"<xsl:value-of
select="$null"/>")
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.2   +2 -2      xml-cocoon2/src/java/org/apache/cocoon/acting/Attic/DatabaseAuthenticatorAction.java
  
  Index: DatabaseAuthenticatorAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/Attic/DatabaseAuthenticatorAction.java,v
  retrieving revision 1.7.2.1
  retrieving revision 1.7.2.2
  diff -u -r1.7.2.1 -r1.7.2.2
  --- DatabaseAuthenticatorAction.java	25 Aug 2002 09:12:09 -0000	1.7.2.1
  +++ DatabaseAuthenticatorAction.java	17 Nov 2002 19:10:06 -0000	1.7.2.2
  @@ -264,7 +264,7 @@
               queryBuffer.append (" FROM ");
               queryBuffer.append (table.getAttribute ("name"));
               if (!queryBufferEnd.toString ().trim ().equals (""))
  -                queryBuffer.append (" WHERE ").append (queryBufferEnd);
  +                queryBuffer.append (" WHERE ").append (queryBufferEnd.toString ());
               return queryBuffer.toString ();
           } catch (Exception e) {
               getLogger ().debug ("DBAUTH: got exception: " + e);
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.8.2.2   +11 -10    xml-cocoon2/src/java/org/apache/cocoon/acting/modular/Attic/DatabaseAction.java
  
  Index: DatabaseAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/modular/Attic/DatabaseAction.java,v
  retrieving revision 1.8.2.1
  retrieving revision 1.8.2.2
  diff -u -r1.8.2.1 -r1.8.2.2
  --- DatabaseAction.java	2 Oct 2002 08:41:20 -0000	1.8.2.1
  +++ DatabaseAction.java	17 Nov 2002 19:10:07 -0000	1.8.2.2
  @@ -125,7 +125,10 @@
    *
    * <p>The number of affected rows is returned to the sitemap with the
    * "row-count" parameter if at least one row was affected.</p>
  -
  + *
  + * <p>All known column types can be found in 
  + * {@link org.apache.cocoon.util.JDBCTypeConversions JDBCTypeConversions}.</p>
  + *
    * <table>
    * <tr><td colspan="2">Configuration options (setup):</td></tr>
    * <tr><td>input            </td><td>default mode name for reading
values</td></tr>
  @@ -145,6 +148,7 @@
    * @see org.apache.cocoon.components.modules.input
    * @see org.apache.cocoon.components.modules.output
    * @see org.apache.cocoon.components.modules.database
  + * @see org.apache.cocoon.util.JDBCTypeConversions
    */
   public abstract class DatabaseAction  extends AbstractComplementaryConfigurableAction implements
Configurable, Disposable {
   
  @@ -159,8 +163,8 @@
       static final String ATTRIBUTE_KEY = "org.apache.cocoon.action.modular.DatabaseAction.outputModeName";
   
       // These can be overidden from cocoon.xconf
  -    static final String inputHint = "request"; // default to request parameters
  -    static final String outputHint = "attribute"; // default to request attributes
  +    static final String inputHint = "request-param"; // default to request parameters
  +    static final String outputHint = "request-attr"; // default to request attributes
       static final String databaseHint = "manual"; // default to manual auto increments
   
       static final String INPUT_MODULE_SELECTOR = InputModule.ROLE + "Selector";
  @@ -559,12 +563,9 @@
               set.columns[i].isSet = false;
               set.columns[i].isKey = isKey;
               set.columns[i].isAutoIncrement = false;
  -            if ( isKey & this.honourAutoIncrement() ) {
  -                String autoIncrement = set.columns[i].columnConf.getAttribute("autoincrement","false");
  -                if ( autoIncrement.equalsIgnoreCase("yes") || autoIncrement.equalsIgnoreCase("true")
) {
  -                    set.columns[i].isAutoIncrement = true;
  -                }
  -            }
  +            if ( isKey & this.honourAutoIncrement() ) 
  +                set.columns[i].isAutoIncrement = set.columns[i].columnConf.getAttributeAsBoolean("autoincrement",false);
  +            
               set.columns[i].modeConf = getMode( set.columns[i].columnConf,
                                                  selectMode( set.columns[i].isAutoIncrement,
modeTypes ) );
               set.columns[i].mode = ( set.columns[i].modeConf != null ?
  
  
  
  1.4.2.1   +6 -6      xml-cocoon2/src/java/org/apache/cocoon/acting/modular/TestAction.java
  
  Index: TestAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/modular/TestAction.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- TestAction.java	31 May 2002 07:38:58 -0000	1.4
  +++ TestAction.java	17 Nov 2002 19:10:07 -0000	1.4.2.1
  @@ -70,7 +70,7 @@
   import org.apache.cocoon.components.modules.input.InputModule;
   import org.apache.cocoon.components.modules.output.OutputModule;
   
  -import java.util.Enumeration;
  +import java.util.Iterator;
   import java.util.Map;
   import java.util.HashMap;
   
  @@ -101,8 +101,8 @@
       String defaultParameterName = null;
       boolean useGetValues = false;
   
  -    String inputHint = "request"; // default to request parameters
  -    String outputHint = "attribute"; // default to request attributes
  +    String inputHint = "request-param"; // default to request parameters
  +    String outputHint = "request-attr"; // default to request attributes
   
   
       public void configure(Configuration config) throws ConfigurationException {
  @@ -149,9 +149,9 @@
                       if (getLogger().isDebugEnabled()) getLogger().debug("reading all parameter
values");
                       // for a test, read all parameters from input and write them to outout
                       // get names first, then (one) value per name
  -                    Enumeration enum = input.getAttributeNames(this.inputConf,objectModel);
  -                    while (enum.hasMoreElements()) {
  -                        parameterName = (String) enum.nextElement();
  +                    Iterator iter = input.getAttributeNames(this.inputConf,objectModel);
  +                    while (iter.hasNext()) {
  +                        parameterName = (String) iter.next();
                           Object value = input.getAttribute(parameterName, this.inputConf,
objectModel);
                           output.setAttribute(this.outputConf, objectModel, parameterName,
value);
                           
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.5   +50 -2     xml-cocoon2/src/documentation/xdocs/userdocs/xsp/esql.xml
  
  Index: esql.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/documentation/xdocs/userdocs/xsp/esql.xml,v
  retrieving revision 1.4.2.4
  retrieving revision 1.4.2.5
  diff -u -r1.4.2.4 -r1.4.2.5
  --- esql.xml	11 Aug 2002 20:17:22 -0000	1.4.2.4
  +++ esql.xml	17 Nov 2002 19:10:07 -0000	1.4.2.5
  @@ -123,7 +123,51 @@
   </esql:connection>]]>
   </source>
   
  -   <s2 title="Refering to results">
  +   <s2 title="Dynamic Queries">
  +    <p>When a query contains dynamic parts, e.g. a value that is to be matched,
  +     esql offers two different possibilities to achieve that. First, as the 
  +     query is really a string, it can be constructed like any other string by 
  +     concattenation.
  +    </p>
  +
  +   <source><![CDATA[
  +    <xsp:logic>
  +       String orderBy = null;
  +       switch(type) {
  +       case 1: orderBy = "order by name"; break;
  +       case 2: orderBy = "order by salary"; break;
  +       default: orderBy = "";
  +       }
  +    </xsp:logic>
  +
  +    <!-- ... -->
  +
  +    <esql:query>SELECT name, salary FROM employee <xsp:expr>orderBy</xsp:expr></esql:query>
  +]]>
  +</source>
  +
  +    <p>Note, however, that here any string will be part of the actual
  +     statement. In this example it does no harm as the value for the
  +     <code>orderBy</code> variable is completely under the control of
  +     your code. Any malicious attacker could not inject his or her own
  +     code. Thus this technique should not be used when values returned
  +     from the client have to be used.
  +    </p>
  +    <p>The second variant is to use a PreparedStatement for dynamic 
  +     parameters. Since the driver is supposed to keep parameters
  +     distinct from the statement, no code can be injected this way. In
  +     addition, your DBMS puts more effort into optimizing the
  +     statement. PreparedStatements are created whenever a
  +     <code>&lt;esql:parameter/&gt;</code> tag appears in a query. 
  +    </p>
  +   <source><![CDATA[
  +    <esql:query>SELECT name, salary FROM employee 
  +                WHERE name=<esql:parameter><xsp:expr>name</xsp:expr></esql:parameter></esql:query>
  +]]>
  +   </source>
  +   </s2>
  +
  +   <s2 title="Refering to Results">
   
       <p>A select query usually returns one ResultSet. This case is handled by
        the <code>esql:results</code> tag and its content. However, many special
  @@ -237,7 +281,11 @@
        tags.  It follows the nesting ideology of <code>&lt;xsp:logic&gt; ...
         &lt;xsp:content&gt;&lt;/&gt;&lt;/&gt;</code>You can
nest
        <code>&lt;esql:group&gt;</code> and <code>&lt;esql:member&gt;</code>
  -     indefinately.</p>
  +     indefinately. <code>group-on</code> can be an attribute of
  +     <code>group</code> or a text node. The value of the text node has
  +     precedence over the attribute. The value can be the column name or the
  +     column number. 
  +     </p>
   
       <source><![CDATA[
   <esql:execute-query>
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message