cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r168617 - in /cocoon/blocks/unsupported/databases/trunk: java/org/apache/cocoon/transformation/SQLTransformer.java samples/samples.xml samples/stylesheets/sql2html.xsl samples/transform/sitemap.xmap samples/transform/sql-page2.xml samples/transform/sql-page3.xml
Date Fri, 06 May 2005 15:24:48 GMT
Author: vgritsenko
Date: Fri May  6 08:24:48 2005
New Revision: 168617

URL: http://svn.apache.org/viewcvs?rev=168617&view=rev
Log:
fix bug #25098

Modified:
    cocoon/blocks/unsupported/databases/trunk/java/org/apache/cocoon/transformation/SQLTransformer.java
    cocoon/blocks/unsupported/databases/trunk/samples/samples.xml
    cocoon/blocks/unsupported/databases/trunk/samples/stylesheets/sql2html.xsl
    cocoon/blocks/unsupported/databases/trunk/samples/transform/sitemap.xmap
    cocoon/blocks/unsupported/databases/trunk/samples/transform/sql-page2.xml
    cocoon/blocks/unsupported/databases/trunk/samples/transform/sql-page3.xml

Modified: cocoon/blocks/unsupported/databases/trunk/java/org/apache/cocoon/transformation/SQLTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/databases/trunk/java/org/apache/cocoon/transformation/SQLTransformer.java?rev=168617&r1=168616&r2=168617&view=diff
==============================================================================
--- cocoon/blocks/unsupported/databases/trunk/java/org/apache/cocoon/transformation/SQLTransformer.java
(original)
+++ cocoon/blocks/unsupported/databases/trunk/java/org/apache/cocoon/transformation/SQLTransformer.java
Fri May  6 08:24:48 2005
@@ -132,6 +132,12 @@
  * <code>own-connection</code> parameter.
  * </p>
  *
