Tag: cws_src680_qiq User: fs Date: 2006/06/27 01:06:15 Modified: dba/dbaccess/qa/complex/dbaccess/QueryInQuery.java
Log: some more test cases File Changes: Directory: /dba/dbaccess/qa/complex/dbaccess/ ============================================= File [changed]: QueryInQuery.java Url: http://dba.openoffice.org/source/browse/dba/dbaccess/qa/complex/dbaccess/QueryInQuery.java?r1=1.1.2.1&r2=1.1.2.2 Delta lines: +55 -12 --------------------- --- QueryInQuery.java 26 Jun 2006 21:11:09 -0000 1.1.2.1 +++ QueryInQuery.java 27 Jun 2006 08:06:12 -0000 1.1.2.2 @@ -4,9 +4,9 @@ * * $RCSfile: QueryInQuery.java,v $ * - * $Revision: 1.1.2.1 $ + * $Revision: 1.1.2.2 $ * - * last change: $Author: fs $ $Date: 2006/06/26 21:11:09 $ + * last change: $Author: fs $ $Date: 2006/06/27 08:06:12 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -34,6 +34,9 @@ ************************************************************************/ package complex.dbaccess; +import com.sun.star.container.ElementExistException; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.WrappedTargetException; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.sdb.CommandType; import com.sun.star.sdb.XSingleSelectQueryComposer; @@ -50,7 +53,9 @@ public String[] getTestMethodNames() { return new String[] { - "executeSimpleSelect" + "executeSimpleSelect", + "executeAliasedSelect", + "checkNameCollisions" }; } @@ -73,7 +78,7 @@ { m_database = new CRMDatabase( getORB() ); - m_database.getDatabase().getDataSource().createQuery( "products (inner)", "SELECT * FROM \"products\"" ); + m_database.getDatabase().getDataSource().createQuery( "query products", "SELECT * FROM \"products\"" ); XMultiServiceFactory connectionFactory = (XMultiServiceFactory)UnoRuntime.queryInterface( XMultiServiceFactory.class, m_database.getConnection() ); @@ -100,14 +105,12 @@ } // -------------------------------------------------------------------------------------------------------- - /** executes a SQL statement simply selecting all columns from a query - */ - public void executeSimpleSelect() throws SQLException + private void verifyEqualRowSetContent( int _outerCommandType, String _outerCommand, int _innerCommandType, String _innerCommand ) throws SQLException { - RowSet outerRowSet = m_database.getDatabase().createRowSet(CommandType.COMMAND, "SELECT * FROM \"products (inner)\"" ); + RowSet outerRowSet = m_database.getDatabase().createRowSet( _outerCommandType, _outerCommand ); outerRowSet.execute(); - RowSet innerRowSet = m_database.getDatabase().createRowSet(CommandType.QUERY, "products (inner)" ); + RowSet innerRowSet = m_database.getDatabase().createRowSet( _innerCommandType, _innerCommand ); innerRowSet.execute(); outerRowSet.last(); @@ -116,15 +119,55 @@ outerRowSet.beforeFirst(); innerRowSet.beforeFirst(); - assure( "wrong record counts", outerRowSet.getColumnCount() == innerRowSet.getColumnCount() ); + assure( "wrong column counts", outerRowSet.getColumnCount() == innerRowSet.getColumnCount() ); while ( outerRowSet.next() && innerRowSet.next() ) { - for ( int i=1; i < outerRowSet.getColumnCount(); ++i ) + for ( int i=1; i <= outerRowSet.getColumnCount(); ++i ) { assure( "content of column " + i + " of row " + outerRowSet.getRow() + " not identical", innerRowSet.getString(i).equals( outerRowSet.getString(i) ) ); } } + } + + // -------------------------------------------------------------------------------------------------------- + /** executes a SQL statement simply selecting all columns from a query + */ + public void executeSimpleSelect() throws SQLException + { + verifyEqualRowSetContent( + CommandType.COMMAND, "SELECT * FROM \"query products\"", + CommandType.QUERY, "query products" ); + } + + // -------------------------------------------------------------------------------------------------------- + /** verifies that aliases for inner queries work as expected + */ + public void executeAliasedSelect() throws SQLException + { + verifyEqualRowSetContent( + CommandType.COMMAND, "SELECT \"PROD\".\"ID\" FROM \"query products\" AS \"PROD\"", + CommandType.COMMAND, "SELECT \"ID\" FROM \"products\"" ); + verifyEqualRowSetContent( + CommandType.COMMAND, "SELECT \"PROD\".* FROM \"query products\" AS \"PROD\"", + CommandType.QUERY, "query products" ); + } + + // -------------------------------------------------------------------------------------------------------- + /** verifies that aliases for inner queries work as expected + */ + public void checkNameCollisions() + { + boolean caughtExpected = false; + try + { + m_database.getDatabase().getDataSource().createQuery( "products", "SELECT * FROM \"products\"" ); + } + catch ( WrappedTargetException e ) { caughtExpected = true; } + catch ( IllegalArgumentException e ) {} + catch ( ElementExistException e ) { caughtExpected = true; } + assure( "creating queries with the name of an existing table should not be possible", + caughtExpected ); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
