Tag: cws_src680_qiq
User: fs      
Date: 2006/06/29 03:18:45

Modified:
   dba/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java

Log:
 #i51143# additional test case for parameters in nested queries

File Changes:

Directory: /dba/dbaccess/qa/complex/dbaccess/
=============================================

File [changed]: SingleSelectQueryComposer.java
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java?r1=1.4.124.1&r2=1.4.124.2
Delta lines:  +47 -3
--------------------
--- SingleSelectQueryComposer.java      26 Jun 2006 21:10:07 -0000      
1.4.124.1
+++ SingleSelectQueryComposer.java      29 Jun 2006 10:18:43 -0000      
1.4.124.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: SingleSelectQueryComposer.java,v $
  *
- *  $Revision: 1.4.124.1 $
+ *  $Revision: 1.4.124.2 $
  *
- *  last change: $Author: fs $ $Date: 2006/06/26 21:10:07 $
+ *  last change: $Author: fs $ $Date: 2006/06/29 10:18:43 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -34,6 +34,7 @@
  ************************************************************************/
 package complex.dbaccess;
 
+import com.sun.star.lang.WrappedTargetException;
 import com.sun.star.uno.UnoRuntime;
 import com.sun.star.beans.*;
 import com.sun.star.sdbcx.*;
@@ -69,7 +70,8 @@
     {
         return new String[] {
             "testAttributes",
-            "testSubQueries"
+            "testSubQueries",
+            "testParameters"
         };
     }
 
@@ -216,5 +218,47 @@
         String sExecutableQuery = m_composer.getQueryWithSubstitution();
         assure( "simple query containing a sub query improperly parsed to SDBC 
level statement",
             sExecutableQuery.equals( "SELECT * FROM ( " + sInnerCommand  + " ) 
AS \"" + innerProductsQuery + "\"") );
+    }
+
+    /** tests the XParametersSupplier functionality
+     */
+    public void testParameters()
+    {
+        try
+        {
+            // "orders for customers" is a query with a named parameter (based 
on another query)
+            m_database.getDatabase().getDataSource().createQuery( "orders for 
customer", "SELECT * FROM \"all orders\" WHERE \"Customer Name\" LIKE :cname" );
+            // "orders for customer and product" is query based on "orders for 
customers", adding an additional,
+            // anonymous parameter
+            m_database.getDatabase().getDataSource().createQuery( "orders for 
customer and product", "SELECT * FROM \"orders for customer\" WHERE \"Product 
Name\" LIKE ?" );
+
+            m_composer.setQuery( 
m_database.getDatabase().getDataSource().getQueryDefinition( "orders for 
customer and product" ).getCommand() );
+            XParametersSupplier suppParams = 
(XParametersSupplier)UnoRuntime.queryInterface(
+                XParametersSupplier.class, m_composer );
+            XIndexAccess parameters = suppParams.getParameters();
+
+            String expectedParamNames[] = {
+                "cname",
+                "Product Name"
+            };
+
+            int paramCount = parameters.getCount();
+            assure( "composer did find wrong number of parameters in the 
nested queries.",
+                paramCount == expectedParamNames.length );
+
+            for ( int i = 0; i < paramCount; ++i )
+            {
+                XPropertySet param = (XPropertySet)UnoRuntime.queryInterface(
+                    XPropertySet.class, parameters.getByIndex(i) );
+                String paramName = (String)param.getPropertyValue( "Name" );
+                assure( "wrong parameter name at position " + ( i + 1 ) + " 
(expected: " + expectedParamNames[i] + ", found: " + paramName + ")",
+                    paramName.equals( expectedParamNames[i] ) );
+                
+            }
+        }
+        catch( Exception e )
+        {
+            assure( "caught an exception: " + e, false );
+        }
     }
 }




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to