+ * <p>
+ * TODO: Support inserting of the XML data into the database without need to escape it.
+ *       Can be implemented by introducing new &lt;sql:xml/&gt; tag to indicate that
+ *       startSerializedXMLRecording(...) should be used.
+ * </p>
+ *
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  * @author <a href="mailto:giacomo.pati@pwr.ch">Giacomo Pati</a>
@@ -1158,7 +1164,7 @@
 
                 if (success) {
                     AttributesImpl attr = new AttributesImpl();
-                    if (this.showNrOfRows) {
+                    if (showNrOfRows) {
                         attr.addAttribute("", this.nrOfRowsAttr, this.nrOfRowsAttr, "CDATA",
String.valueOf(getNrOfRows()));
                     }
                     String name = getName();
@@ -1167,7 +1173,9 @@
                     }
                     start(this.rowsetElement, attr);
 
-                    if (!isStoredProcedure) {
+                    if (isStoredProcedure) {
+                        serializeStoredProcedure();
+                    } else {
                         while (next()) {
                             start(this.rowElement, EMPTY_ATTRIBUTES);
                             serializeRow();
@@ -1176,8 +1184,6 @@
                             }
                             end(this.rowElement);
                         }
-                    } else {
-                        serializeStoredProcedure();
                     }
 
                     end(this.rowsetElement);
@@ -1262,6 +1268,7 @@
 
         protected int getNrOfRows() throws SQLException {
             int nr = 0;
+
             if (rs != null) {
                 if (oldDriver) {
                     nr = -1;
@@ -1324,10 +1331,12 @@
             // If rv is not -1, then an SQL insert, update, etc, has
             // happened (see JDBC docs - return codes for executeUpdate)
             if (rv != -1) {
-                return false;
+                // Output row with return code. Once.
+                return true;
             }
 
             if (rs == null || !rs.next()) {
+                // No more rows.
                 return false;
             }
 
@@ -1400,18 +1409,20 @@
 
         protected void serializeRow()
         throws SQLException, SAXException {
-            if (!isUpdate && !isStoredProcedure) {
+            if (rv != -1) {
+                start("returncode", EMPTY_ATTRIBUTES);
+                serializeData(String.valueOf(rv));
+                end("returncode");
+                // We only want the return code shown once.
+                // Reset rv so next() returns false next time.
+                rv = -1;
+            } else {
                 for (int i = 1; i <= md.getColumnCount(); i++) {
                     String columnName = getColumnName(md.getColumnName(i));
                     start(columnName, EMPTY_ATTRIBUTES);
                     serializeData(getColumnValue(i));
                     end(columnName);
                 }
-            } else if (isUpdate && !isStoredProcedure) {
-                start("returncode", EMPTY_ATTRIBUTES);
-                serializeData(String.valueOf(rv));
-                end("returncode");
-                rv = -1; // we only want the return code shown once.
             }
         }
 

Modified: cocoon/blocks/unsupported/databases/trunk/samples/samples.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/databases/trunk/samples/samples.xml?rev=168617&r1=168616&r2=168617&view=diff
==============================================================================
--- cocoon/blocks/unsupported/databases/trunk/samples/samples.xml (original)
+++ cocoon/blocks/unsupported/databases/trunk/samples/samples.xml Fri May  6 08:24:48 2005
@@ -41,7 +41,8 @@
        Example with two queries nested into the third one.
      </sample>
      <sample name="XML Test" href="transform/sql-page3" xlink:role="dynamic">
-       Example with inserting XML into a database.
+       Example with inserting XML into a database and with a select statement
+       nested into the insert statement.
      </sample>
   </group>
 
@@ -68,7 +69,7 @@
        modular package which supports auto increments and more.
      </sample>
      <sample name="File Upload to Blob" href="mod-db/file-upload-blob">
-       A simple example demonstrating of populating a binary database column 
+       A simple example demonstrating of populating a binary database column
        via a multipart form file upload.
      </sample>
   </group>
@@ -107,5 +108,5 @@
        Start the tutorial application.
      </sample>
   </group>
-  
+
 </samples>

Modified: cocoon/blocks/unsupported/databases/trunk/samples/stylesheets/sql2html.xsl
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/databases/trunk/samples/stylesheets/sql2html.xsl?rev=168617&r1=168616&r2=168617&view=diff
==============================================================================
--- cocoon/blocks/unsupported/databases/trunk/samples/stylesheets/sql2html.xsl (original)
+++ cocoon/blocks/unsupported/databases/trunk/samples/stylesheets/sql2html.xsl Fri May  6
08:24:48 2005
@@ -60,6 +60,13 @@
 
   <xsl:template match="sql:description"/>
 
+  <xsl:template match="sql:returncode">
+    <td>
+      <xsl:copy-of select="node()"/>
+      rows updated.
+    </td>
+  </xsl:template>
+
   <xsl:template match="sql:id">
     <!-- ignore -->
   </xsl:template>

Modified: cocoon/blocks/unsupported/databases/trunk/samples/transform/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/databases/trunk/samples/transform/sitemap.xmap?rev=168617&r1=168616&r2=168617&view=diff
==============================================================================
--- cocoon/blocks/unsupported/databases/trunk/samples/transform/sitemap.xmap (original)
+++ cocoon/blocks/unsupported/databases/trunk/samples/transform/sitemap.xmap Fri May  6 08:24:48
2005
@@ -36,8 +36,8 @@
 <!-- =========================== Pipelines ================================= -->
 
   <map:pipelines>
-
     <map:pipeline>
+
       <map:match pattern="*">
         <map:generate src="{1}.xml"/>
         <!--
@@ -55,7 +55,7 @@
           <map:parameter name="contextPath" value="{request:contextPath}"/>
           <map:parameter name="file" value=".xml"/>
         </map:transform>
-        <map:serialize/>
+        <map:serialize type="html"/>
       </map:match>
 
       <map:match pattern="">

Modified: cocoon/blocks/unsupported/databases/trunk/samples/transform/sql-page2.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/databases/trunk/samples/transform/sql-page2.xml?rev=168617&r1=168616&r2=168617&view=diff
==============================================================================
--- cocoon/blocks/unsupported/databases/trunk/samples/transform/sql-page2.xml (original)
+++ cocoon/blocks/unsupported/databases/trunk/samples/transform/sql-page2.xml Fri May  6 08:24:48
2005
@@ -24,7 +24,7 @@
   </resources>
 
   <content>
-    <para>This is my first Cocoon2 page filled with SQL data!</para>
+    <para>This is another page filled with SQL data.</para>
 
     <sql:execute-query xmlns:sql="http://apache.org/cocoon/SQL/2.0">
       <sql:query>

Modified: cocoon/blocks/unsupported/databases/trunk/samples/transform/sql-page3.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/databases/trunk/samples/transform/sql-page3.xml?rev=168617&r1=168616&r2=168617&view=diff
==============================================================================
--- cocoon/blocks/unsupported/databases/trunk/samples/transform/sql-page3.xml (original)
+++ cocoon/blocks/unsupported/databases/trunk/samples/transform/sql-page3.xml Fri May  6 08:24:48
2005
@@ -24,18 +24,32 @@
   </resources>
 
   <content>
-    <para>This is my first Cocoon2 page filled with SQL data!</para>
+    <para>This page inserts a row into the table.</para>
 
     <sql:execute-query xmlns:sql="http://apache.org/cocoon/SQL/2.0">
       <sql:query>
-        select max(id) as maxid from department
+        select (max(id)+1) as maxid from department
       </sql:query>
       <sql:execute-query>
+        <!--
+          - Don't do this in real applications: use sequences or auto increment fields.
+          -->
         <sql:query>
-         insert into department (id, name, description) 
-             values(<sql:ancestor-value name="maxid" level="1"/> + 1, 'XML Test',
-            '<span>An XML Test</span>')
+          insert into department (id, name, description)
+          values(<sql:ancestor-value name="maxid" level="1"/>,
+                 'XML Test <sql:ancestor-value name="maxid" level="1"/>',
+                 '&lt;span&gt;A <sql:ancestor-value name="maxid" level="1"/>th
attempt to insert &lt;i&gt;XML&lt;/i&gt; into the database.&lt;/span&gt;')
         </sql:query>
+
+        <!--
+          - Output data after update is complete.
+          -->
+        <sql:execute-query>
+          <sql:query>
+            select id, name, description from department
+          </sql:query>
+        </sql:execute-query>
+
       </sql:execute-query>
     </sql:execute-query>
   </content>



Mime
View raw message