Commit 62204af8 authored by romanb's avatar romanb

[2.0] Ongoing work on Query/DQL implementation and tests.

parent f9a22281
......@@ -16,7 +16,7 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL;
......@@ -26,11 +26,10 @@ use Doctrine\DBAL\Types\Type;
/**
* Configuration container for the Doctrine DBAL.
*
* INTERNAL: When adding a new configuration option just write a getter/setter
* pair and add the option to the _attributes array with a proper default value.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
* @internal When adding a new configuration option just write a getter/setter
* pair and add the option to the _attributes array with a proper default value.
*/
class Configuration
{
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver;
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver;
use \PDO;
/**
* PDO implementation of the driver Connection interface.
* PDO implementation of the Connection interface.
* Used by all PDO-based drivers.
*
* @since 2.0
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver\PDOMsSql;
......@@ -7,7 +26,7 @@ namespace Doctrine\DBAL\Driver\PDOMsSql;
*
* @since 2.0
*/
class Connection extends PDO implements \Doctrine\DBAL\Driver\PDOConnection
class Connection extends \PDO implements \Doctrine\DBAL\Driver\Connection
{
/**
* Performs the rollback.
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver\PDOMsSql;
/**
* The PDO-based MsSql driver.
*
* @since 2.0
*/
class Driver implements \Doctrine\DBAL\Driver
{
public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
......@@ -15,9 +39,7 @@ class Driver implements \Doctrine\DBAL\Driver
}
/**
* Constructs the MySql PDO DSN.
*
* Overrides Connection#_constructPdoDsn().
* Constructs the MsSql PDO DSN.
*
* @return string The DSN.
*/
......
......@@ -52,8 +52,6 @@ class Driver implements \Doctrine\DBAL\Driver
/**
* Constructs the MySql PDO DSN.
*
* Overrides Connection#_constructPdoDsn().
*
* @return string The DSN.
*/
private function _constructPdoDsn(array $params)
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver\PDOOracle;
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver\PDOSqlite;
......@@ -13,10 +32,10 @@ class Driver implements \Doctrine\DBAL\Driver
* Tries to establish a database connection to SQLite.
*
* @param array $params
* @param unknown_type $username
* @param unknown_type $password
* @param string $username
* @param string $password
* @param array $driverOptions
* @return unknown
* @return Connection
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{
......
<?php
/*
* $Id: Interface.php 3882 2008-02-22 18:11:35Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver;
/**
* The PDO implementation of the Statement interface.
* Used by all PDO-based drivers.
*
* @since 2.0
*/
class PDOStatement extends \PDOStatement implements \Doctrine\DBAL\Driver\Statement
{
private function __construct() {}
......
<?php
/*
* $Id: Interface.php 3882 2008-02-22 18:11:35Z jwage $
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
......
......@@ -3,7 +3,7 @@
namespace Doctrine\DBAL\Types;
/**
* Type that maps PHP arrays to VARCHAR SQL type.
* Type that maps a PHP array to a VARCHAR SQL type.
*
* @since 2.0
*/
......
......@@ -6,8 +6,17 @@ namespace Doctrine\DBAL\Types;
* Type that maps a database BIGINT to a PHP string.
*
* @author robo
* @since 2.0
*/
class BigIntType extends Type
{
//put your code here
public function getName()
{
return "BigInteger";
}
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getBigIntTypeDeclarationSql($fieldDeclaration);
}
}
\ No newline at end of file
......@@ -5,13 +5,13 @@ namespace Doctrine\DBAL\Types;
/**
* Type that maps an SQL boolean to a PHP boolean.
*
* @since 2.0
*/
class BooleanType extends Type
{
/**
* Enter description here...
* {@inheritdoc}
*
* @param unknown_type $value
* @override
*/
public function convertToDatabaseValue($value, Doctrine_DatabasePlatform $platform)
......@@ -20,14 +20,12 @@ class BooleanType extends Type
}
/**
* Enter description here...
* {@inheritdoc}
*
* @param unknown_type $value
* @return unknown
* @override
*/
public function convertToObjectValue($value)
{
return (bool)$value;
return (bool) $value;
}
}
\ No newline at end of file
......@@ -10,26 +10,31 @@ namespace Doctrine\DBAL\Types;
class DateTimeType extends Type
{
/**
* Enter description here...
* {@inheritdoc}
*/
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getDateTimeTypeDeclarationSql($fieldDeclaration);
}
/**
* {@inheritdoc}
*
* @param unknown_type $value
* @param Doctrine_DatabasePlatform $platform
* @override
*/
public function convertToDatabaseValue($value, Doctrine_DatabasePlatform $platform)
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
//TODO: howto? dbms specific? delegate to platform?
return $value;
}
/**
* Enter description here...
* {@inheritdoc}
*
* @param string $value
* @return DateTime
* @override
*/
public function convertToObjectValue($value)
{
return new DateTime($value);
return new \DateTime($value);
}
}
\ No newline at end of file
......@@ -5,8 +5,22 @@ namespace Doctrine\DBAL\Types;
/**
* Type that maps an SQL DECIMAL to a PHP double.
*
* @since 2.0
*/
class DecimalType extends Type
{
public function getName()
{
return "Decimal";
}
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getDecimalTypeDeclarationSql($fieldDeclaration);
}
public function convertToPHPValue($value)
{
return (double) $value;
}
}
\ No newline at end of file
......@@ -3,11 +3,24 @@
namespace Doctrine\DBAL\Types;
/**
* Description of SmallIntType
* Type that maps a database SMALLINT to a PHP integer.
*
* @author robo
*/
class SmallIntType
{
//put your code here
public function getName()
{
return "SmallInteger";
}
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getSmallIntTypeDeclarationSql($fieldDeclaration);
}
public function convertToPHPValue($value)
{
return (int) $value;
}
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ namespace Doctrine\DBAL\Types;
class TextType extends Type
{
/** @override */
public function getSqlDeclaration(array $fieldDeclaration, Doctrine_DatabasePlatform $platform)
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getClobDeclarationSql($fieldDeclaration);
}
......
......@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Types;
use Doctrine\Common\DoctrineException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
abstract class Type
......@@ -9,16 +10,14 @@ abstract class Type
private static $_typeObjects = array();
private static $_typesMap = array(
'integer' => 'Doctrine\DBAL\Types\IntegerType',
'int' => '\Doctrine\DBAL\Types\IntegerType',
'tinyint' => '\Doctrine\DBAL\Types\TinyIntType',
'smallint' => '\Doctrine\DBAL\Types\SmallIntType',
'mediumint' => '\Doctrine\DBAL\Types\MediumIntType',
'bigint' => '\Doctrine\DBAL\Types\BigIntType',
'int' => 'Doctrine\DBAL\Types\IntegerType',
'smallint' => 'Doctrine\DBAL\Types\SmallIntType',
'bigint' => 'Doctrine\DBAL\Types\BigIntType',
'varchar' => 'Doctrine\DBAL\Types\VarcharType',
'text' => '\Doctrine\DBAL\Types\TextType',
'datetime' => '\Doctrine\DBAL\Types\DateTimeType',
'decimal' => '\Doctrine\DBAL\Types\DecimalType',
'double' => '\Doctrine\DBAL\Types\DoubleType'
'text' => 'Doctrine\DBAL\Types\TextType',
'datetime' => 'Doctrine\DBAL\Types\DateTimeType',
'decimal' => 'Doctrine\DBAL\Types\DecimalType',
'double' => 'Doctrine\DBAL\Types\DoubleType'
);
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
......@@ -55,7 +54,7 @@ abstract class Type
}
if ( ! isset(self::$_typeObjects[$name])) {
if ( ! isset(self::$_typesMap[$name])) {
\Doctrine\Common\DoctrineException::updateMe("Unknown type: $name");
throw DoctrineException::updateMe("Unknown type: $name");
}
self::$_typeObjects[$name] = new self::$_typesMap[$name]();
}
......@@ -72,7 +71,7 @@ abstract class Type
public static function addCustomType($name, $className)
{
if (isset(self::$_typesMap[$name])) {
throw Doctrine_Exception::typeExists($name);
throw DoctrineException::typeExists($name);
}
self::$_typesMap[$name] = $className;
}
......
......@@ -175,7 +175,7 @@ abstract class AbstractHydrator
/**
* Processes a row of the result set.
* Used for identity hydration (HYDRATE_IDENTITY_OBJECT and HYDRATE_IDENTITY_ARRAY).
* Used for identity-based hydration (HYDRATE_OBJECT and HYDRATE_ARRAY).
* Puts the elements of a result row into a new array, grouped by the class
* they belong to. The column names in the result set are mapped to their
* field names during this procedure as well as any necessary conversions on
......@@ -199,30 +199,21 @@ abstract class AbstractHydrator
$cache[$key]['dqlAlias'] = $this->_tableAliases[
implode(\Doctrine\ORM\Query\SqlWalker::SQLALIAS_SEPARATOR, $e)
];
$classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
// check whether it's an aggregate value or a regular field
if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName])) {
$fieldName = $this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName];
if ($cache[$key]['dqlAlias'] == 'dctrn') {
$cache[$key]['fieldName'] = $columnName;
$cache[$key]['isScalar'] = true;
} else {
$classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
$fieldName = $this->_lookupFieldName($classMetadata, $columnName);
$cache[$key]['fieldName'] = $fieldName;
$cache[$key]['isScalar'] = false;
$cache[$key]['type'] = $classMetadata->getTypeOfColumn($columnName);
}
$cache[$key]['fieldName'] = $fieldName;
// Cache identifier information
$cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName);
/*if ($classMetadata->isIdentifier($fieldName)) {
$cache[$key]['isIdentifier'] = true;
} else {
$cache[$key]['isIdentifier'] = false;
}*/
}
}
$class = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
$dqlAlias = $cache[$key]['dqlAlias'];
$fieldName = $cache[$key]['fieldName'];
if ($cache[$key]['isScalar']) {
......@@ -230,6 +221,8 @@ abstract class AbstractHydrator
continue;
}
$dqlAlias = $cache[$key]['dqlAlias'];
if ($cache[$key]['isIdentifier']) {
$id[$dqlAlias] .= '|' . $value;
}
......@@ -239,6 +232,11 @@ abstract class AbstractHydrator
if ( ! isset($nonemptyComponents[$dqlAlias]) && $value !== null) {
$nonemptyComponents[$dqlAlias] = true;
}
/* TODO: Consider this instead of the above 4 lines. */
/*if ($value !== null) {
$rowData[$dqlAlias][$fieldName] = $cache[$key]['type']->convertToPHPValue($value);
}*/
}
return $rowData;
......@@ -266,24 +264,22 @@ abstract class AbstractHydrator
// cache general information like the column name <-> field name mapping
$e = explode(\Doctrine\ORM\Query\SqlWalker::SQLALIAS_SEPARATOR, $key);
$columnName = array_pop($e);
$cache[$key]['dqlAlias'] = $this->_tableAliases[
implode(\Doctrine\ORM\Query\SqlWalker::SQLALIAS_SEPARATOR, $e)
];
$classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
// check whether it's an aggregate value or a regular field
if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName])) {
$fieldName = $this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName];
$sqlAlias = implode(\Doctrine\ORM\Query\SqlWalker::SQLALIAS_SEPARATOR, $e);
$cache[$key]['dqlAlias'] = $this->_tableAliases[$sqlAlias];
// check whether it's a scalar value or a regular field
if ($cache[$key]['dqlAlias'] == 'dctrn') {
$cache[$key]['fieldName'] = $columnName;
$cache[$key]['isScalar'] = true;
} else {
$classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
$fieldName = $this->_lookupFieldName($classMetadata, $columnName);
$cache[$key]['fieldName'] = $fieldName;
$cache[$key]['isScalar'] = false;
// cache type information
$cache[$key]['type'] = $classMetadata->getTypeOfColumn($columnName);
}
$cache[$key]['fieldName'] = $fieldName;
}
$class = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
$dqlAlias = $cache[$key]['dqlAlias'];
$fieldName = $cache[$key]['fieldName'];
......@@ -353,13 +349,6 @@ abstract class AbstractHydrator
}
}
\Doctrine\Common\DoctrineException::updateMe("No field name found for column name '$lcColumnName' during hydration.");
}
/** Needed only temporarily until the new parser is ready */
private $_isResultMixed = false;
public function setResultMixed($bool)
{
$this->_isResultMixed = $bool;
throw DoctrineException::updateMe("No field name found for column name '$lcColumnName' during hydration.");
}
}
\ No newline at end of file
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM\Internal\Hydration;
......@@ -27,16 +42,8 @@ class ArrayHydrator extends AbstractHydrator
protected function _prepare($parserResult)
{
parent::_prepare($parserResult);
//reset($this->_queryComponents);
//$this->_rootAlias = key($this->_queryComponents);
$this->_rootAlias = $parserResult->getDefaultQueryComponentAlias();
$this->_rootEntityName = $this->_queryComponents[$this->_rootAlias]['metadata']->getClassName();
if (isset($this->_queryComponents['dctrn'])) {
$this->_isSimpleQuery = count($this->_queryComponents) <= 2;
} else {
$this->_isSimpleQuery = count($this->_queryComponents) <= 1;
}
$this->_rootEntityName = $this->_queryComponents[$this->_rootAlias]['metadata']->getClassName();
$this->_isSimpleQuery = count($this->_queryComponents) <= 1;
$this->_identifierMap = array();
$this->_resultPointers = array();
......
......@@ -48,15 +48,9 @@ class ObjectHydrator extends AbstractHydrator
protected function _prepare($parserResult)
{
parent::_prepare($parserResult);
//reset($this->_queryComponents);
//$this->_rootAlias = key($this->_queryComponents);
$this->_rootAlias = $parserResult->getDefaultQueryComponentAlias();
$this->_rootEntityName = $this->_queryComponents[$this->_rootAlias]['metadata']->getClassName();
if (isset($this->_queryComponents['dctrn'])) {
$this->_isSimpleQuery = count($this->_queryComponents) <= 2;
} else {
$this->_isSimpleQuery = count($this->_queryComponents) <= 1;
}
$this->_identifierMap = array();
$this->_resultPointers = array();
$this->_idTemplate = array();
......
......@@ -545,10 +545,31 @@ class Query extends AbstractQuery
public function getSingleResult($hydrationMode = null)
{
$result = $this->execute(array(), $hydrationMode);
if (is_array($result)) {
if (count($result) > 1) {
throw QueryException::nonUniqueResult();
}
return is_array($result) ? array_shift($result) : $result->getFirst();
return array_shift($result);
} else if (is_object($result)) {
if (count($result) > 1) {
throw QueryException::nonUniqueResult();
}
return $result->getFirst();
}
return $result;
}
/**
* Gets the single scalar result of the query.
*
* Alias for getSingleResult(HYDRATE_SINGLE_SCALAR).
*
* @return mixed
* @throws QueryException If the query result is not unique.
*/
public function getSingleScalarResult()
{
return $this->getSingleResult(self::HYDRATE_SINGLE_SCALAR);
}
/**
......
......@@ -46,23 +46,22 @@ abstract class AbstractResult
*
* Two dimensional array containing the map for query aliases. Main keys are component aliases.
*
* table Table object associated with given alias.
* metadata Table object associated with given alias.
* relation Relation object owned by the parent.
* parent Alias of the parent.
* agg Aggregates of this component.
* map Name of the column / aggregate value this component is mapped to a collection.
*/
protected $_queryComponents;
protected $_queryComponents = array();
/**
* @var array Table alias map. Keys are SQL aliases and values DQL aliases.
*/
protected $_tableAliasMap;
protected $_tableAliasMap = array();
/**
* @var array Enum params.
*/
protected $_enumParams;
protected $_enumParams = array();
/**
* @var string
......@@ -74,23 +73,6 @@ abstract class AbstractResult
*/
protected $_isMixedQuery = false;
/**
* Cannot be called directly, factory methods handle this job.
*
* @param mixed $data Data to be stored.
* @param array $queryComponents Query components.
* @param array $tableAliasMap Table aliases.
* @param array $enumParams Enum params.
* @return Doctrine_ORM_Query_CacheHandler
*/
public function __construct($data = '', $queryComponents = array(), $tableAliasMap = array(), $enumParams = array())
{
$this->_data = $data;
$this->_queryComponents = $queryComponents;
$this->_tableAliasMap = $tableAliasMap;
$this->_enumParams = $enumParams;
}
/**
* Defines the mapping components.
*
......
......@@ -22,6 +22,7 @@
namespace Doctrine\ORM\Query;
use Doctrine\Common\DoctrineException;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\AST;
use Doctrine\ORM\Query\Exec;
......@@ -104,35 +105,42 @@ class Parser
*/
private $_em;
/**
* The Query to parse.
*
* @var Query
*/
private $_query;
/**
* Whether the query is a SELECT query and contains scalar values in the result list
* as defined by the SelectExpressions.
*
* @var boolean
*/
private $_resultContainsScalars = false;
/**
* Whether the query is a SELECT query and contains objects in the result list
* as defined by the SelectExpressions.
*
* @var boolean
*/
private $_resultContainsObjects = false;
/**
* Creates a new query parser object.
*
* @param string $dql DQL to be parsed.
* @param Doctrine_Connection $connection The connection to use
* @param Query $query The Query to parse.
*/
public function __construct(\Doctrine\ORM\Query $query)
public function __construct(Query $query)
{
$this->_query = $query;
$this->_em = $query->getEntityManager();
$this->_lexer = new Lexer($query->getDql());
$this->_parserResult = new ParserResult(
'',
array( // queryComponent
self::SCALAR_QUERYCOMPONENT_ALIAS => array(
'metadata' => null,
'parent' => null,
'relation' => null,
'map' => null,
'scalar' => null,
),
),
array( // tableAliasMap
self::SCALAR_QUERYCOMPONENT_ALIAS => self::SCALAR_QUERYCOMPONENT_ALIAS,
)
);
$this->_parserResult = new ParserResult;
$this->_parserResult->setEntityManager($this->_em);
$this->free(true);
//$this->free(true);
}
/**
......@@ -205,9 +213,9 @@ class Parser
}
/**
* Returns the scanner object associated with this object.
* Gets the lexer used by the parser.
*
* @return Doctrine_ORM_Query_Lexer
* @return Doctrine\ORM\Query\Lexer
*/
public function getLexer()
{
......@@ -215,9 +223,9 @@ class Parser
}
/**
* Returns the parser result associated with this object.
* Gets the ParserResult that is being filled with information during parsing.
*
* @return Doctrine_ORM_Query_ParserResult
* @return Doctrine\ORM\Query\ParserResult
*/
public function getParserResult()
{
......@@ -250,7 +258,7 @@ class Parser
$message .= "'{$this->_lexer->lookahead['value']}'";
}
throw \Doctrine\Common\DoctrineException::updateMe($message);
throw DoctrineException::updateMe($message);
}
/**
......@@ -265,7 +273,7 @@ class Parser
$token = $this->_lexer->token;
}
//TODO: Include $token in $message
throw \Doctrine\Common\DoctrineException::updateMe($message);
throw DoctrineException::updateMe($message);
}
/**
......@@ -317,12 +325,10 @@ class Parser
return ($la['value'] === '(' && $next['type'] === Lexer::T_SELECT);
}
/* Parse methods */
/**
* QueryLanguage ::= SelectStatement | UpdateStatement | DeleteStatement
*/
private function _QueryLanguage()
public function _QueryLanguage()
{
$this->_lexer->moveNext();
switch ($this->_lexer->lookahead['type']) {
......@@ -641,6 +647,10 @@ class Parser
$peek = $this->_lexer->glimpse();
// First we recognize for an IdentificationVariable (DQL class alias)
if ($peek['value'] != '.' && $peek['value'] != '(' && $this->_lexer->lookahead['type'] === Lexer::T_IDENTIFIER) {
$this->_resultContainsObjects = true;
if ($this->_resultContainsScalars) {
$this->_parserResult->setMixedQuery(true);
}
$expression = $this->_IdentificationVariable();
} else if (($isFunction = $this->_isFunction()) !== false || $this->_isSubselect()) {
if ($isFunction) {
......@@ -661,7 +671,17 @@ class Parser
$this->match(Lexer::T_IDENTIFIER);
$fieldIdentificationVariable = $this->_lexer->token['value'];
}
$this->_resultContainsScalars = true;
if ($this->_resultContainsObjects) {
$this->_parserResult->setMixedQuery(true);
}
} else {
$this->_resultContainsObjects = true;
if ($this->_resultContainsScalars) {
$this->_parserResult->setMixedQuery(true);
}
//TODO: If hydration mode is OBJECT throw an exception ("partial object dangerous...")
// unless the doctrine.forcePartialLoad query hint is set
$expression = $this->_StateFieldPathExpression();
}
return new AST\SelectExpression($expression, $fieldIdentificationVariable);
......@@ -823,28 +843,6 @@ class Parser
return $join;
}
/*private function _isSingleValuedPathExpression()
{
$parserResult = $this->_parserResult;
// Trying to recoginize this grammar:
// IdentificationVariable "." (CollectionValuedAssociationField | SingleValuedAssociationField)
$token = $this->lookahead;
$this->_scanner->resetPeek();
if ($parserResult->hasQueryComponent($token['value'])) {
$queryComponent = $parserResult->getQueryComponent($token['value']);
$peek = $this->_scanner->peek();
if ($peek['value'] === '.') {
$peek2 = $this->_scanner->peek();
if ($queryComponent['metadata']->hasAssociation($peek2['value']) &&
$queryComponent['metadata']->getAssociationMapping($peek2['value'])->isOneToOne()) {
return true;
}
}
}
return false;
}*/
/**
* JoinPathExpression ::= IdentificationVariable "." (CollectionValuedAssociationField | SingleValuedAssociationField)
*/
......
......@@ -51,17 +51,20 @@ class SqlWalker
{
$this->_em = $em;
$this->_parserResult = $parserResult;
$sqlToDqlAliasMap = array();
$sqlToDqlAliasMap = array(Parser::SCALAR_QUERYCOMPONENT_ALIAS => Parser::SCALAR_QUERYCOMPONENT_ALIAS);
foreach ($parserResult->getQueryComponents() as $dqlAlias => $qComp) {
if ($dqlAlias != Parser::SCALAR_QUERYCOMPONENT_ALIAS) {
$sqlAlias = $this->generateSqlTableAlias($qComp['metadata']->getTableName());
$sqlToDqlAliasMap[$sqlAlias] = $dqlAlias;
}
}
// SQL => DQL alias stored in ParserResult, needed for hydration.
$parserResult->setTableAliasMap($sqlToDqlAliasMap);
// DQL => SQL alias stored only locally, needed for SQL construction.
$this->_dqlToSqlAliasMap = array_flip($sqlToDqlAliasMap);
// In a mixed query we start alias counting for scalars with 1 since
// index 0 will hold the object.
if ($parserResult->isMixedQuery()) {
$this->_scalarAliasCounter = 1;
}
}
public function getConnection()
......@@ -233,8 +236,9 @@ class SqlWalker
public function walkSelectExpression($selectExpression)
{
$sql = '';
if ($selectExpression->getExpression() instanceof AST\StateFieldPathExpression) {
$pathExpression = $selectExpression->getExpression();
$expr = $selectExpression->getExpression();
if ($expr instanceof AST\StateFieldPathExpression) {
$pathExpression = $expr;
if ($pathExpression->isSimpleStateFieldPathExpression()) {
$parts = $pathExpression->getParts();
$numParts = count($parts);
......@@ -258,8 +262,8 @@ class SqlWalker
throw DoctrineException::updateMe("Encountered invalid PathExpression during SQL construction.");
}
}
else if ($selectExpression->getExpression() instanceof AST\AggregateExpression) {
$aggExpr = $selectExpression->getExpression();
else if ($expr instanceof AST\AggregateExpression) {
$aggExpr = $expr;
if ( ! $selectExpression->getFieldIdentificationVariable()) {
$alias = $this->_scalarAliasCounter++;
} else {
......@@ -267,18 +271,17 @@ class SqlWalker
}
$sql .= $this->walkAggregateExpression($aggExpr) . ' AS dctrn__' . $alias;
}
else if ($selectExpression->getExpression() instanceof AST\Subselect) {
$sql .= $this->walkSubselect($selectExpression->getExpression());
} else if ($selectExpression->getExpression() instanceof AST\Functions\FunctionNode) {
$funcExpr = $selectExpression->getExpression();
else if ($expr instanceof AST\Subselect) {
$sql .= $this->walkSubselect($expr);
} else if ($expr instanceof AST\Functions\FunctionNode) {
if ( ! $selectExpression->getFieldIdentificationVariable()) {
$alias = $this->_scalarAliasCounter++;
} else {
$alias = $selectExpression->getFieldIdentificationVariable();
}
$sql .= $this->walkFunction($selectExpression->getExpression()) . ' AS dctrn__' . $alias;
$sql .= $this->walkFunction($expr) . ' AS dctrn__' . $alias;
} else {
$dqlAlias = $selectExpression->getExpression();
$dqlAlias = $expr;
$queryComp = $this->_parserResult->getQueryComponent($dqlAlias);
$class = $queryComp['metadata'];
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM\Tools;
use Doctrine\ORM\EntityManager;
/**
* The SchemaTool is a tool to create and/or drop database schemas based on
* <tt>ClassMetadata</tt> class descriptors.
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision: 4805 $
*/
class SchemaTool
{
/** The EntityManager */
private $_em;
/** The DatabasePlatform */
private $_platform;
/**
* Initializes a new SchemaTool instance that uses the connection of the
* provided EntityManager.
*
* @param Doctrine\ORM\EntityManager $em
*/
public function __construct(EntityManager $em)
{
$this->_em = $em;
$this->_platform = $em->getConnection()->getDatabasePlatform();
}
/**
* Creates the database schema for the given array of ClassMetadata instances.
*
* @param array $classes
*/
public function createSchema(array $classes)
{
$createSchemaSql = $this->getCreateSchemaSql($classes);
$conn = $this->_em->getConnection();
foreach ($createSchemaSql as $sql) {
$conn->execute($sql);
}
}
/**
* Gets an array of DDL statements for the specified array of ClassMetadata instances.
*
* @param array $classes
* @return array $sql
*/
public function getCreateSchemaSql(array $classes)
{
$sql = array();
$foreignKeyConstraints = array();
// First we create the tables
foreach ($classes as $class) {
$columns = array(); // table columns
$options = array(); // table options
foreach ($class->getFieldMappings() as $fieldName => $mapping) {
$column = array();
$column['name'] = $mapping['columnName'];
$column['type'] = $mapping['type'];
$column['length'] = $mapping['length'];
$column['notnull'] = ! $mapping['nullable'];
if ($class->isIdentifier($fieldName)) {
$column['primary'] = true;
$options['primary'][] = $mapping['columnName'];
if ($class->isIdGeneratorIdentity()) {
$column['autoincrement'] = true;
}
}
$columns[$mapping['columnName']] = $column;
}
foreach ($class->getAssociationMappings() as $mapping) {
$foreignClass = $this->_em->getClassMetadata($mapping->getTargetEntityName());
if ($mapping->isOneToOne() && $mapping->isOwningSide()) {
$constraint = array();
$constraint['tableName'] = $class->getTableName();
$constraint['foreignTable'] = $foreignClass->getTableName();
$constraint['local'] = array();
$constraint['foreign'] = array();
foreach ($mapping->getJoinColumns() as $joinColumn) {
$column = array();
$column['name'] = $joinColumn['name'];
$column['type'] = $foreignClass->getTypeOfColumn($joinColumn['referencedColumnName']);
$columns[$joinColumn['name']] = $column;
$constraint['local'][] = $joinColumn['name'];
$constraint['foreign'][] = $joinColumn['referencedColumnName'];
}
$foreignKeyConstraints[] = $constraint;
} else if ($mapping->isOneToMany() && $mapping->isOwningSide()) {
//... create join table, one-many through join table supported later
throw DoctrineException::updateMe("Not yet implemented.");
} else if ($mapping->isManyToMany() && $mapping->isOwningSide()) {
// create join table
$joinTableColumns = array();
$joinTableOptions = array();
$joinTable = $mapping->getJoinTable();
$constraint1 = array();
$constraint1['tableName'] = $joinTable['name'];
$constraint1['foreignTable'] = $class->getTableName();
$constraint1['local'] = array();
$constraint1['foreign'] = array();
foreach ($joinTable['joinColumns'] as $joinColumn) {
$column = array();
$column['primary'] = true;
$joinTableOptions['primary'][] = $joinColumn['name'];
$column['name'] = $joinColumn['name'];
$column['type'] = $class->getTypeOfColumn($joinColumn['referencedColumnName']);
$joinTableColumns[$joinColumn['name']] = $column;
$constraint1['local'][] = $joinColumn['name'];
$constraint1['foreign'][] = $joinColumn['referencedColumnName'];
}
$foreignKeyConstraints[] = $constraint1;
$constraint2 = array();
$constraint2['tableName'] = $joinTable['name'];
$constraint2['foreignTable'] = $foreignClass->getTableName();
$constraint2['local'] = array();
$constraint2['foreign'] = array();
foreach ($joinTable['inverseJoinColumns'] as $inverseJoinColumn) {
$column = array();
$column['primary'] = true;
$joinTableOptions['primary'][] = $inverseJoinColumn['name'];
$column['name'] = $inverseJoinColumn['name'];
$column['type'] = $this->_em->getClassMetadata($mapping->getTargetEntityName())
->getTypeOfColumn($inverseJoinColumn['referencedColumnName']);
$joinTableColumns[$inverseJoinColumn['name']] = $column;
$constraint2['local'][] = $inverseJoinColumn['name'];
$constraint2['foreign'][] = $inverseJoinColumn['referencedColumnName'];
}
$foreignKeyConstraints[] = $constraint2;
$sql = array_merge($sql, $this->_platform->getCreateTableSql(
$joinTable['name'], $joinTableColumns, $joinTableOptions));
}
}
$sql = array_merge($sql, $this->_platform->getCreateTableSql($class->getTableName(), $columns, $options));
}
// Now create the foreign key constraints
if ($this->_platform->supportsForeignKeyConstraints()) {
foreach ($foreignKeyConstraints as $fkConstraint) {
$sql = array_merge($sql, (array)$this->_platform->getCreateForeignKeySql($fkConstraint['tableName'], $fkConstraint));
}
}
return $sql;
}
public function dropSchema(array $classes)
{
//TODO
}
public function getDropSchemaSql(array $classes)
{
//TODO
}
}
\ No newline at end of file
<?php
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Tests\Models\CMS\CmsUser;
require_once __DIR__ . '/../../TestInit.php';
/**
* Functional Query tests.
*
* @author robo
*/
class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
$this->useModelSet('cms');
parent::setUp();
}
public function testSimpleQueries()
{
$user = new CmsUser;
$user->name = 'Guilherme';
$user->username = 'gblanco';
$user->status = 'developer';
$this->_em->save($user);
$this->_em->flush();
$this->_em->clear();
$query = $this->_em->createQuery("select u, upper(u.name) from Doctrine\Tests\Models\CMS\CmsUser u where u.username = 'gblanco'");
$result = $query->getResultList();
$this->assertEquals(1, count($result));
$this->assertTrue($result[0][0] instanceof CmsUser);
$this->assertEquals('Guilherme', $result[0][0]->name);
$this->assertEquals('gblanco', $result[0][0]->username);
$this->assertEquals('developer', $result[0][0]->status);
$this->assertEquals('GUILHERME', $result[0][1]);
$resultArray = $query->getResultArray();
$this->assertEquals(1, count($resultArray));
$this->assertTrue(is_array($resultArray[0][0]));
$this->assertEquals('Guilherme', $resultArray[0][0]['name']);
$this->assertEquals('gblanco', $resultArray[0][0]['username']);
$this->assertEquals('developer', $resultArray[0][0]['status']);
$this->assertEquals('GUILHERME', $resultArray[0][1]);
$scalarResult = $query->getScalarResult();
$this->assertEquals(1, count($scalarResult));
$this->assertEquals('Guilherme', $scalarResult[0]['u_name']);
$this->assertEquals('gblanco', $scalarResult[0]['u_username']);
$this->assertEquals('developer', $scalarResult[0]['u_status']);
$this->assertEquals('GUILHERME', $scalarResult[0]['dctrn_1']);
$query = $this->_em->createQuery("select upper(u.name) from Doctrine\Tests\Models\CMS\CmsUser u where u.username = 'gblanco'");
$this->assertEquals('GUILHERME', $query->getSingleScalarResult());
}
}
<?php
namespace Doctrine\Tests\ORM\Functional;
require_once __DIR__ . '/../../TestInit.php';
/**
* Description of SequenceGeneratorTest
*
* @author robo
*/
class SequenceGeneratorTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function testFoo()
{
$this->assertEquals(1, 1);
}
}
/**
* @DoctrineEntity
*/
class SeqUser {
/**
* @DoctrineId
* @DoctrineIdGenerator("sequence")
*/
private $id;
public function getId() {
return $this->id;
}
}
......@@ -70,8 +70,7 @@ class ArrayHydratorTest extends HydrationTest
'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'),
'parent' => null,
'relation' => null,
'map' => null,
'agg' => array('0' => 'nameUpper')
'map' => null
),
'p' => array(
'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'),
......@@ -83,6 +82,7 @@ class ArrayHydratorTest extends HydrationTest
// Faked table alias map
$tableAliasMap = array(
'dctrn' => 'dctrn',
'u' => 'u',
'p' => 'p'
);
......@@ -93,19 +93,19 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '42',
),
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '43',
),
array(
'u__id' => '2',
'u__status' => 'developer',
'u__0' => 'JWAGE',
'dctrn__nameUpper' => 'JWAGE',
'p__phonenumber' => '91'
)
);
......@@ -154,13 +154,13 @@ class ArrayHydratorTest extends HydrationTest
'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'),
'parent' => 'u',
'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'),
'map' => null,
'agg' => array('0' => 'numPhones')
'map' => null
)
);
// Faked table alias map
$tableAliasMap = array(
'dctrn' => 'dctrn',
'u' => 'u',
'p' => 'p'
);
......@@ -171,12 +171,12 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'p__0' => '2',
'dctrn__numPhones' => '2',
),
array(
'u__id' => '2',
'u__status' => 'developer',
'p__0' => '1',
'dctrn__numPhones' => '1',
)
);
......@@ -211,7 +211,6 @@ class ArrayHydratorTest extends HydrationTest
'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'),
'parent' => null,
'relation' => null,
'agg' => array('0' => 'nameUpper'),
'map' => 'id'
),
'p' => array(
......@@ -224,6 +223,7 @@ class ArrayHydratorTest extends HydrationTest
// Faked table alias map
$tableAliasMap = array(
'dctrn' => 'dctrn',
'u' => 'u',
'p' => 'p'
);
......@@ -234,19 +234,19 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '42',
),
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '43',
),
array(
'u__id' => '2',
'u__status' => 'developer',
'u__0' => 'JWAGE',
'dctrn__nameUpper' => 'JWAGE',
'p__phonenumber' => '91'
)
);
......@@ -295,8 +295,7 @@ class ArrayHydratorTest extends HydrationTest
'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'),
'parent' => null,
'relation' => null,
'map' => null,
'agg' => array('0' => 'nameUpper')
'map' => null
),
'p' => array(
'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'),
......@@ -314,6 +313,7 @@ class ArrayHydratorTest extends HydrationTest
// Faked table alias map
$tableAliasMap = array(
'dctrn' => 'dctrn',
'u' => 'u',
'p' => 'p',
'a' => 'a'
......@@ -325,7 +325,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '42',
'a__id' => '1',
'a__topic' => 'Getting things done!'
......@@ -333,7 +333,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '43',
'a__id' => '1',
'a__topic' => 'Getting things done!'
......@@ -341,7 +341,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '42',
'a__id' => '2',
'a__topic' => 'ZendCon'
......@@ -349,7 +349,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '43',
'a__id' => '2',
'a__topic' => 'ZendCon'
......@@ -357,7 +357,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '2',
'u__status' => 'developer',
'u__0' => 'JWAGE',
'dctrn__nameUpper' => 'JWAGE',
'p__phonenumber' => '91',
'a__id' => '3',
'a__topic' => 'LINQ'
......@@ -365,7 +365,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '2',
'u__status' => 'developer',
'u__0' => 'JWAGE',
'dctrn__nameUpper' => 'JWAGE',
'p__phonenumber' => '91',
'a__id' => '4',
'a__topic' => 'PHP6'
......@@ -424,8 +424,7 @@ class ArrayHydratorTest extends HydrationTest
'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'),
'parent' => null,
'relation' => null,
'map' => null,
'agg' => array('0' => 'nameUpper')
'map' => null
),
'p' => array(
'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'),
......@@ -449,6 +448,7 @@ class ArrayHydratorTest extends HydrationTest
// Faked table alias map
$tableAliasMap = array(
'dctrn' => 'dctrn',
'u' => 'u',
'p' => 'p',
'a' => 'a',
......@@ -461,7 +461,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '42',
'a__id' => '1',
'a__topic' => 'Getting things done!',
......@@ -471,7 +471,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '43',
'a__id' => '1',
'a__topic' => 'Getting things done!',
......@@ -481,7 +481,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '42',
'a__id' => '2',
'a__topic' => 'ZendCon',
......@@ -491,7 +491,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '1',
'u__status' => 'developer',
'u__0' => 'ROMANB',
'dctrn__nameUpper' => 'ROMANB',
'p__phonenumber' => '43',
'a__id' => '2',
'a__topic' => 'ZendCon',
......@@ -501,7 +501,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '2',
'u__status' => 'developer',
'u__0' => 'JWAGE',
'dctrn__nameUpper' => 'JWAGE',
'p__phonenumber' => '91',
'a__id' => '3',
'a__topic' => 'LINQ',
......@@ -511,7 +511,7 @@ class ArrayHydratorTest extends HydrationTest
array(
'u__id' => '2',
'u__status' => 'developer',
'u__0' => 'JWAGE',
'dctrn__nameUpper' => 'JWAGE',
'p__phonenumber' => '91',
'a__id' => '4',
'a__topic' => 'PHP6',
......
<?php
namespace Doctrine\Tests\ORM\Tools;
use Doctrine\ORM\Tools\SchemaTool;
require_once __DIR__ . '/../../TestInit.php';
class SchemaToolTest extends \Doctrine\Tests\OrmTestCase
{
public function testGetCreateSchemaSql()
{
$driver = new \Doctrine\Tests\Mocks\DriverMock;
$conn = new \Doctrine\Tests\Mocks\ConnectionMock(array(), $driver);
$conn->setDatabasePlatform(new \Doctrine\DBAL\Platforms\MySqlPlatform());
$em = $this->_getTestEntityManager($conn);
$classes = array(
$em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'),
$em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'),
$em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'),
);
$exporter = new SchemaTool($em);
$sql = $exporter->getCreateSchemaSql($classes);
$this->assertEquals(count($sql), 8);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment