Author: dr Date: Thu Jan 3 16:16:28 2008 New Revision: 7059 Log: - Fixed bug #11266: ezcQueryExpression->in( 'colname', array() ) produces a strange exception message.
Added: trunk/Database/src/exceptions/query/invalid_parameter.php (with props) Modified: trunk/Database/ChangeLog trunk/Database/design/class_diagram.png trunk/Database/src/db_autoload.php trunk/Database/src/query_autoload.php trunk/Database/src/sqlabstraction/expression.php trunk/Database/src/sqlabstraction/implementations/expression_oracle.php trunk/Database/tests/sqlabstraction/expression_test.php Modified: trunk/Database/ChangeLog ============================================================================== --- trunk/Database/ChangeLog [iso-8859-1] (original) +++ trunk/Database/ChangeLog [iso-8859-1] Thu Jan 3 16:16:28 2008 @@ -1,3 +1,10 @@ +1.3.4 - [RELEASEDATE] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Fixed bug #11266: ezcQueryExpression->in( 'colname', array() ) produces a + strange exception message. + + 1.3.3 - Wednesday 05 December 2007 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Modified: trunk/Database/design/class_diagram.png ============================================================================== Binary files - no diff available. Modified: trunk/Database/src/db_autoload.php ============================================================================== --- trunk/Database/src/db_autoload.php [iso-8859-1] (original) +++ trunk/Database/src/db_autoload.php [iso-8859-1] Thu Jan 3 16:16:28 2008 @@ -18,12 +18,12 @@ 'ezcDbUtilities' => 'Database/sqlabstraction/utilities.php', 'ezcDbFactory' => 'Database/factory.php', 'ezcDbHandlerMssql' => 'Database/handlers/mssql.php', - 'ezcDbMssqlOptions' => 'Database/options/identifiers.php', 'ezcDbHandlerMysql' => 'Database/handlers/mysql.php', 'ezcDbHandlerOracle' => 'Database/handlers/oracle.php', 'ezcDbHandlerPgsql' => 'Database/handlers/pgsql.php', 'ezcDbHandlerSqlite' => 'Database/handlers/sqlite.php', 'ezcDbInstance' => 'Database/instance.php', + 'ezcDbMssqlOptions' => 'Database/options/identifiers.php', 'ezcDbUtilitiesMysql' => 'Database/sqlabstraction/implementations/utilities_mysql.php', 'ezcDbUtilitiesOracle' => 'Database/sqlabstraction/implementations/utilities_oracle.php', 'ezcDbUtilitiesPgsql' => 'Database/sqlabstraction/implementations/utilities_pgsql.php', Added: trunk/Database/src/exceptions/query/invalid_parameter.php ============================================================================== --- trunk/Database/src/exceptions/query/invalid_parameter.php (added) +++ trunk/Database/src/exceptions/query/invalid_parameter.php [iso-8859-1] Thu Jan 3 16:16:28 2008 @@ -1,0 +1,33 @@ +<?php +/** + * File containing the ezcQueryInvalidParameterException class. + * + * @package Database + * @version //autogentag// + * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ + +/** + * Exception thrown when a method does not the receive correct variables it requires. + * + * @package Database + * @version //autogentag// + */ +class ezcQueryInvalidParameterException extends ezcQueryException +{ + /** + * Constructs an ezcQueryVariableParameterException. + * + * @param string $method + * @param int $parameterNumber + * @param string $foundContents + * @param string $expectedContents + */ + public function __construct( $method, $parameterNumber, $foundContents, $expectedContents ) + { + $info = "Argument '{$parameterNumber}' of method '{$method}' expects {$expectedContents} but {$foundContents} was provided."; + parent::__construct( $info ); + } +} +?> Propchange: trunk/Database/src/exceptions/query/invalid_parameter.php ------------------------------------------------------------------------------ svn:eol-style = native Modified: trunk/Database/src/query_autoload.php ============================================================================== --- trunk/Database/src/query_autoload.php [iso-8859-1] (original) +++ trunk/Database/src/query_autoload.php [iso-8859-1] Thu Jan 3 16:16:28 2008 @@ -12,6 +12,7 @@ return array( 'ezcQueryException' => 'Database/exceptions/query_exception.php', 'ezcQueryInvalidException' => 'Database/exceptions/query/invalid.php', + 'ezcQueryInvalidParameterException' => 'Database/exceptions/query/invalid_parameter.php', 'ezcQueryVariableParameterException' => 'Database/exceptions/query/variable_parameter.php', 'ezcQuery' => 'Database/sqlabstraction/query.php', 'ezcQueryExpression' => 'Database/sqlabstraction/expression.php', Modified: trunk/Database/src/sqlabstraction/expression.php ============================================================================== --- trunk/Database/src/sqlabstraction/expression.php [iso-8859-1] (original) +++ trunk/Database/src/sqlabstraction/expression.php [iso-8859-1] Thu Jan 3 16:16:28 2008 @@ -538,8 +538,9 @@ * * in() accepts an arbitrary number of parameters. The first parameter * must always specify the value that should be matched against. Successive - * must contain a logical expression or an array with logical expressions. - * These expressions will be matched against the first parameter. + * parameters must contain a logical expression or an array with logical + * expressions. These expressions will be matched against the first + * parameter. * * Example: * <code> @@ -552,7 +553,10 @@ * in resulting SQL query and saves time of converting strings to * numbers inside RDBMS. * - * @throws ezcDbAbstractionException if called with less than two parameters.. + * @throws ezcQueryVariableParameterException if called with less than two + * parameters. + * @throws ezcQueryInvalidParameterException if the 2nd parameter is an + * empty array. * @param string $column the value that should be matched against * @param string|array(string) $... values that will be matched against $column * @return string logical expression @@ -563,6 +567,11 @@ if ( count( $args ) < 2 ) { throw new ezcQueryVariableParameterException( 'in', count( $args ), 2 ); + } + + if ( is_array( $args[1] ) && count( $args[1] ) == 0 ) + { + throw new ezcQueryInvalidParameterException( 'in', 2, 'an empty array', 'a non-empty array' ); } $values = ezcQuerySelect::arrayFlatten( array_slice( $args, 1 ) ); Modified: trunk/Database/src/sqlabstraction/implementations/expression_oracle.php ============================================================================== --- trunk/Database/src/sqlabstraction/implementations/expression_oracle.php [iso-8859-1] (original) +++ trunk/Database/src/sqlabstraction/implementations/expression_oracle.php [iso-8859-1] Thu Jan 3 16:16:28 2008 @@ -239,12 +239,13 @@ /** * Returns the SQL to check if a value is one in a set of - * given values.. + * given values. * * in() accepts an arbitrary number of parameters. The first parameter * must always specify the value that should be matched against. Successive - * must contain a logical expression or an array with logical expressions. - * These expressions will be matched against the first parameter. + * parameters must contain a logical expression or an array with logical + * expressions. These expressions will be matched against the first + * parameter. * * Example: * <code> @@ -256,8 +257,10 @@ * implementation creates a list of combined IN() expressions to bypass * this limitation. * - * @throws ezcDbAbstractionException if called with less than two parameters.. - * @param string $column the value that should be matched against + * @throws ezcQueryVariableParameterException if called with less than two + * parameters. + * @throws ezcQueryInvalidParameterException if the 2nd parameter is an + * empty array. * @param string|array(string) values that will be matched against $column * @return string logical expression */ @@ -267,6 +270,11 @@ if ( count( $args ) < 2 ) { throw new ezcQueryVariableParameterException( 'in', count( $args ), 2 ); + } + + if ( is_array( $args[1] ) && count( $args[1] ) == 0 ) + { + throw new ezcQueryInvalidParameterException( 'in', 2, 'empty array', 'non-empty array' ); } $values = ezcQuerySelect::arrayFlatten( array_slice( $args, 1 ) ); Modified: trunk/Database/tests/sqlabstraction/expression_test.php ============================================================================== --- trunk/Database/tests/sqlabstraction/expression_test.php [iso-8859-1] (original) +++ trunk/Database/tests/sqlabstraction/expression_test.php [iso-8859-1] Thu Jan 3 16:16:28 2008 @@ -260,6 +260,19 @@ catch ( ezcQueryVariableParameterException $e ) {} } + public function testInEmptyArray() + { + try + { + $this->e->in( 'id', array() ); + $this->fail( "Expected exception not thrown" ); + } + catch ( ezcQueryInvalidParameterException $e ) + { + $this->assertEquals( "Argument '2' of method 'in' expects a non-empty array but an empty array was provided.", $e->getMessage() ); + } + } + public function testInSingle() { $reference = "id IN ( 1 )"; @@ -283,7 +296,31 @@ $reference = "id IN ( '1', '2' )"; $this->assertEquals( $reference, $this->e->in( 'id', '1', '2' ) ); } - + + public function testInSingleArray() + { + $reference = "id IN ( 1 )"; + $this->assertEquals( $reference, $this->e->in( 'id', array( 1 ) ) ); + } + + public function testInMultiArray() + { + $reference = "id IN ( 1, 2 )"; + $this->assertEquals( $reference, $this->e->in( 'id', array( 1, 2 ) ) ); + } + + public function testInMultiStringArray() + { + $reference = "id IN ( 'foo', 'bar' )"; + $this->assertEquals( $reference, $this->e->in( 'id', array( 'foo', 'bar' ) ) ); + } + + public function testInMultiNumericStringArray() + { + $reference = "id IN ( '1', '2' )"; + $this->assertEquals( $reference, $this->e->in( 'id', array( '1', '2' ) ) ); + } + public function testInStringQuoting() { if ( $this->db->getName() == 'mysql' ) -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components