Commit 354ede1e authored by romanb's avatar romanb

[2.0][DDC-354][DDC-425] Fixed. Encapsulated SQL logging better in the DBAL....

[2.0][DDC-354][DDC-425] Fixed. Encapsulated SQL logging better in the DBAL. Added binding types to DBAL mapping types as well as using these binding types in the persisters. Query and NativeQuery now support PDO binding types as well as DBAL mapping types when binding parameters.
parent 70141886
# Upgrade from 2.0-ALPHA4 to 2.0-BETA1
## New inversedBy attribute
It is now *mandatory* that the owning side of a bidirectional association specifies the
'inversedBy' attribute that points to the name of the field on the inverse side that completes
the association. Example:
[php]
// BEFORE (ALPHA4 AND EARLIER)
class User
{
//...
/** @OneToOne(targetEntity="Address", mappedBy="user") */
private $address;
//...
}
class Address
{
//...
/** @OneToOne(targetEntity="User") */
private $address;
//...
}
// SINCE BETA1
// User class DOES NOT CHANGE
class Address
{
//...
/** @OneToOne(targetEntity="User", inversedBy="address") */
private $user;
//...
}
Thus, the inversedBy attribute is the counterpart to the mappedBy attribute. This change
was necessary to enable some simplifications and further performance improvements. We
apologize for the inconvenience.
## Default Property for Field Mappings
The "default" option for database column defaults has been removed. If desired, database column defaults can
......
......@@ -43,10 +43,18 @@ class EventArgs
* @static
*/
private static $_emptyEventArgsInstance;
/**
* Gets the single, empty EventArgs instance.
*
* Gets the single, empty and immutable EventArgs instance.
*
* This instance will be used when events are dispatched without any parameter,
* like this: EventManager::dispatchEvent('eventname');
*
* The benefit from this is that only one empty instance is instantiated and shared
* (otherwise there would be instances for every dispatched in the abovementioned form)
*
* @see EventManager::dispatchEvent
* @link http://msdn.microsoft.com/en-us/library/system.eventargs.aspx
* @static
* @return EventArgs
*/
......@@ -55,7 +63,7 @@ class EventArgs
if ( ! self::$_emptyEventArgsInstance) {
self::$_emptyEventArgsInstance = new EventArgs;
}
return self::$_emptyEventArgsInstance;
}
}
}
......@@ -33,7 +33,6 @@ use Doctrine\DBAL\Types\Type;
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*
* @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.
*/
......@@ -61,6 +60,7 @@ class Configuration
* Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled.
*
* @param SqlLogger $logger
* @todo Rename to setSQLLogger()
*/
public function setSqlLogger($logger)
{
......@@ -71,6 +71,7 @@ class Configuration
* Gets the SQL logger that is used.
*
* @return SqlLogger
* @todo Rename to getSQLLogger()
*/
public function getSqlLogger()
{
......
This diff is collapsed.
......@@ -46,7 +46,7 @@ interface Driver
public function getName();
/**
* Get the name of the database connected to for this driver instance
* Get the name of the database connected to for this driver.
*
* @param Doctrine\DBAL\Connection $conn
* @return string $database
......
......@@ -25,7 +25,7 @@ namespace Doctrine\DBAL\Driver;
* Connection interface.
* Driver connections must implement this interface.
*
* This resembles the PDO interface.
* This resembles (a subset of) the PDO interface.
*
* @since 2.0
*/
......@@ -33,7 +33,7 @@ interface Connection
{
function prepare($prepareString);
function query();
function quote($input);
function quote($input, $type=\PDO::PARAM_STR);
function exec($statement);
function lastInsertId($name = null);
function beginTransaction();
......
......@@ -21,7 +21,7 @@
namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Connection;
use \PDO;
/**
* The OCI8 implementation of the Statement interface.
......@@ -36,17 +36,31 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
private $_paramCounter = 0;
private static $_PARAM = ':param';
private static $fetchStyleMap = array(
Connection::FETCH_BOTH => OCI_BOTH,
Connection::FETCH_ASSOC => OCI_ASSOC,
Connection::FETCH_NUM => OCI_NUM
PDO::FETCH_BOTH => OCI_BOTH,
PDO::FETCH_ASSOC => OCI_ASSOC,
PDO::FETCH_NUM => OCI_NUM
);
private $_paramMap = array();
/**
* Creates a new OCI8Statement that uses the given connection handle and SQL statement.
*
* @param resource $dbh The connection handle.
* @param string $statement The SQL statement.
*/
public function __construct($dbh, $statement)
{
$this->_sth = oci_parse($dbh, $this->_convertPositionalToNamedPlaceholders($statement));
}
/**
* Oracle does not support positional parameters, hence this method converts all
* positional parameters into artificially named parameters. Note that this conversion
* is not perfect. All question marks (?) in the original statement are treated as
* placeholders and converted to a named parameter.
*
* @param string $statement The SQL statement to convert.
*/
private function _convertPositionalToNamedPlaceholders($statement)
{
$count = 1;
......@@ -55,17 +69,9 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
$statement = substr_replace($statement, ":param$count", $pos, 1);
++$count;
}
return $statement;
}
/**
* {@inheritdoc}
*/
public function bindColumn($column, &$param, $type = null)
{
return oci_define_by_name($this->_sth, strtoupper($column), $param, $type);
}
/**
* {@inheritdoc}
......@@ -78,7 +84,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = null, $length = null, $driverOptions = array())
public function bindParam($column, &$variable, $type = null)
{
$column = isset($this->_paramMap[$column]) ? $this->_paramMap[$column] : $column;
......@@ -136,9 +142,9 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
$this->bindValue($key, $val);
}
}
$ret = @oci_execute($this->_sth, OCI_DEFAULT);
if (!$ret) {
if ( ! $ret) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
return $ret;
......@@ -147,7 +153,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
/**
* {@inheritdoc}
*/
public function fetch($fetchStyle = Connection::FETCH_BOTH)
public function fetch($fetchStyle = PDO::FETCH_BOTH)
{
if ( ! isset(self::$fetchStyleMap[$fetchStyle])) {
throw new \InvalidArgumentException("Invalid fetch style: " . $fetchStyle);
......@@ -159,7 +165,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
/**
* {@inheritdoc}
*/
public function fetchAll($fetchStyle = Connection::FETCH_BOTH)
public function fetchAll($fetchStyle = PDO::FETCH_BOTH)
{
if ( ! isset(self::$fetchStyleMap[$fetchStyle])) {
throw new \InvalidArgumentException("Invalid fetch style: " . $fetchStyle);
......
......@@ -21,7 +21,7 @@
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection as DBALConnection;
use \PDO;
/**
* Statement interface.
......@@ -38,18 +38,6 @@ use Doctrine\DBAL\Connection as DBALConnection;
*/
interface Statement
{
/**
* Bind a column to a PHP variable
*
* @param mixed $column Number of the column (1-indexed) or name of the column in the result set.
* If using the column name, be aware that the name should match
* the case of the column, as returned by the driver.
* @param string $param Name of the PHP variable to which the column will be bound.
* @param integer $type Data type of the parameter, specified by the PDO::PARAM_* constants.
* @return boolean Returns TRUE on success or FALSE on failure
*/
function bindColumn($column, &$param, $type = null);
/**
* Binds a value to a corresponding named or positional
* placeholder in the SQL statement that was used to prepare the statement.
......@@ -85,13 +73,9 @@ interface Statement
* @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants. To return
* an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
* PDO::PARAM_INPUT_OUTPUT bits for the data_type parameter.
*
* @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter
* from a stored procedure, you must explicitly set the length.
* @param mixed $driverOptions
* @return boolean Returns TRUE on success or FALSE on failure.
*/
function bindParam($column, &$variable, $type = null, $length = null, $driverOptions = array());
function bindParam($column, &$variable, $type = null);
/**
* Closes the cursor, enabling the statement to be executed again.
......@@ -142,7 +126,7 @@ interface Statement
* bound parameters in the SQL statement being executed.
* @return boolean Returns TRUE on success or FALSE on failure.
*/
function execute($params = array());
function execute($params = null);
/**
* fetch
......@@ -171,7 +155,7 @@ interface Statement
*
* @return mixed
*/
function fetch($fetchStyle = DBALConnection::FETCH_BOTH);
function fetch($fetchStyle = PDO::FETCH_BOTH);
/**
* Returns an array containing all of the result set rows
......@@ -185,7 +169,7 @@ interface Statement
*
* @return array
*/
function fetchAll($fetchStyle = DBALConnection::FETCH_BOTH);
function fetchAll($fetchStyle = PDO::FETCH_BOTH);
/**
* fetchColumn
......
......@@ -80,6 +80,7 @@ abstract class AbstractAsset
return substr($columnName, -floor(($maxSize-$postfixLen)/$columnCount - 1));
}, $columnNames);
$parts[] = $postfix;
return trim(implode("_", $parts), '_');
}
}
\ No newline at end of file
......@@ -81,7 +81,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
// fetch primary
$stmt = $this->_conn->execute( "PRAGMA TABLE_INFO ('$tableName')" );
$indexArray = $stmt->fetchAll(\Doctrine\DBAL\Connection::FETCH_ASSOC);
$indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach($indexArray AS $indexColumnRow) {
if($indexColumnRow['pk'] == "1") {
$indexBuffer[] = array(
......@@ -102,7 +102,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
$idx['non_unique'] = $tableIndex['unique']?false:true;
$stmt = $this->_conn->execute( "PRAGMA INDEX_INFO ( '{$keyName}' )" );
$indexArray = $stmt->fetchAll(\Doctrine\DBAL\Connection::FETCH_ASSOC);
$indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ( $indexArray as $indexColumnRow ) {
$idx['column_name'] = $indexColumnRow['name'];
......
<?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;
use PDO,
Doctrine\DBAL\Types\Type,
Doctrine\DBAL\Driver\Statement as DriverStatement;
/**
* A thin wrapper around a Doctrine\DBAL\Driver\Statement that adds support
* for logging, DBAL mapping types, etc.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class Statement implements DriverStatement
{
/**
* @var string The SQL statement.
*/
private $_sql;
/**
* @var array The bound parameters.
*/
private $_params = array();
/**
* @var Doctrine\DBAL\Driver\Statement The underlying driver statement.
*/
private $_stmt;
/**
* @var Doctrine\DBAL\Platforms\AbstractPlatform The underlying database platform.
*/
private $_platform;
/**
* @var Doctrine\DBAL\Connection The connection this statement is bound to and executed on.
*/
private $_conn;
/**
* Creates a new <tt>Statement</tt> for the given SQL and <tt>Connection</tt>.
*
* @param string $sql The SQL of the statement.
* @param Doctrine\DBAL\Connection The connection on which the statement should be executed.
*/
public function __construct($sql, Connection $conn)
{
$this->_sql = $sql;
$this->_stmt = $conn->getWrappedConnection()->prepare($sql);
$this->_conn = $conn;
$this->_platform = $conn->getDatabasePlatform();
}
/**
* Binds a parameter value to the statement.
*
* The value can optionally be bound with a PDO binding type or a DBAL mapping type.
* If bound with a DBAL mapping type, the binding type is derived from the mapping
* type and the value undergoes the conversion routines of the mapping type before
* being bound.
*
* @param $name The name or position of the parameter.
* @param $value The value of the parameter.
* @param mixed $type Either a PDO binding type or a DBAL mapping type name or instance.
* @return boolean TRUE on success, FALSE on failure.
*/
public function bindValue($name, $value, $type = null)
{
$this->_params[$name] = $value;
if ($type !== null) {
if (is_string($type)) {
$type = Type::getType($type);
}
if ($type instanceof Type) {
$value = $type->convertToDatabaseValue($value, $this->_platform);
$bindingType = $type->getBindingType();
} else {
$bindingType = $type; // PDO::PARAM_* constants
}
return $this->_stmt->bindValue($name, $value, $bindingType);
} else {
return $this->_stmt->bindValue($name, $value);
}
}
/**
* Binds a parameter to a value by reference.
*
* Binding a parameter by reference does not support DBAL mapping types.
*
* @param string $name The name or position of the parameter.
* @param mixed $value The reference to the variable to bind
* @param integer $type The PDO binding type.
* @return boolean TRUE on success, FALSE on failure.
*/
public function bindParam($name, &$var, $type = PDO::PARAM_STR)
{
return $this->_stmt->bindParam($name, $var, $type);
}
/**
* Executes the statement with the currently bound parameters.
*
* @return boolean TRUE on success, FALSE on failure.
*/
public function execute($params = null)
{
if ($this->_conn->getConfiguration()->getSQLLogger()) {
$this->_conn->getConfiguration()->getSQLLogger()->logSQL($this->_sql, $this->_params);
}
$this->_params = array();
return $this->_stmt->execute($params);
}
/**
* Closes the cursor, freeing the database resources used by this statement.
*
* @return boolean TRUE on success, FALSE on failure.
*/
public function closeCursor()
{
return $this->_stmt->closeCursor();
}
/**
* Returns the number of columns in the result set.
*
* @return integer
*/
public function columnCount()
{
return $this->_stmt->columnCount();
}
/**
* Fetches the SQLSTATE associated with the last operation on the statement.
*
* @return string
*/
public function errorCode()
{
return $this->_stmt->errorCode();
}
/**
* Fetches extended error information associated with the last operation on the statement.
*
* @return array
*/
public function errorInfo()
{
return $this->_stmt->errorInfo();
}
/**
* Fetches the next row from a result set.
*
* @param integer $fetchStyle
* @return mixed The return value of this function on success depends on the fetch type.
* In all cases, FALSE is returned on failure.
*/
public function fetch($fetchStyle = PDO::FETCH_BOTH)
{
return $this->_stmt->fetch($fetchStyle);
}
/**
* Returns an array containing all of the result set rows.
*
* @param integer $fetchStyle
* @param integer $columnIndex
* @return array An array containing all of the remaining rows in the result set.
*/
public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0)
{
if ($columnIndex != 0) {
return $this->_stmt->fetchAll($fetchStyle, $columnIndex);
}
return $this->_stmt->fetchAll($fetchStyle);
}
/**
* Returns a single column from the next row of a result set.
*
* @param integer $columnIndex
* @return mixed A single column from the next row of a result set or FALSE if there are no more rows.
*/
public function fetchColumn($columnIndex = 0)
{
return $this->_stmt->fetchColumn($columnIndex);
}
/**
* Returns the number of rows affected by the last execution of this statement.
*
* @return integer The number of affected rows.
*/
public function rowCount()
{
return $this->_stmt->rowCount();
}
/**
* Gets the wrapped driver statement.
*
* @return Doctrine\DBAL\Driver\Statement
*/
public function getWrappedStatement()
{
return $this->_stmt;
}
}
\ No newline at end of file
<?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\Types;
......@@ -26,6 +45,6 @@ class ArrayType extends Type
public function getName()
{
return 'Array';
return Type::TARRAY;
}
}
\ No newline at end of file
<?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\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* Type that maps a database BIGINT to a PHP string.
*
......@@ -12,16 +33,16 @@ class BigIntType extends Type
{
public function getName()
{
return 'BigInteger';
return Type::BIGINT;
}
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getBigIntTypeDeclarationSQL($fieldDeclaration);
}
public function getTypeCode()
public function getBindingType()
{
return self::CODE_INT;
return \PDO::PARAM_INT;
}
}
\ No newline at end of file
<?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\Types;
......@@ -28,6 +47,11 @@ class BooleanType extends Type
public function getName()
{
return 'boolean';
return Type::BOOLEAN;
}
public function getBindingType()
{
return \PDO::PARAM_BOOL;
}
}
\ No newline at end of file
<?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\Types;
......@@ -13,7 +32,7 @@ class DateTimeType extends Type
{
public function getName()
{
return 'DateTime';
return Type::DATETIME;
}
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
......
<?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\Types;
......@@ -13,7 +32,7 @@ class DateType extends Type
{
public function getName()
{
return 'Date';
return Type::DATE;
}
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
......
<?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\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* Type that maps an SQL DECIMAL to a PHP double.
*
......@@ -11,15 +32,15 @@ class DecimalType extends Type
{
public function getName()
{
return 'Decimal';
return Type::DECIMAL;
}
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getDecimalTypeDeclarationSQL($fieldDeclaration);
}
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return (double) $value;
}
......
<?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\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* Type that maps an SQL INT to a PHP integer.
*
......@@ -12,21 +33,21 @@ class IntegerType extends Type
{
public function getName()
{
return 'Integer';
return Type::INTEGER;
}
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration);
}
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return (int) $value;
}
public function getTypeCode()
public function getBindingType()
{
return self::CODE_INT;
return \PDO::PARAM_INT;
}
}
\ No newline at end of file
......@@ -26,6 +26,6 @@ class ObjectType extends Type
public function getName()
{
return 'Object';
return Type::OBJECT;
}
}
\ No newline at end of file
<?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\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* Type that maps a database SMALLINT to a PHP integer.
*
......@@ -11,21 +32,21 @@ class SmallIntType extends Type
{
public function getName()
{
return "SmallInteger";
return Type::SMALLINT;
}
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getSmallIntTypeDeclarationSQL($fieldDeclaration);
}
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return (int) $value;
}
public function getTypeCode()
public function getBindingType()
{
return self::CODE_INT;
return \PDO::PARAM_INT;
}
}
\ No newline at end of file
......@@ -21,6 +21,8 @@
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* Type that maps an SQL VARCHAR to a PHP string.
*
......@@ -29,13 +31,13 @@ namespace Doctrine\DBAL\Types;
class StringType extends Type
{
/** @override */
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
}
/** @override */
public function getDefaultLength(\Doctrine\DBAL\Platforms\AbstractPlatform $platform)
public function getDefaultLength(AbstractPlatform $platform)
{
return $platform->getVarcharDefaultLength();
}
......@@ -43,6 +45,6 @@ class StringType extends Type
/** @override */
public function getName()
{
return 'string';
return Type::STRING;
}
}
\ No newline at end of file
<?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\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* Type that maps an SQL CLOB to a PHP string.
*
......@@ -10,13 +31,13 @@ namespace Doctrine\DBAL\Types;
class TextType extends Type
{
/** @override */
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}
public function getName()
{
return 'text';
return Type::TEXT;
}
}
\ No newline at end of file
<?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\Types;
......@@ -13,7 +32,7 @@ class TimeType extends Type
{
public function getName()
{
return 'Time';
return Type::TIME;
}
/**
......@@ -26,19 +45,15 @@ class TimeType extends Type
/**
* {@inheritdoc}
*
* @override
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return ($value !== null)
? $value->format($platform->getTimeFormatString()) : null;
}
/**
* {@inheritdoc}
*
* @override
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
......
......@@ -34,32 +34,36 @@ use Doctrine\DBAL\Platforms\AbstractPlatform,
*/
abstract class Type
{
/* The following constants represent type codes and mirror the PDO::PARAM_X constants
* to decouple ourself from PDO.
*/
const CODE_BOOL = 5;
const CODE_NULL = 0;
const CODE_INT = 1;
const CODE_STR = 2;
const CODE_LOB = 3;
const TARRAY = 'array';
const BIGINT = 'bigint';
const BOOLEAN = 'boolean';
const DATETIME = 'datetime';
const DATE = 'date';
const TIME = 'time';
const DECIMAL = 'decimal';
const INTEGER = 'integer';
const OBJECT = 'object';
const SMALLINT = 'smallint';
const STRING = 'string';
const TEXT = 'text';
/** Map of already instantiated type objects. One instance per type (flyweight). */
private static $_typeObjects = array();
/** The map of supported doctrine mapping types. */
private static $_typesMap = array(
'array' => 'Doctrine\DBAL\Types\ArrayType',
'object' => 'Doctrine\DBAL\Types\ObjectType',
'boolean' => 'Doctrine\DBAL\Types\BooleanType',
'integer' => 'Doctrine\DBAL\Types\IntegerType',
'smallint' => 'Doctrine\DBAL\Types\SmallIntType',
'bigint' => 'Doctrine\DBAL\Types\BigIntType',
'string' => 'Doctrine\DBAL\Types\StringType',
'text' => 'Doctrine\DBAL\Types\TextType',
'datetime' => 'Doctrine\DBAL\Types\DateTimeType',
'date' => 'Doctrine\DBAL\Types\DateType',
'time' => 'Doctrine\DBAL\Types\TimeType',
'decimal' => 'Doctrine\DBAL\Types\DecimalType'
self::TARRAY => 'Doctrine\DBAL\Types\ArrayType',
self::OBJECT => 'Doctrine\DBAL\Types\ObjectType',
self::BOOLEAN => 'Doctrine\DBAL\Types\BooleanType',
self::INTEGER => 'Doctrine\DBAL\Types\IntegerType',
self::SMALLINT => 'Doctrine\DBAL\Types\SmallIntType',
self::BIGINT => 'Doctrine\DBAL\Types\BigIntType',
self::STRING => 'Doctrine\DBAL\Types\StringType',
self::TEXT => 'Doctrine\DBAL\Types\TextType',
self::DATETIME => 'Doctrine\DBAL\Types\DateTimeType',
self::DATE => 'Doctrine\DBAL\Types\DateType',
self::TIME => 'Doctrine\DBAL\Types\TimeType',
self::DECIMAL => 'Doctrine\DBAL\Types\DecimalType'
);
/* Prevent instantiation and force use of the factory method. */
......@@ -117,16 +121,6 @@ abstract class Type
*/
abstract public function getName();
/**
* Gets the type code of this type.
*
* @return integer
*/
public function getTypeCode()
{
return self::CODE_STR;
}
/**
* Factory method to create type instances.
* Type instances are implemented as flyweights.
......@@ -194,6 +188,25 @@ abstract class Type
self::$_typesMap[$name] = $className;
}
/**
* Gets the (preferred) binding type for values of this type that
* can be used when binding parameters to prepared statements.
*
* This method should return one of the PDO::PARAM_* constants, that is, one of:
*
* PDO::PARAM_BOOL
* PDO::PARAM_NULL
* PDO::PARAM_INT
* PDO::PARAM_STR
* PDO::PARAM_LOB
*
* @return integer
*/
public function getBindingType()
{
return \PDO::PARAM_STR;
}
/**
* Get the types array map which holds all registered types and the corresponding
* type class
......
......@@ -21,8 +21,10 @@
namespace Doctrine\ORM\Internal\Hydration;
use Doctrine\DBAL\Connection,
Doctrine\DBAL\Types\Type;
use PDO,
Doctrine\DBAL\Connection,
Doctrine\DBAL\Types\Type,
Doctrine\ORM\EntityManager;
/**
* Base class for all hydrators. A hydrator is a class that provides some form
......@@ -54,7 +56,7 @@ abstract class AbstractHydrator
/** @var Statement The statement that provides the data to hydrate. */
protected $_stmt;
/** @var array The query hints. */
protected $_hints;
......@@ -63,7 +65,7 @@ abstract class AbstractHydrator
*
* @param Doctrine\ORM\EntityManager $em The EntityManager to use.
*/
public function __construct(\Doctrine\ORM\EntityManager $em)
public function __construct(EntityManager $em)
{
$this->_em = $em;
$this->_platform = $em->getConnection()->getDatabasePlatform();
......@@ -112,18 +114,18 @@ abstract class AbstractHydrator
*/
public function hydrateRow()
{
$row = $this->_stmt->fetch(Connection::FETCH_ASSOC);
$row = $this->_stmt->fetch(PDO::FETCH_ASSOC);
if ( ! $row) {
$this->_cleanup();
return false;
}
$result = $this->_getRowContainer();
$result = array();
$this->_hydrateRow($row, $this->_cache, $result);
return $result;
}
/**
* Excutes one-time preparation tasks once each time hydration is started
* Excutes one-time preparation tasks, once each time hydration is started
* through {@link hydrateAll} or {@link iterate()}.
*/
protected function _prepare()
......@@ -149,7 +151,7 @@ abstract class AbstractHydrator
* @param array $cache The cache to use.
* @param mixed $result The result to fill.
*/
protected function _hydrateRow(array &$data, array &$cache, array &$result)
protected function _hydrateRow(array $data, array &$cache, array &$result)
{
throw new HydrationException("_hydrateRow() not implemented by this hydrator.");
}
......@@ -159,14 +161,6 @@ abstract class AbstractHydrator
*/
abstract protected function _hydrateAll();
/**
* Gets the row container used during row-by-row hydration through {@link iterate()}.
*/
protected function _getRowContainer()
{
return array();
}
/**
* Processes a row of the result set.
* Used for identity-based hydration (HYDRATE_OBJECT and HYDRATE_ARRAY).
......@@ -178,7 +172,7 @@ abstract class AbstractHydrator
* @return array An array with all the fields (name => value) of the data row,
* grouped by their component alias.
*/
protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents)
protected function _gatherRowData(array $data, array &$cache, array &$id, array &$nonemptyComponents)
{
$rowData = array();
......
......@@ -21,7 +21,7 @@
namespace Doctrine\ORM\Internal\Hydration;
use Doctrine\DBAL\Connection;
use PDO, Doctrine\DBAL\Connection;
/**
* The ArrayHydrator produces a nested array "graph" that is often (not always)
......@@ -60,7 +60,7 @@ class ArrayHydrator extends AbstractHydrator
{
$result = array();
$cache = array();
while ($data = $this->_stmt->fetch(Connection::FETCH_ASSOC)) {
while ($data = $this->_stmt->fetch(PDO::FETCH_ASSOC)) {
$this->_hydrateRow($data, $cache, $result);
}
......@@ -68,7 +68,7 @@ class ArrayHydrator extends AbstractHydrator
}
/** @override */
protected function _hydrateRow(array &$data, array &$cache, array &$result)
protected function _hydrateRow(array $data, array &$cache, array &$result)
{
// 1) Initialize
$id = $this->_idTemplate; // initialize the id-memory
......
......@@ -31,18 +31,17 @@ namespace Doctrine\ORM\Internal\Hydration;
class IterableResult implements \Iterator
{
/**
*
* @var \Doctrine\ORM\Internal\Hydration\AbstractHydrator
* @var Doctrine\ORM\Internal\Hydration\AbstractHydrator
*/
private $_hydrator;
/**
* @var bool
* @var boolean
*/
private $_rewinded = false;
/**
* @var int
* @var integer
*/
private $_key = -1;
......@@ -52,8 +51,7 @@ class IterableResult implements \Iterator
private $_current = null;
/**
*
* @param \Doctrine\ORM\Internal\Hydration\AbstractHydrator $hydrator
* @param Doctrine\ORM\Internal\Hydration\AbstractHydrator $hydrator
*/
public function __construct($hydrator)
{
......@@ -62,7 +60,7 @@ class IterableResult implements \Iterator
public function rewind()
{
if($this->_rewinded == true) {
if ($this->_rewinded == true) {
throw new HydrationException("Can only iterate a Result once.");
} else {
$this->_current = $this->next();
......
......@@ -21,7 +21,8 @@
namespace Doctrine\ORM\Internal\Hydration;
use Doctrine\ORM\PersistentCollection,
use PDO,
Doctrine\ORM\PersistentCollection,
Doctrine\ORM\Query,
Doctrine\Common\Collections\ArrayCollection,
Doctrine\Common\Collections\Collection;
......@@ -102,7 +103,7 @@ class ObjectHydrator extends AbstractHydrator
}
}
}
/**
* {@inheritdoc}
*/
......@@ -122,8 +123,9 @@ class ObjectHydrator extends AbstractHydrator
{
$result = array();
$cache = array();
while ($data = $this->_stmt->fetch(\Doctrine\DBAL\Connection::FETCH_ASSOC)) {
$this->_hydrateRow($data, $cache, $result);
while ($row = $this->_stmt->fetch(PDO::FETCH_ASSOC)) {
$this->_hydrateRow($row, $cache, $result);
}
// Take snapshots from all newly initialized collections
......@@ -189,7 +191,6 @@ class ObjectHydrator extends AbstractHydrator
$className = $this->_ce[$className]->discriminatorMap[$data[$discrColumn]];
unset($data[$discrColumn]);
}
return $this->_uow->createEntity($className, $data, $this->_hints);
}
......@@ -244,7 +245,7 @@ class ObjectHydrator extends AbstractHydrator
* @param array $cache
* @param array $result
*/
protected function _hydrateRow(array &$data, array &$cache, array &$result)
protected function _hydrateRow(array $data, array &$cache, array &$result)
{
// Initialize
$id = $this->_idTemplate; // initialize the id-memory
......@@ -263,12 +264,11 @@ class ObjectHydrator extends AbstractHydrator
// Hydrate the data chunks
foreach ($rowData as $dqlAlias => $data) {
$index = false;
$entityName = $this->_rsm->aliasMap[$dqlAlias];
if (isset($this->_rsm->parentAliasMap[$dqlAlias])) {
// It's a joined result
$parentAlias = $this->_rsm->parentAliasMap[$dqlAlias];
// Get a reference to the parent object to which the joined element belongs.
......
......@@ -38,14 +38,14 @@ class ScalarHydrator extends AbstractHydrator
{
$result = array();
$cache = array();
while ($data = $this->_stmt->fetch(Connection::FETCH_ASSOC)) {
while ($data = $this->_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $this->_gatherScalarRowData($data, $cache);
}
return $result;
}
/** @override */
protected function _hydrateRow(array &$data, array &$cache, array &$result)
protected function _hydrateRow(array $data, array &$cache, array &$result)
{
$result[] = $this->_gatherScalarRowData($data, $cache);
}
......
......@@ -35,7 +35,7 @@ class SingleScalarHydrator extends AbstractHydrator
protected function _hydrateAll()
{
$cache = array();
$result = $this->_stmt->fetchAll(Connection::FETCH_ASSOC);
$result = $this->_stmt->fetchAll(\PDO::FETCH_ASSOC);
if (count($result) > 1 || count($result[key($result)]) > 1) {
throw new \Doctrine\ORM\NonUniqueResultException;
}
......
......@@ -249,16 +249,6 @@ abstract class AssociationMapping
return $this->fetchMode == self::FETCH_LAZY;
}
/**
* Whether the source entity of this association represents the inverse side.
*
* @return boolean
*/
public function isInverseSide()
{
return ! $this->isOwningSide;
}
/**
* Whether the association is a one-to-one association.
*
......@@ -298,7 +288,12 @@ abstract class AssociationMapping
{
return (bool) $this->joinTable;
}
/**
* Checks whether the association has any cascades configured.
*
* @return boolean
*/
public function hasCascades()
{
return $this->isCascadePersist ||
......
......@@ -21,6 +21,8 @@
namespace Doctrine\ORM\Mapping;
use ReflectionClass, ReflectionProperty;
/**
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
* of an entity and it's associations.
......@@ -73,7 +75,7 @@ class ClassMetadata extends ClassMetadataInfo
$this->name = $entityName;
$this->reflClass = new \ReflectionClass($entityName);
$this->namespace = $this->reflClass->getNamespaceName();
$this->primaryTable['name'] = $this->reflClass->getShortName();
$this->table['name'] = $this->reflClass->getShortName();
$this->rootEntityName = $entityName;
}
......@@ -271,9 +273,9 @@ class ClassMetadata extends ClassMetadataInfo
*/
public function getQuotedTableName($platform)
{
return isset($this->primaryTable['quoted']) ?
$platform->quoteIdentifier($this->primaryTable['name']) :
$this->primaryTable['name'];
return isset($this->table['quoted']) ?
$platform->quoteIdentifier($this->table['name']) :
$this->table['name'];
}
/**
......@@ -306,8 +308,8 @@ class ClassMetadata extends ClassMetadataInfo
'discriminatorColumn',
'discriminatorValue',
'discriminatorMap',
'fieldMappings',
'fieldNames', //TODO: Not all of this stuff needs to be serialized. Only type, columnName and fieldName.
'fieldMappings',//TODO: Not all of this stuff needs to be serialized. Only type, columnName and fieldName.
'fieldNames',
'generatorType',
'identifier',
'idGenerator', //TODO: Does not really need to be serialized. Could be moved to runtime.
......@@ -320,13 +322,13 @@ class ClassMetadata extends ClassMetadataInfo
'lifecycleCallbacks',
'name',
'parentClasses',
'primaryTable',
'table',
'rootEntityName',
'subClasses',
'versionField'
);
}
/**
* Restores some state that can not be serialized/unserialized.
*
......@@ -335,22 +337,21 @@ class ClassMetadata extends ClassMetadataInfo
public function __wakeup()
{
// Restore ReflectionClass and properties
$this->reflClass = new \ReflectionClass($this->name);
$this->reflClass = new ReflectionClass($this->name);
foreach ($this->fieldMappings as $field => $mapping) {
if (isset($mapping['inherited'])) {
$reflField = new \ReflectionProperty($mapping['inherited'], $field);
$reflField = new ReflectionProperty($mapping['inherited'], $field);
} else {
$reflField = $this->reflClass->getProperty($field);
}
$reflField->setAccessible(true);
$this->reflFields[$field] = $reflField;
}
foreach ($this->associationMappings as $field => $mapping) {
if (isset($this->inheritedAssociationFields[$field])) {
$reflField = new \ReflectionProperty($this->inheritedAssociationFields[$field], $field);
$reflField = new ReflectionProperty($this->inheritedAssociationFields[$field], $field);
} else {
$reflField = $this->reflClass->getProperty($field);
}
......
......@@ -294,8 +294,9 @@ class ClassMetadataInfo
* uniqueConstraints => array
*
* @var array
* @todo Rename to just $table
*/
public $primaryTable;
public $table;
/**
* READ-ONLY: The registered lifecycle callbacks for entities of this class.
......@@ -862,7 +863,7 @@ class ClassMetadataInfo
*/
public function getTableName()
{
return $this->primaryTable['name'];
return $this->table['name'];
}
/**
......@@ -872,7 +873,7 @@ class ClassMetadataInfo
*/
public function getTemporaryIdTableName()
{
return $this->primaryTable['name'] . '_id_tmp';
return $this->table['name'] . '_id_tmp';
}
/**
......@@ -966,7 +967,7 @@ class ClassMetadataInfo
*/
public function setTableName($tableName)
{
$this->primaryTable['name'] = $tableName;
$this->table['name'] = $tableName;
}
/**
......@@ -981,7 +982,7 @@ class ClassMetadataInfo
*/
public function setPrimaryTable(array $primaryTableDefinition)
{
$this->primaryTable = $primaryTableDefinition;
$this->table = $primaryTableDefinition;
}
/**
......@@ -1101,7 +1102,7 @@ class ClassMetadataInfo
*/
private function _registerMappingIfInverse(AssociationMapping $assoc)
{
if ($assoc->isInverseSide()) {
if ( ! $assoc->isOwningSide) {
$this->inverseMappings[$assoc->targetEntityName][$assoc->mappedBy] = $assoc;
}
}
......
......@@ -63,7 +63,7 @@ class DatabaseDriver implements Driver
$className = Inflector::classify($tableName);
$metadata->name = $className;
$metadata->primaryTable['name'] = $tableName;
$metadata->table['name'] = $tableName;
$columns = $this->_sm->listTableColumns($tableName);
......
......@@ -31,6 +31,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
* @since 2.0
* @version $Revision: 1393 $
* @author Jonathan H. Wage <jonwage@gmail.com>
* @todo Rename: MetadataDriver
*/
interface Driver
{
......
......@@ -41,6 +41,7 @@ use Doctrine\Common\Cache\ArrayCache,
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @todo Rename: PHPDriver
*/
class PhpDriver extends AbstractFileDriver
{
......
......@@ -62,11 +62,11 @@ class XmlDriver extends AbstractFileDriver
// Evaluate <entity...> attributes
if (isset($xmlRoot['table'])) {
$metadata->primaryTable['name'] = (string)$xmlRoot['table'];
$metadata->table['name'] = (string)$xmlRoot['table'];
}
if (isset($xmlRoot['schema'])) {
$metadata->primaryTable['schema'] = (string)$xmlRoot['schema'];
$metadata->table['schema'] = (string)$xmlRoot['schema'];
}
if (isset($xmlRoot['inheritance-type'])) {
......@@ -108,7 +108,7 @@ class XmlDriver extends AbstractFileDriver
$columns = $index['columns'];
}
$metadata->primaryTable['indexes'][$index['name']] = array(
$metadata->table['indexes'][$index['name']] = array(
'columns' => $columns
);
}
......@@ -123,7 +123,7 @@ class XmlDriver extends AbstractFileDriver
$columns = $unique['columns'];
}
$metadata->primaryTable['uniqueConstraints'][$unique['name']] = array(
$metadata->table['uniqueConstraints'][$unique['name']] = array(
'columns' => $columns
);
}
......
......@@ -62,11 +62,11 @@ class YamlDriver extends AbstractFileDriver
// Evaluate root level properties
if (isset($element['table'])) {
$metadata->primaryTable['name'] = $element['table'];
$metadata->table['name'] = $element['table'];
}
if (isset($element['schema'])) {
$metadata->primaryTable['schema'] = $element['schema'];
$metadata->table['schema'] = $element['schema'];
}
if (isset($element['inheritanceType'])) {
......@@ -107,7 +107,7 @@ class YamlDriver extends AbstractFileDriver
$columns = $index['columns'];
}
$metadata->primaryTable['indexes'][$index['name']] = array(
$metadata->table['indexes'][$index['name']] = array(
'columns' => $columns
);
}
......@@ -126,7 +126,7 @@ class YamlDriver extends AbstractFileDriver
$columns = $unique['columns'];
}
$metadata->primaryTable['uniqueConstraints'][$unique['name']] = array(
$metadata->table['uniqueConstraints'][$unique['name']] = array(
'columns' => $columns
);
}
......
......@@ -21,7 +21,7 @@
namespace Doctrine\ORM;
use Doctrine\ORM\Query\AbstractQuery;
use Doctrine\DBAL\Types\Type;
/**
* Represents a native SQL query.
......@@ -33,24 +33,13 @@ final class NativeQuery extends AbstractQuery
{
private $_sql;
/**
* Initializes a new instance of the <tt>NativeQuery</tt> class that is bound
* to the given EntityManager.
*
* @param EntityManager $em The EntityManager to use.
*/
public function __construct(EntityManager $em)
{
parent::__construct($em);
}
/**
* Sets the SQL of the query.
*
* @param string $sql
* @return Doctrine\ORM\AbstractQuery
* @return NativeQuery This query instance.
*/
public function setSql($sql)
public function setSQL($sql)
{
$this->_sql = $sql;
return $this;
......@@ -62,37 +51,27 @@ final class NativeQuery extends AbstractQuery
* @return mixed The built SQL query or an array of all SQL queries.
* @override
*/
public function getSql()
public function getSQL()
{
return $this->_sql;
}
/**
* Executes the query.
*
* @param array $params
* @return Statement The Statement handle.
* @override
*/
protected function _doExecute(array $params)
{
return $this->_em->getConnection()->execute($this->_sql, $this->_prepareParams($params));
}
/**
* {@inheritdoc}
*
* @override
*/
protected function _prepareParams(array $params)
protected function _doExecute()
{
$sqlParams = array();
$stmt = $this->_em->getConnection()->prepare($this->_sql);
$params = $this->_params;
foreach ($params as $key => $value) {
$sqlParams[$key] = $value;
if (isset($this->_paramTypes[$key])) {
$stmt->bindValue($key, $value, $this->_paramTypes[$key]);
} else {
$stmt->bindValue($key, $value);
}
}
ksort($sqlParams);
return array_values($sqlParams);
$stmt->execute();
return $stmt;
}
}
\ No newline at end of file
......@@ -290,7 +290,12 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
*/
private function _changed()
{
$this->_isDirty = true;
if ( ! $this->_isDirty) {
$this->_isDirty = true;
//if ($this->_isNotifyRequired) {
//$this->_em->getUnitOfWork()->scheduleCollectionUpdate($this);
//}
}
}
/**
......
......@@ -61,14 +61,6 @@ abstract class AbstractCollectionPersister
$this->_conn = $em->getConnection();
}
/*public function recreate(PersistentCollection $coll)
{
if ($coll->getRelation()->isInverseSide()) {
return;
}
//...
}*/
/**
* Deletes the persistent state represented by the given collection.
*
......@@ -76,7 +68,7 @@ abstract class AbstractCollectionPersister
*/
public function delete(PersistentCollection $coll)
{
if ($coll->getMapping()->isInverseSide()) {
if ( ! $coll->getMapping()->isOwningSide) {
return; // ignore inverse side
}
$sql = $this->_getDeleteSql($coll);
......@@ -106,7 +98,7 @@ abstract class AbstractCollectionPersister
*/
public function update(PersistentCollection $coll)
{
if ($coll->getMapping()->isInverseSide()) {
if ( ! $coll->getMapping()->isOwningSide) {
return; // ignore inverse side
}
$this->deleteRows($coll);
......
<?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\Persisters;
use Doctrine\ORM\Mapping\ClassMetadata,
Doctrine\DBAL\Types\Type;
/**
* Base class for entity persisters that implement a certain inheritance mapping strategy.
* All these persisters are assumed to use a discriminator column to discriminate entity
* types in the hierarchy.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
abstract class AbstractEntityInheritancePersister extends StandardEntityPersister
{
/**
* Map from column names to class names that declare the field the column is mapped to.
*
* @var array
*/
private $_declaringClassMap = array();
/**
* {@inheritdoc}
*/
protected function _prepareInsertData($entity)
{
$data = parent::_prepareInsertData($entity);
// Populate the discriminator column
$discColumn = $this->_class->discriminatorColumn;
$this->_columnTypes[$discColumn['name']] = $discColumn['type'];
$data[$this->_getDiscriminatorColumnTableName()][$discColumn['name']] = $this->_class->discriminatorValue;
return $data;
}
/**
* Gets the name of the table that contains the discriminator column.
*
* @return string The table name.
*/
abstract protected function _getDiscriminatorColumnTableName();
/**
* {@inheritdoc}
*/
protected function _processSQLResult(array $sqlResult)
{
$data = array();
$discrColumnName = $this->_platform->getSQLResultCasing($this->_class->discriminatorColumn['name']);
$entityName = $this->_class->discriminatorMap[$sqlResult[$discrColumnName]];
unset($sqlResult[$discrColumnName]);
foreach ($sqlResult as $column => $value) {
$realColumnName = $this->_resultColumnNames[$column];
if (isset($this->_declaringClassMap[$column])) {
$class = $this->_declaringClassMap[$column];
if ($class->name == $entityName || is_subclass_of($entityName, $class->name)) {
$field = $class->fieldNames[$realColumnName];
$data[$field] = Type::getType($class->fieldMappings[$field]['type'])
->convertToPHPValue($value, $this->_platform);
}
} else {
$data[$realColumnName] = $value;
}
}
return array($entityName, $data);
}
/**
* {@inheritdoc}
*/
protected function _getSelectColumnSQL($field, ClassMetadata $class)
{
$columnName = $class->columnNames[$field];
$sql = $this->_getSQLTableAlias($class) . '.' . $class->getQuotedColumnName($field, $this->_platform);
$columnAlias = $this->_platform->getSQLResultCasing($columnName . $this->_sqlAliasCounter++);
if ( ! isset($this->_resultColumnNames[$columnAlias])) {
$this->_resultColumnNames[$columnAlias] = $columnName;
$this->_declaringClassMap[$columnAlias] = $class;
}
return "$sql AS $columnAlias";
}
}
\ No newline at end of file
......@@ -27,27 +27,20 @@ use Doctrine\ORM\Mapping\ClassMetadata;
* Persister for entities that participate in a hierarchy mapped with the
* SINGLE_TABLE strategy.
*
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision: 3406 $
* @link www.doctrine-project.org
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 2.0
* @link http://martinfowler.com/eaaCatalog/singleTableInheritance.html
*/
class SingleTablePersister extends StandardEntityPersister
class SingleTablePersister extends AbstractEntityInheritancePersister
{
/** @override */
protected function _prepareData($entity, array &$result, $isInsert = false)
/** {@inheritdoc} */
protected function _getDiscriminatorColumnTableName()
{
parent::_prepareData($entity, $result, $isInsert);
// Populate the discriminator column
if ($isInsert) {
$discColumn = $this->_class->discriminatorColumn['name'];
$result[$this->_class->getQuotedTableName($this->_platform)][$discColumn] =
$this->_class->discriminatorValue;
}
return $this->_class->table['name'];
}
/** @override */
/** {@inheritdoc} */
protected function _getSelectColumnListSQL()
{
$columnList = parent::_getSelectColumnListSQL();
......@@ -86,7 +79,7 @@ class SingleTablePersister extends StandardEntityPersister
return $columnList;
}
/** @override */
/** {@inheritdoc} */
protected function _getInsertColumnList()
{
$columns = parent::_getInsertColumnList();
......@@ -96,19 +89,13 @@ class SingleTablePersister extends StandardEntityPersister
return $columns;
}
/** @override */
protected function _processSQLResult(array $sqlResult)
{
return $this->_processSQLResultInheritanceAware($sqlResult);
}
/** @override */
/** {@inheritdoc} */
protected function _getSQLTableAlias(ClassMetadata $class)
{
if (isset($this->_sqlTableAliases[$class->rootEntityName])) {
return $this->_sqlTableAliases[$class->rootEntityName];
}
$tableAlias = $this->_em->getClassMetadata($class->rootEntityName)->primaryTable['name'][0] . $this->_sqlAliasCounter++;
$tableAlias = $this->_em->getClassMetadata($class->rootEntityName)->table['name'][0] . $this->_sqlAliasCounter++;
$this->_sqlTableAliases[$class->rootEntityName] = $tableAlias;
return $tableAlias;
......
......@@ -114,7 +114,7 @@ class ProxyFactory
}
/**
* Generates a (reference or association) proxy class.
* Generates a proxy class file.
*
* @param $class
* @param $originalClassName
......
......@@ -21,8 +21,7 @@
namespace Doctrine\ORM;
use Doctrine\ORM\Query\AbstractQuery,
Doctrine\ORM\Query\Parser,
use Doctrine\ORM\Query\Parser,
Doctrine\ORM\Query\QueryException;
/**
......@@ -124,7 +123,7 @@ final class Query extends AbstractQuery
private $_maxResults = null;
/**
* @var CacheDriver The cache driver used for caching queries.
* @var CacheDriver The cache driver used for caching queries.
*/
private $_queryCache;
......@@ -161,17 +160,17 @@ final class Query extends AbstractQuery
* @return mixed The built sql query or an array of all sql queries.
* @override
*/
public function getSql()
public function getSQL()
{
return $this->_parse()->getSqlExecutor()->getSqlStatements();
}
/**
* Returns the correspondent AST for this Query.
* Returns the corresponding AST for this DQL query.
*
* @return \Doctrine\ORM\Query\AST\SelectStatement |
* \Doctrine\ORM\Query\AST\UpdateStatement |
* \Doctrine\ORM\Query\AST\DeleteStatement
* @return Doctrine\ORM\Query\AST\SelectStatement |
* Doctrine\ORM\Query\AST\UpdateStatement |
* Doctrine\ORM\Query\AST\DeleteStatement
*/
public function getAST()
{
......@@ -216,62 +215,51 @@ final class Query extends AbstractQuery
/**
* {@inheritdoc}
*
* @param array $params
* @return Statement The resulting Statement.
* @override
*/
protected function _doExecute(array $params)
protected function _doExecute()
{
$executor = $this->_parse()->getSqlExecutor();
$params = $this->_prepareParams($params);
if ( ! $this->_resultSetMapping) {
$this->_resultSetMapping = $this->_parserResult->getResultSetMapping();
}
return $executor->execute($this->_em->getConnection(), $params);
}
/**
* {@inheritdoc}
*
* @override
*/
protected function _prepareParams(array $params)
{
$sqlParams = array();
// Prepare parameters
$paramMappings = $this->_parserResult->getParameterMappings();
if (count($paramMappings) != count($params)) {
if (count($paramMappings) != count($this->_params)) {
throw QueryException::invalidParameterNumber();
}
foreach ($params as $key => $value) {
$sqlParams = $types = array();
foreach ($this->_params as $key => $value) {
if ( ! isset($paramMappings[$key])) {
throw QueryException::unknownParameter($key);
}
if (isset($this->_paramTypes[$key])) {
foreach ($paramMappings[$key] as $position) {
$types[$position] = $this->_paramTypes[$key];
}
}
if (is_object($value)) {
//$values = $this->_em->getClassMetadata(get_class($value))->getIdentifierValues($value);
if (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($value))) {
$values = $this->_em->getUnitOfWork()->getEntityIdentifier($value);
//var_dump($this->_em->getUnitOfWork()->getEntityIdentifier($value));
$sqlPositions = $paramMappings[$key];
$sqlParams = array_merge($sqlParams, array_combine((array)$sqlPositions, $values));
} else if (is_bool($value)) {
$boolValue = $this->_em->getConnection()->getDatabasePlatform()->convertBooleans($value);
foreach ($paramMappings[$key] as $position) {
$sqlParams[$position] = $boolValue;
}
} else {
foreach ($paramMappings[$key] as $position) {
$sqlParams[$position] = $value;
}
}
}
ksort($sqlParams);
return array_values($sqlParams);
if ($sqlParams) {
ksort($sqlParams);
$sqlParams = array_values($sqlParams);
}
if ($this->_resultSetMapping === null) {
$this->_resultSetMapping = $this->_parserResult->getResultSetMapping();
}
return $executor->execute($this->_em->getConnection(), $sqlParams, $types);
}
/**
......
......@@ -57,8 +57,8 @@ class SizeFunction extends FunctionNode
$targetClass = $sqlWalker->getEntityManager()->getClassMetadata($assoc->targetEntityName);
$targetAssoc = $targetClass->associationMappings[$assoc->mappedBy];
$targetTableAlias = $sqlWalker->getSqlTableAlias($targetClass->primaryTable['name']);
$sourceTableAlias = $sqlWalker->getSqlTableAlias($qComp['metadata']->primaryTable['name'], $dqlAlias);
$targetTableAlias = $sqlWalker->getSqlTableAlias($targetClass->table['name']);
$sourceTableAlias = $sqlWalker->getSqlTableAlias($qComp['metadata']->table['name'], $dqlAlias);
$whereSql = '';
......@@ -68,10 +68,10 @@ class SizeFunction extends FunctionNode
. $sourceTableAlias . '.' . $targetKeyColumn;
}
$tableName = $targetClass->primaryTable['name'];
$tableName = $targetClass->table['name'];
} else if ($assoc->isManyToMany()) {
$targetTableAlias = $sqlWalker->getSqlTableAlias($assoc->joinTable['name']);
$sourceTableAlias = $sqlWalker->getSqlTableAlias($qComp['metadata']->primaryTable['name'], $dqlAlias);
$sourceTableAlias = $sqlWalker->getSqlTableAlias($qComp['metadata']->table['name'], $dqlAlias);
$whereSql = '';
......
......@@ -21,6 +21,8 @@
namespace Doctrine\ORM\Query\Exec;
use Doctrine\DBAL\Connection;
/**
* Base class for SQL statement executors.
*
......@@ -28,7 +30,7 @@ namespace Doctrine\ORM\Query\Exec;
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @todo Rename: AbstractSQLExecutor
*/
abstract class AbstractSqlExecutor
{
......@@ -47,8 +49,9 @@ abstract class AbstractSqlExecutor
/**
* Executes all sql statements.
*
* @param Doctrine_Connection $conn The database connection that is used to execute the queries.
* @param Doctrine\DBAL\Connection $conn The database connection that is used to execute the queries.
* @param array $params The parameters.
* @return Doctrine\DBAL\Driver\Statement
*/
abstract public function execute(\Doctrine\DBAL\Connection $conn, array $params);
abstract public function execute(Connection $conn, array $params, array $types);
}
\ No newline at end of file
......@@ -21,7 +21,8 @@
namespace Doctrine\ORM\Query\Exec;
use Doctrine\ORM\Query\AST;
use Doctrine\DBAL\Connection,
Doctrine\ORM\Query\AST;
/**
* Executes the SQL statements for bulk DQL DELETE statements on classes in
......@@ -52,11 +53,11 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor
$em = $sqlWalker->getEntityManager();
$conn = $em->getConnection();
$platform = $conn->getDatabasePlatform();
$primaryClass = $em->getClassMetadata($AST->deleteClause->abstractSchemaName);
$primaryDqlAlias = $AST->deleteClause->aliasIdentificationVariable;
$rootClass = $em->getClassMetadata($primaryClass->rootEntityName);
$tempTable = $rootClass->getTemporaryIdTableName();
$idColumnNames = $rootClass->getIdentifierColumnNames();
$idColumnList = implode(', ', $idColumnNames);
......@@ -64,17 +65,17 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor
// 1. Create an INSERT INTO temptable ... SELECT identifiers WHERE $AST->getWhereClause()
$this->_insertSql = 'INSERT INTO ' . $tempTable . ' (' . $idColumnList . ')'
. ' SELECT t0.' . implode(', t0.', $idColumnNames);
$sqlWalker->setSqlTableAlias($primaryClass->primaryTable['name'] . $primaryDqlAlias, 't0');
$sqlWalker->setSqlTableAlias($primaryClass->table['name'] . $primaryDqlAlias, 't0');
$rangeDecl = new AST\RangeVariableDeclaration($primaryClass->name, $primaryDqlAlias);
$fromClause = new AST\FromClause(array(new AST\IdentificationVariableDeclaration($rangeDecl, null, array())));
$this->_insertSql .= $sqlWalker->walkFromClause($fromClause);
// Append WHERE clause, if there is one.
if ($AST->whereClause) {
$this->_insertSql .= $sqlWalker->walkWhereClause($AST->whereClause);
}
// 2. Create ID subselect statement used in DELETE .... WHERE ... IN (subselect)
// 2. Create ID subselect statement used in DELETE ... WHERE ... IN (subselect)
$idSubselect = 'SELECT ' . $idColumnList . ' FROM ' . $tempTable;
// 3. Create and store DELETE statements
......@@ -106,24 +107,24 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor
* @param array $params The parameters.
* @override
*/
public function execute(\Doctrine\DBAL\Connection $conn, array $params)
public function execute(Connection $conn, array $params, array $types)
{
$numDeleted = 0;
// Create temporary id table
$conn->executeUpdate($this->_createTempTableSql);
// Insert identifiers
$numDeleted = $conn->executeUpdate($this->_insertSql, $params);
$numDeleted = $conn->executeUpdate($this->_insertSql, $params, $types);
// Execute DELETE statements
foreach ($this->_sqlStatements as $sql) {
$conn->executeUpdate($sql);
}
// Drop temporary table
$conn->executeUpdate($this->_dropTempTableSql);
return $numDeleted;
}
}
\ No newline at end of file
......@@ -21,7 +21,9 @@
namespace Doctrine\ORM\Query\Exec;
use Doctrine\ORM\Query\AST;
use Doctrine\DBAL\Connection,
Doctrine\DBAL\Types\Type,
Doctrine\ORM\Query\AST;
/**
* Executes the SQL statements for bulk DQL UPDATE statements on classes in
......@@ -69,7 +71,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
// 1. Create an INSERT INTO temptable ... SELECT identifiers WHERE $AST->getWhereClause()
$this->_insertSql = 'INSERT INTO ' . $tempTable . ' (' . $idColumnList . ')'
. ' SELECT t0.' . implode(', t0.', $idColumnNames);
$sqlWalker->setSqlTableAlias($primaryClass->primaryTable['name'] . $updateClause->aliasIdentificationVariable, 't0');
$sqlWalker->setSqlTableAlias($primaryClass->table['name'] . $updateClause->aliasIdentificationVariable, 't0');
$rangeDecl = new AST\RangeVariableDeclaration($primaryClass->name, $updateClause->aliasIdentificationVariable);
$fromClause = new AST\FromClause(array(new AST\IdentificationVariableDeclaration($rangeDecl, null, array())));
$this->_insertSql .= $sqlWalker->walkFromClause($fromClause);
......@@ -101,6 +103,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
$updateSql .= $sqlWalker->walkUpdateItem($updateItem);
//FIXME: parameters can be more deeply nested. traverse the tree.
//FIXME (URGENT): With query cache the parameter is out of date. Move to execute() stage.
if ($newValue instanceof AST\InputParameter) {
$paramKey = $newValue->name;
$this->_sqlParameters[$i][] = $sqlWalker->getQuery()->getParameter($paramKey);
......@@ -124,7 +127,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
foreach ($idColumnNames as $idColumnName) {
$columnDefinitions[$idColumnName] = array(
'notnull' => true,
'type' => \Doctrine\DBAL\Types\Type::getType($rootClass->getTypeOfColumn($idColumnName))
'type' => Type::getType($rootClass->getTypeOfColumn($idColumnName))
);
}
$this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
......@@ -134,13 +137,13 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
}
/**
* Executes all sql statements.
* Executes all SQL statements.
*
* @param Doctrine_Connection $conn The database connection that is used to execute the queries.
* @param array $params The parameters.
* @param Connection $conn The database connection that is used to execute the queries.
* @param array $params The parameters.
* @override
*/
public function execute(\Doctrine\DBAL\Connection $conn, array $params)
public function execute(Connection $conn, array $params, array $types)
{
$numUpdated = 0;
......@@ -148,7 +151,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
$conn->executeUpdate($this->_createTempTableSql);
// Insert identifiers. Parameters from the update clause are cut off.
$numUpdated = $conn->executeUpdate($this->_insertSql, array_slice($params, $this->_numParametersInUpdateClause));
$numUpdated = $conn->executeUpdate($this->_insertSql, array_slice($params, $this->_numParametersInUpdateClause), $types);
// Execute UPDATE statements
for ($i=0, $count=count($this->_sqlStatements); $i<$count; ++$i) {
......
......@@ -21,6 +21,10 @@
namespace Doctrine\ORM\Query\Exec;
use Doctrine\DBAL\Connection,
Doctrine\ORM\Query\AST\SelectStatement,
Doctrine\ORM\Query\SqlWalker;
/**
* Executor that executes the SQL statement for simple DQL SELECT statements.
*
......@@ -31,14 +35,14 @@ namespace Doctrine\ORM\Query\Exec;
* @since 2.0
*/
class SingleSelectExecutor extends AbstractSqlExecutor
{
public function __construct(\Doctrine\ORM\Query\AST\SelectStatement $AST, $sqlWalker)
{
public function __construct(SelectStatement $AST, SqlWalker $sqlWalker)
{
$this->_sqlStatements = $sqlWalker->walkSelectStatement($AST);
}
public function execute(\Doctrine\DBAL\Connection $conn, array $params)
public function execute(Connection $conn, array $params, array $types)
{
return $conn->execute($this->_sqlStatements, $params);
return $conn->execute($this->_sqlStatements, $params, $types);
}
}
......@@ -21,7 +21,8 @@
namespace Doctrine\ORM\Query\Exec;
use Doctrine\ORM\Query\AST;
use Doctrine\DBAL\Connection,
Doctrine\ORM\Query\AST;
/**
* Executor that executes the SQL statements for DQL DELETE/UPDATE statements on classes
......@@ -45,8 +46,8 @@ class SingleTableDeleteUpdateExecutor extends AbstractSqlExecutor
}
}
public function execute(\Doctrine\DBAL\Connection $conn, array $params)
public function execute(Connection $conn, array $params, array $types)
{
return $conn->executeUpdate($this->_sqlStatements, $params);
return $conn->executeUpdate($this->_sqlStatements, $params, $types);
}
}
\ No newline at end of file
......@@ -38,7 +38,7 @@ use Doctrine\ORM\Query;
*/
class Parser
{
/** Maps BUILT-IN string function names to AST class names. */
/** READ-ONLY: Maps BUILT-IN string function names to AST class names. */
private static $_STRING_FUNCTIONS = array(
'concat' => 'Doctrine\ORM\Query\AST\Functions\ConcatFunction',
'substring' => 'Doctrine\ORM\Query\AST\Functions\SubstringFunction',
......@@ -47,7 +47,7 @@ class Parser
'upper' => 'Doctrine\ORM\Query\AST\Functions\UpperFunction'
);
/** Maps BUILT-IN numeric function names to AST class names. */
/** READ-ONLY: Maps BUILT-IN numeric function names to AST class names. */
private static $_NUMERIC_FUNCTIONS = array(
'length' => 'Doctrine\ORM\Query\AST\Functions\LengthFunction',
'locate' => 'Doctrine\ORM\Query\AST\Functions\LocateFunction',
......@@ -57,7 +57,7 @@ class Parser
'size' => 'Doctrine\ORM\Query\AST\Functions\SizeFunction'
);
/** Maps BUILT-IN datetime function names to AST class names. */
/** READ-ONLY: Maps BUILT-IN datetime function names to AST class names. */
private static $_DATETIME_FUNCTIONS = array(
'current_date' => 'Doctrine\ORM\Query\AST\Functions\CurrentDateFunction',
'current_time' => 'Doctrine\ORM\Query\AST\Functions\CurrentTimeFunction',
......@@ -2587,18 +2587,12 @@ class Parser
// Check for custom functions afterwards
$config = $this->_em->getConfiguration();
if (($func = $config->getCustomStringFunction($funcName)) !== null) {
self::$_STRING_FUNCTIONS[$funcName] = $func;
return $this->FunctionsReturningStrings();
} else if (($func = $config->getCustomNumericFunction($funcName)) !== null) {
self::$_NUMERIC_FUNCTIONS[$funcName] = $func;
return $this->FunctionsReturningNumerics();
} else if (($func = $config->getCustomDatetimeFunction($funcName)) !== null) {
self::$_DATETIME_FUNCTIONS[$funcName] = $func;
return $this->FunctionsReturningDatetime();
if ($config->getCustomStringFunction($funcName) !== null) {
return $this->CustomFunctionsReturningStrings();
} else if ($config->getCustomNumericFunction($funcName) !== null) {
return $this->CustomFunctionsReturningNumerics();
} else if ($config->getCustomDatetimeFunction($funcName) !== null) {
return $this->CustomFunctionsReturningDatetime();
}
$this->syntaxError('known function', $token);
......@@ -2623,6 +2617,16 @@ class Parser
return $function;
}
public function CustomFunctionsReturningNumerics()
{
$funcNameLower = strtolower($this->_lexer->lookahead['value']);
$funcClass = $this->_em->getConfiguration()->getCustomNumericFunction($funcNameLower);
$function = new $funcClass($funcNameLower);
$function->parse($this);
return $function;
}
/**
* FunctionsReturningDateTime ::= "CURRENT_DATE" | "CURRENT_TIME" | "CURRENT_TIMESTAMP"
*/
......@@ -2636,6 +2640,16 @@ class Parser
return $function;
}
public function CustomFunctionsReturningDatetime()
{
$funcNameLower = strtolower($this->_lexer->lookahead['value']);
$funcClass = $this->_em->getConfiguration()->getCustomDatetimeFunction($funcNameLower);
$function = new $funcClass($funcNameLower);
$function->parse($this);
return $function;
}
/**
* FunctionsReturningStrings ::=
* "CONCAT" "(" StringPrimary "," StringPrimary ")" |
......@@ -2648,7 +2662,16 @@ class Parser
{
$funcNameLower = strtolower($this->_lexer->lookahead['value']);
$funcClass = self::$_STRING_FUNCTIONS[$funcNameLower];
//$funcClass = $this->_em->getConfiguration()->getDQLStringFunctionClassName($funcNameLower);
$function = new $funcClass($funcNameLower);
$function->parse($this);
return $function;
}
public function CustomFunctionsReturningStrings()
{
$funcNameLower = strtolower($this->_lexer->lookahead['value']);
$funcClass = $this->_em->getConfiguration()->getCustomStringFunction($funcNameLower);
$function = new $funcClass($funcNameLower);
$function->parse($this);
......
......@@ -240,12 +240,12 @@ class SqlWalker implements TreeWalker
{
$sql = '';
$baseTableAlias = $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias);
$baseTableAlias = $this->getSqlTableAlias($class->table['name'], $dqlAlias);
// INNER JOIN parent class tables
foreach ($class->parentClasses as $parentClassName) {
$parentClass = $this->_em->getClassMetadata($parentClassName);
$tableAlias = $this->getSqlTableAlias($parentClass->primaryTable['name'], $dqlAlias);
$tableAlias = $this->getSqlTableAlias($parentClass->table['name'], $dqlAlias);
$sql .= ' INNER JOIN ' . $parentClass->getQuotedTableName($this->_platform)
. ' ' . $tableAlias . ' ON ';
$first = true;
......@@ -264,7 +264,7 @@ class SqlWalker implements TreeWalker
if ( ! $this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) {
foreach ($class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName);
$tableAlias = $this->getSqlTableAlias($subClass->primaryTable['name'], $dqlAlias);
$tableAlias = $this->getSqlTableAlias($subClass->table['name'], $dqlAlias);
$sql .= ' LEFT JOIN ' . $subClass->getQuotedTableName($this->_platform)
. ' ' . $tableAlias . ' ON ';
......@@ -295,7 +295,7 @@ class SqlWalker implements TreeWalker
if ($qComp['metadata']->isInheritanceTypeJoined()) {
$tableName = $this->_em->getUnitOfWork()->getEntityPersister($class->name)->getOwningTable($fieldName);
} else {
$tableName = $qComp['metadata']->primaryTable['name'];
$tableName = $qComp['metadata']->table['name'];
}
if ($sql != '') {
......@@ -331,7 +331,7 @@ class SqlWalker implements TreeWalker
}
$sql .= (($this->_useSqlTableAliases)
? $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias) . '.' : ''
? $this->getSqlTableAlias($class->table['name'], $dqlAlias) . '.' : ''
) . $class->discriminatorColumn['name']
. ' IN (' . implode(', ', $values) . ')';
}
......@@ -432,7 +432,7 @@ class SqlWalker implements TreeWalker
$class = $this->_em->getClassMetadata($class->fieldMappings[$fieldName]['inherited']);
}
return $this->getSqlTableAlias($class->primaryTable['name'], $identificationVariable);
return $this->getSqlTableAlias($class->table['name'], $identificationVariable);
}
/**
......@@ -519,7 +519,7 @@ class SqlWalker implements TreeWalker
if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()) {
// Add discriminator columns to SQL
$rootClass = $this->_em->getClassMetadata($class->rootEntityName);
$tblAlias = $this->getSqlTableAlias($rootClass->primaryTable['name'], $dqlAlias);
$tblAlias = $this->getSqlTableAlias($rootClass->table['name'], $dqlAlias);
$discrColumn = $rootClass->discriminatorColumn;
$columnAlias = $this->getSqlColumnAlias($discrColumn['name']);
$sql .= ", $tblAlias." . $discrColumn['name'] . ' AS ' . $columnAlias;
......@@ -535,9 +535,9 @@ class SqlWalker implements TreeWalker
if ($assoc->isOwningSide && $assoc->isOneToOne()) {
if (isset($class->inheritedAssociationFields[$assoc->sourceFieldName])) {
$owningClass = $this->_em->getClassMetadata($class->inheritedAssociationFields[$assoc->sourceFieldName]);
$sqlTableAlias = $this->getSqlTableAlias($owningClass->primaryTable['name'], $dqlAlias);
$sqlTableAlias = $this->getSqlTableAlias($owningClass->table['name'], $dqlAlias);
} else {
$sqlTableAlias = $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias);
$sqlTableAlias = $this->getSqlTableAlias($class->table['name'], $dqlAlias);
}
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
......@@ -552,7 +552,7 @@ class SqlWalker implements TreeWalker
} else {
// Add foreign key columns to SQL, if necessary
if ($addMetaColumns) {
$sqlTableAlias = $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias);
$sqlTableAlias = $this->getSqlTableAlias($class->table['name'], $dqlAlias);
foreach ($class->associationMappings as $assoc) {
if ($assoc->isOwningSide && $assoc->isOneToOne()) {
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
......@@ -587,7 +587,7 @@ class SqlWalker implements TreeWalker
$class = $this->_em->getClassMetadata($rangeDecl->abstractSchemaName);
$sql .= $class->getQuotedTableName($this->_platform) . ' '
. $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias);
. $this->getSqlTableAlias($class->table['name'], $dqlAlias);
if ($class->isInheritanceTypeJoined()) {
$sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias);
......@@ -908,9 +908,9 @@ class SqlWalker implements TreeWalker
}
if (isset($mapping['inherited'])) {
$tableName = $this->_em->getClassMetadata($mapping['inherited'])->primaryTable['name'];
$tableName = $this->_em->getClassMetadata($mapping['inherited'])->table['name'];
} else {
$tableName = $class->primaryTable['name'];
$tableName = $class->table['name'];
}
if ($beginning) $beginning = false; else $sql .= ', ';
......@@ -931,7 +931,7 @@ class SqlWalker implements TreeWalker
if ($class->isInheritanceTypeSingleTable() || ! $this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) {
foreach ($class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName);
$sqlTableAlias = $this->getSqlTableAlias($subClass->primaryTable['name'], $dqlAlias);
$sqlTableAlias = $this->getSqlTableAlias($subClass->table['name'], $dqlAlias);
foreach ($subClass->fieldMappings as $fieldName => $mapping) {
if (isset($mapping['inherited']) || $partialFieldSet && !in_array($fieldName, $partialFieldSet)) {
continue;
......@@ -1016,7 +1016,7 @@ class SqlWalker implements TreeWalker
$class = $this->_em->getClassMetadata($rangeDecl->abstractSchemaName);
$sql = ' FROM ' . $class->getQuotedTableName($this->_platform) . ' '
. $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias);
. $this->getSqlTableAlias($class->table['name'], $dqlAlias);
if ($class->isInheritanceTypeJoined()) {
$sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias);
......@@ -1302,8 +1302,8 @@ class SqlWalker implements TreeWalker
if ($assoc->isOneToMany()) {
$targetClass = $this->_em->getClassMetadata($assoc->targetEntityName);
$targetTableAlias = $this->getSqlTableAlias($targetClass->primaryTable['name']);
$sourceTableAlias = $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias);
$targetTableAlias = $this->getSqlTableAlias($targetClass->table['name']);
$sourceTableAlias = $this->getSqlTableAlias($class->table['name'], $dqlAlias);
$sql .= $targetClass->getQuotedTableName($this->_platform)
. ' ' . $targetTableAlias . ' WHERE ';
......@@ -1338,8 +1338,8 @@ class SqlWalker implements TreeWalker
// SQL table aliases
$joinTableAlias = $this->getSqlTableAlias($joinTable['name']);
$targetTableAlias = $this->getSqlTableAlias($targetClass->primaryTable['name']);
$sourceTableAlias = $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias);
$targetTableAlias = $this->getSqlTableAlias($targetClass->table['name']);
$sourceTableAlias = $this->getSqlTableAlias($class->table['name'], $dqlAlias);
// join to target table
$sql .= $assoc->getQuotedJoinTableName($this->_platform)
......@@ -1351,8 +1351,7 @@ class SqlWalker implements TreeWalker
$joinColumns = $assoc->isOwningSide
? $joinTable['inverseJoinColumns']
: $joinTable['joinColumns'];
//$referencedColumnClass = $assoc->isOwningSide ? $targetClass : $class;
$first = true;
foreach ($joinColumns as $joinColumn) {
if ($first) $first = false; else $sql .= ' AND ';
......@@ -1362,13 +1361,13 @@ class SqlWalker implements TreeWalker
$targetClass->fieldNames[$joinColumn['referencedColumnName']],
$this->_platform);
}
$sql .= ' WHERE ';
$joinColumns = $assoc->isOwningSide
? $joinTable['joinColumns']
: $joinTable['inverseJoinColumns'];
$first = true;
foreach ($joinColumns as $joinColumn) {
if ($first) $first = false; else $sql .= ' AND ';
......
......@@ -35,7 +35,7 @@ abstract class TreeWalkerAdapter implements TreeWalker
private $_queryComponents;
/**
* @inheritdoc
* {@inheritdoc}
*/
public function __construct($query, $parserResult, array $queryComponents)
{
......
......@@ -101,10 +101,10 @@ class ConvertDoctrine1Schema
if (isset($model['tableName']) && $model['tableName']) {
$e = explode('.', $model['tableName']);
if (count($e) > 1) {
$metadata->primaryTable['schema'] = $e[0];
$metadata->primaryTable['name'] = $e[1];
$metadata->table['schema'] = $e[0];
$metadata->table['name'] = $e[1];
} else {
$metadata->primaryTable['name'] = $e[0];
$metadata->table['name'] = $e[0];
}
}
}
......@@ -208,7 +208,7 @@ class ConvertDoctrine1Schema
$type = (isset($index['type']) && $index['type'] == 'unique')
? 'uniqueConstraints' : 'indexes';
$metadata->primaryTable[$type][$name] = array(
$metadata->table[$type][$name] = array(
'columns' => $index['fields']
);
}
......
......@@ -443,12 +443,12 @@ public function <methodName>()
private function _generateTableAnnotation($metadata)
{
$table = array();
if ($metadata->primaryTable['name']) {
$table[] = 'name="' . $metadata->primaryTable['name'] . '"';
if ($metadata->table['name']) {
$table[] = 'name="' . $metadata->table['name'] . '"';
}
if (isset($metadata->primaryTable['schema'])) {
$table[] = 'schema="' . $metadata->primaryTable['schema'] . '"';
if (isset($metadata->table['schema'])) {
$table[] = 'schema="' . $metadata->table['schema'] . '"';
}
return '@Table(' . implode(', ', $table) . ')';
......@@ -570,7 +570,7 @@ public function <methodName>()
. ($associationMapping->isManyToMany() ? ' = array()' : null) . ";\n";
}
return implode("\n", $lines)
return implode("\n", $lines);
}
private function _generateEntityFieldMappingProperties(ClassMetadataInfo $metadata)
......
......@@ -64,8 +64,8 @@ class PhpExporter extends AbstractExporter
$lines[] = "\$metadata->customRepositoryClassName = '" . $metadata->customRepositoryClassName . "';";
}
if ($metadata->primaryTable) {
$lines[] = '$metadata->setPrimaryTable(' . $this->_varExport($metadata->primaryTable) . ');';
if ($metadata->table) {
$lines[] = '$metadata->setPrimaryTable(' . $this->_varExport($metadata->table) . ');';
}
if ($metadata->discriminatorColumn) {
......
......@@ -67,16 +67,16 @@ class XmlExporter extends AbstractExporter
$root->addAttribute('name', $metadata->name);
if (isset($metadata->primaryTable['name'])) {
$root->addAttribute('table', $metadata->primaryTable['name']);
if (isset($metadata->table['name'])) {
$root->addAttribute('table', $metadata->table['name']);
}
if (isset($metadata->primaryTable['schema'])) {
$root->addAttribute('schema', $metadata->primaryTable['schema']);
if (isset($metadata->table['schema'])) {
$root->addAttribute('schema', $metadata->table['schema']);
}
if (isset($metadata->primaryTable['inheritance-type'])) {
$root->addAttribute('inheritance-type', $metadata->primaryTable['inheritance-type']);
if (isset($metadata->table['inheritance-type'])) {
$root->addAttribute('inheritance-type', $metadata->table['inheritance-type']);
}
if ($metadata->discriminatorColumn) {
......@@ -97,20 +97,20 @@ class XmlExporter extends AbstractExporter
$root->addChild('change-tracking-policy', $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy));
if (isset($metadata->primaryTable['indexes'])) {
if (isset($metadata->table['indexes'])) {
$indexesXml = $root->addChild('indexes');
foreach ($metadata->primaryTable['indexes'] as $name => $index) {
foreach ($metadata->table['indexes'] as $name => $index) {
$indexXml = $indexesXml->addChild('index');
$indexXml->addAttribute('name', $name);
$indexXml->addAttribute('columns', implode(',', $index['columns']));
}
}
if (isset($metadata->primaryTable['uniqueConstraints'])) {
if (isset($metadata->table['uniqueConstraints'])) {
$uniqueConstraintsXml = $root->addChild('unique-constraints');
foreach ($metadata->primaryTable['uniqueConstraints'] as $unique) {
foreach ($metadata->table['uniqueConstraints'] as $unique) {
$uniqueConstraintXml = $uniqueConstraintsXml->addChild('unique-constraint');
$uniqueConstraintXml->addAttribute('name', $name);
$uniqueConstraintXml->addAttribute('columns', implode(',', $unique['columns']));
......
......@@ -57,10 +57,10 @@ class YamlExporter extends AbstractExporter
} else {
$array['type'] = 'entity';
}
$array['table'] = $metadata->primaryTable['name'];
$array['table'] = $metadata->table['name'];
if (isset($metadata->primaryTable['schema'])) {
$array['schema'] = $metadata->primaryTable['schema'];
if (isset($metadata->table['schema'])) {
$array['schema'] = $metadata->table['schema'];
}
$inheritanceType = $metadata->inheritanceType;
......@@ -80,12 +80,12 @@ class YamlExporter extends AbstractExporter
$array['changeTrackingPolicy'] = $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy);
}
if (isset($metadata->primaryTable['indexes'])) {
$array['indexes'] = $metadata->primaryTable['indexes'];
if (isset($metadata->table['indexes'])) {
$array['indexes'] = $metadata->table['indexes'];
}
if (isset($metadata->primaryTable['uniqueConstraints'])) {
$array['uniqueConstraints'] = $metadata->primaryTable['uniqueConstraints'];
if (isset($metadata->table['uniqueConstraints'])) {
$array['uniqueConstraints'] = $metadata->table['uniqueConstraints'];
}
$fieldMappings = $metadata->fieldMappings;
......
......@@ -112,11 +112,9 @@ class SchemaTool
{
$processedClasses = array(); // Reminder for processed classes, used for hierarchies
$metadataSchemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig();
$metadataSchemaConfig->setExplicitForeignKeyIndexes(false);
$metadataSchemaConfig->setMaxIdentifierLength(63);
$sm = $this->_em->getConnection()->getSchemaManager();
$metadataSchemaConfig = $sm->createSchemaConfig();
$metadataSchemaConfig->setExplicitForeignKeyIndexes(false);
$schema = new \Doctrine\DBAL\Schema\Schema(array(), array(), $metadataSchemaConfig);
$evm = $this->_em->getEventManager();
......@@ -202,14 +200,14 @@ class SchemaTool
$this->_gatherRelationsSql($class, $table, $schema);
}
if (isset($class->primaryTable['indexes'])) {
foreach ($class->primaryTable['indexes'] AS $indexName => $indexData) {
if (isset($class->table['indexes'])) {
foreach ($class->table['indexes'] AS $indexName => $indexData) {
$table->addIndex($indexData['columns'], $indexName);
}
}
if (isset($class->primaryTable['uniqueConstraints'])) {
foreach ($class->primaryTable['uniqueConstraints'] AS $indexName => $indexData) {
if (isset($class->table['uniqueConstraints'])) {
foreach ($class->table['uniqueConstraints'] AS $indexName => $indexData) {
$table->addUniqueIndex($indexData['columns'], $indexName);
}
}
......
......@@ -280,7 +280,7 @@ class UnitOfWork implements PropertyChangedListener
$commitOrder = $this->_getCommitOrder();
$conn = $this->_em->getConnection();
$conn->beginTransaction();
try {
if ($this->_entityInsertions) {
......@@ -645,7 +645,7 @@ class UnitOfWork implements PropertyChangedListener
$actualData[$name] = $refProp->getValue($entity);
}
}
$originalData = $this->_originalEntityData[$oid];
$changeSet = array();
......@@ -693,7 +693,7 @@ class UnitOfWork implements PropertyChangedListener
}
$postInsertIds = $persister->executeInserts();
if ($postInsertIds) {
// Persister returned post-insert IDs
foreach ($postInsertIds as $id => $entity) {
......
......@@ -147,13 +147,13 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertType('array', $columns['baz1']->getPlatformOptions());
$this->assertEquals('baz2', strtolower($columns['baz2']->getname()));
$this->assertContains($columns['baz2']->gettype()->getName(), array('Time', 'Date', 'DateTime'));
$this->assertContains($columns['baz2']->gettype()->getName(), array('time', 'date', 'datetime'));
$this->assertEquals(true, $columns['baz2']->getnotnull());
$this->assertEquals(null, $columns['baz2']->getdefault());
$this->assertType('array', $columns['baz2']->getPlatformOptions());
$this->assertEquals('baz3', strtolower($columns['baz3']->getname()));
$this->assertContains($columns['baz2']->gettype()->getName(), array('Time', 'Date', 'DateTime'));
$this->assertContains($columns['baz2']->gettype()->getName(), array('time', 'date', 'datetime'));
$this->assertEquals(true, $columns['baz3']->getnotnull());
$this->assertEquals(null, $columns['baz3']->getdefault());
$this->assertType('array', $columns['baz3']->getPlatformOptions());
......
......@@ -6,7 +6,7 @@ class DriverConnectionMock implements \Doctrine\DBAL\Driver\Connection
{
public function prepare($prepareString) {}
public function query() {}
public function quote($input) {}
public function quote($input, $type=\PDO::PARAM_STR) {}
public function exec($statement) {}
public function lastInsertId($name = null) {}
public function beginTransaction() {}
......
......@@ -35,6 +35,6 @@ class OneToOneMappingTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('address', $oneToOneMapping->mappedBy);
$this->assertEquals('Address', $oneToOneMapping->sourceEntityName);
$this->assertEquals('Person', $oneToOneMapping->targetEntityName);
$this->assertTrue($oneToOneMapping->isInverseSide());
$this->assertTrue( ! $oneToOneMapping->isOwningSide);
}
}
\ No newline at end of file
......@@ -123,6 +123,16 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$userId = $this->_em->getConnection()->execute("SELECT user_id FROM cms_addresses WHERE id=?",
array($address->id))->fetchColumn();
$this->assertTrue(is_numeric($userId));
$this->_em->clear();
$user2 = $this->_em->createQuery('select u from Doctrine\Tests\Models\CMS\CmsUser u where u.id=?1')
->setParameter(1, $userId)
->getSingleResult();
// Address has been eager-loaded because it cant be lazy
$this->assertTrue($user2->address instanceof CmsAddress);
$this->assertFalse($user2->address instanceof \Doctrine\ORM\Proxy\Proxy);
}
public function testBasicManyToMany()
......
......@@ -23,10 +23,11 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
protected function setUp() {
$this->useModelSet('company');
parent::setUp();
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
}
public function testCRUD()
{
{
$person = new CompanyPerson;
$person->setName('Roman S. Borschel');
......@@ -78,7 +79,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->clear();
$query = $this->_em->createQuery("update Doctrine\Tests\Models\Company\CompanyEmployee p set p.name = ?1, p.department = ?2 where p.name='Guilherme Blanco' and p.salary = ?3");
$query->setParameter(1, 'NewName');
$query->setParameter(1, 'NewName', 'string');
$query->setParameter(2, 'NewDepartment');
$query->setParameter(3, 100000);
$query->getSql();
......
......@@ -32,14 +32,14 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
public function testGetParameters()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$this->assertEquals(array(1 => 42), $query->getParameters(array(1 => 42)));
$this->assertEquals(array(), $query->getParameters());
}
public function testGetParameters_HasSomeAlready()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->setParameter(2, 84);
$this->assertEquals(array(2 => 84, 1 => 42), $query->getParameters(array(1 => 42)));
$this->assertEquals(array(2 => 84), $query->getParameters());
}
public function testSimpleQueries()
......
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
require_once __DIR__ . '/../../../TestInit.php';
use DateTime, Doctrine\DBAL\Types\Type;
class DDC425Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC425Entity'),
//$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC425Other')
));
}
/**
* @group DDC-425
*/
public function testIssue()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
$num = $this->_em->createQuery('DELETE '.__NAMESPACE__.'\DDC425Entity e WHERE e.someDatetimeField > ?1')
->setParameter(1, new DateTime, Type::DATETIME)
->getResult();
$this->assertEquals(0, $num);
}
}
/** @Entity */
class DDC425Entity {
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
public $id;
/** @Column(type="datetime") */
public $someDatetimeField;
}
......@@ -9,6 +9,7 @@ class DDC444Test extends \Doctrine\Tests\OrmFunctionalTestCase
public function setUp()
{
parent::setUp();
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC444User'),
));
......
......@@ -106,7 +106,6 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$this->assertTrue($class->associationMappings['phonenumbers'] instanceof \Doctrine\ORM\Mapping\OneToManyMapping);
$this->assertTrue(isset($class->associationMappings['phonenumbers']));
$this->assertFalse($class->associationMappings['phonenumbers']->isOwningSide);
$this->assertTrue($class->associationMappings['phonenumbers']->isInverseSide());
$this->assertTrue($class->associationMappings['phonenumbers']->isCascadePersist);
$this->assertFalse($class->associationMappings['phonenumbers']->isCascadeRemove);
$this->assertFalse($class->associationMappings['phonenumbers']->isCascadeRefresh);
......
......@@ -65,7 +65,7 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('Profile', $metadatas['Profile']->associationMappings['User']->sourceEntityName);
$this->assertEquals('User', $metadatas['Profile']->associationMappings['User']->targetEntityName);
$this->assertEquals('username', $metadatas['User']->primaryTable['uniqueConstraints']['username']['columns'][0]);
$this->assertEquals('username', $metadatas['User']->table['uniqueConstraints']['username']['columns'][0]);
unlink(__DIR__ . '/convert/User.dcm.yml');
unlink(__DIR__ . '/convert/Profile.dcm.yml');
......
......@@ -25,7 +25,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
public function testWriteEntityClass()
{
$metadata = new ClassMetadataInfo('EntityGeneratorBook');
$metadata->primaryTable['name'] = 'book';
$metadata->table['name'] = 'book';
$metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'default' => 'published'));
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
......
......@@ -124,7 +124,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
*/
public function testTableIsExported($metadata)
{
$this->assertEquals('cms_users', $metadata->primaryTable['name']);
$this->assertEquals('cms_users', $metadata->table['name']);
return $metadata;
}
......
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