home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / esql.xsp < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  5.4 KB  |  166 lines

  1. <?xml version="1.0"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17.  
  18. <!-- CVS: $Id: esql.xsp,v 1.5 2004/04/05 12:25:35 antonio Exp $ -->
  19.  
  20. <xsp:page language="java"
  21.           xmlns:xsp="http://apache.org/xsp"
  22.           xmlns:esql="http://apache.org/cocoon/SQL/v2">
  23.  
  24.   <page>
  25.    <title>A Database Driven XSP Page</title>
  26.     <resources>
  27.        <resource type="file" href="../transform/sql-page.xml.sql">Schema</resource>
  28.        <resource type="doc" href="userdocs/xsp/esql">ESQL</resource>
  29.     </resources>
  30.  
  31.    <content>
  32.  
  33.    <esql:connection>
  34.      <esql:pool>personnel</esql:pool>
  35.  
  36.  
  37.        <para>
  38.            Below you see all guys from the departments
  39.        </para>
  40.  
  41.        <esql:execute-query>
  42.          <esql:query>select * from employee</esql:query>
  43.          <esql:results>
  44.            <esql:row-results>
  45.              <para><esql:get-string column="name"/></para>
  46.              <!-- uncomment if you want columns to become tags -->
  47.              <!-- <esql:get-columns/> -->
  48.            </esql:row-results>
  49.          </esql:results>
  50.        </esql:execute-query>
  51.  
  52.        <hr/>
  53.  
  54.        <para>
  55.            Below you see just some of the guys
  56.        </para>
  57.  
  58.        <esql:execute-query>
  59.          <esql:query>select * from employee</esql:query>
  60.          <esql:use-limit-clause>jdbc</esql:use-limit-clause>
  61.          <esql:skip-rows>1</esql:skip-rows>
  62.          <esql:max-rows>2</esql:max-rows>
  63.          <esql:results>
  64.            <esql:row-results>
  65.              <para><esql:get-string column="name"/></para>
  66.            </esql:row-results>
  67.            <esql:previous-results>
  68.              We skipped some.
  69.            </esql:previous-results>
  70.            <esql:more-results>
  71.              There are some more.
  72.            </esql:more-results>
  73.            <para>
  74.              There is a total of <esql:row-count/> employees.
  75.            </para>
  76.          </esql:results>
  77.        </esql:execute-query>
  78.  
  79.        <hr/>
  80.  
  81.        <para>
  82.            Below departments and employees are printed.
  83.            Without the grouping feature, the result would look like this:
  84.        </para>
  85.  
  86.        <esql:execute-query>
  87.          <esql:query>
  88.            SELECT department.name, employee.id, employee.name as empName FROM department, employee
  89.            WHERE department.id = employee.department_id  ORDER BY department.name
  90.          </esql:query>
  91.          <esql:results>
  92.            <esql:row-results>
  93.              <Department>
  94.                <xsp:attribute name='name'><esql:get-string column='name'/></xsp:attribute>
  95.                <h2><esql:get-string column='name'/></h2>
  96.                <para><employee><esql:get-string column='empName'/></employee></para>
  97.              </Department>
  98.            </esql:row-results>
  99.          </esql:results>
  100.        </esql:execute-query>
  101.  
  102.        <hr/>
  103.  
  104.        <para>
  105.          This uses the grouping feature in esql.
  106.        </para>
  107.  
  108.        <esql:execute-query>
  109.          <esql:query>
  110.            SELECT department.name, employee.id, employee.name as empName FROM department, employee
  111.            WHERE department.id = employee.department_id  ORDER BY department.name
  112.          </esql:query>
  113.          <esql:results>
  114.            <esql:row-results>
  115.              <esql:group group-on='name'><!-- grouping -->
  116.                <Department>
  117.                  <xsp:attribute name='name'><esql:get-string column='name'/></xsp:attribute>
  118.                  <h2><esql:get-string column='name'/></h2>
  119.                  <esql:member><!-- grouping -->
  120.                    <para><employee><esql:get-string column='empName'/></employee></para>
  121.                  </esql:member><!--grouping -->
  122.                </Department>
  123.              </esql:group><!-- grouping -->
  124.            </esql:row-results>
  125.          </esql:results>
  126.        </esql:execute-query>
  127.  
  128.        <hr/>
  129.  
  130.        <para>
  131.          This uses nested queries.
  132.        </para>
  133.  
  134.        <esql:execute-query>
  135.          <esql:query>
  136.            SELECT name, id FROM department ORDER BY name
  137.          </esql:query>
  138.          <esql:results>
  139.            <esql:row-results>
  140.                <Department>
  141.                  <xsp:attribute name='name'><esql:get-string column='name'/></xsp:attribute>
  142.                  <h2><esql:get-string column='name'/></h2>
  143.                  
  144.                  <esql:execute-query>
  145.                     <esql:query>
  146.                        select name from employee 
  147.                        where department_id = <esql:parameter type="int"><esql:get-int column="id" ancestor="1"/></esql:parameter>
  148.                     </esql:query>
  149.                      <esql:results>
  150.                        <esql:row-results>
  151.                             <para><employee><esql:get-string column='name'/></employee></para>
  152.                         </esql:row-results>
  153.                      </esql:results>
  154.                  </esql:execute-query>
  155.  
  156.                </Department>
  157.            </esql:row-results>
  158.          </esql:results>
  159.        </esql:execute-query>
  160.  
  161.       </esql:connection>
  162.  
  163.    </content>
  164.   </page>
  165. </xsp:page>
  166.