1
0
mirror of synced 2025-01-18 22:41:43 +03:00

[2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Started some method renaming. [DDC-142] Fixed (join column names and discriminator column names dont support quoting) [DDC-258] Fixed.

This commit is contained in:
romanb 2010-03-05 16:35:00 +00:00
parent 715da59ded
commit df6ca602fb
77 changed files with 1578 additions and 1609 deletions

View File

@ -32,14 +32,14 @@ namespace Doctrine\Common\Annotations;
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class AnnotationException extends \Doctrine\Common\DoctrineException
class AnnotationException extends \Doctrine\Common\CommonException
{
public static function syntaxError($message)
{
return new self('[Syntax Error] ' . $message);
}
public static function semanticalError($message)
{
return new self('[Semantical Error] ' . $message);

View File

@ -105,7 +105,9 @@ class AnnotationReader
public function getClassAnnotations(ReflectionClass $class)
{
$cacheKey = $class->getName() . self::$CACHE_SALT;
//FIXME: Just use ->fetch(), otherwise some drivers, i.e. APC will fetch twice because they
// implement contains() in terms of fetch(), *sigh*.
if ($this->_cache->contains($cacheKey)) {
return $this->_cache->fetch($cacheKey);
}
@ -140,7 +142,9 @@ class AnnotationReader
public function getPropertyAnnotations(ReflectionProperty $property)
{
$cacheKey = $property->getDeclaringClass()->getName() . '$' . $property->getName() . self::$CACHE_SALT;
//FIXME: Just use ->fetch(), otherwise some drivers, i.e. APC will fetch twice because they
// implement contains() in terms of fetch(), *sigh*.
if ($this->_cache->contains($cacheKey)) {
return $this->_cache->fetch($cacheKey);
}
@ -176,7 +180,9 @@ class AnnotationReader
public function getMethodAnnotations(ReflectionMethod $method)
{
$cacheKey = $method->getDeclaringClass()->getName() . '#' . $method->getName() . self::$CACHE_SALT;
//FIXME: Just use ->fetch(), otherwise some drivers, i.e. APC will fetch twice because they
// implement contains() in terms of fetch(), *sigh*.
if ($this->_cache->contains($cacheKey)) {
return $this->_cache->fetch($cacheKey);
}

View File

@ -23,7 +23,7 @@ namespace Doctrine\Common\Annotations;
/**
* A simple parser for docblock annotations.
*
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
@ -35,8 +35,8 @@ namespace Doctrine\Common\Annotations;
*/
class Parser
{
/**
* Tags that are stripped prior to parsing in order to reduce parsing overhead.
/**
* Tags that are stripped prior to parsing in order to reduce parsing overhead.
*
* @var array
*/
@ -44,28 +44,28 @@ class Parser
"{@example", "{@id", "{@internal", "{@inheritdoc",
"{@link", "{@source", "{@toc", "{@tutorial", "*/"
);
/**
* The lexer.
*
* @var Doctrine\Common\Annotations\Lexer
*/
private $_lexer;
/**
* Flag to control if the current Annotation is nested or not.
*
* @var boolean
*/
private $_isNestedAnnotation = false;
/**
* Default namespace for Annotations.
*
* @var string
*/
private $_defaultAnnotationNamespace = '';
/**
* Hashmap to store namespace aliases.
*
@ -75,9 +75,9 @@ class Parser
/**
* @var string
*/
*/
private $_context = '';
/**
* Constructs a new AnnotationParser.
*
@ -86,21 +86,21 @@ class Parser
{
$this->_lexer = new Lexer;
}
/**
* Sets the default namespace that is assumed for an annotation that does not
* define a namespace prefix.
*
*
* @param $defaultNamespace
*/
public function setDefaultAnnotationNamespace($defaultNamespace)
{
$this->_defaultAnnotationNamespace = $defaultNamespace;
}
/**
* Sets an alias for an annotation namespace.
*
*
* @param $namespace
* @param $alias
*/
@ -111,7 +111,7 @@ class Parser
/**
* Parses the given docblock string for annotations.
*
*
* @param string $docBlockString
* @param string $context
* @return array Array of Annotations. If no annotations are found, an empty array is returned.
@ -122,18 +122,18 @@ class Parser
// Strip out some known inline tags.
$input = str_replace(self::$_strippedInlineTags, '', $docBlockString);
// Cut of the beginning of the input until the first '@'.
$input = substr($input, strpos($input, '@'));
$this->_lexer->reset();
$this->_lexer->setInput(trim($input, '* /'));
$this->_lexer->moveNext();
if ($this->_lexer->isNextToken(Lexer::T_AT)) {
return $this->Annotations();
}
return array();
}
@ -152,22 +152,22 @@ class Parser
$this->_lexer->moveNext();
}
/**
* Generates a new syntax error.
*
*
* @param string $expected Expected string.
* @param array $token Optional token.
* @throws Exception
* @throws AnnotationException
*/
private function syntaxError($expected, $token = null)
{
if ($token === null) {
$token = $this->_lexer->lookahead;
}
$message = "Expected {$expected}, got ";
if ($this->_lexer->lookahead === null) {
$message .= 'end of string';
} else {
@ -178,10 +178,10 @@ class Parser
$message .= ' in '.$this->_context;
}
$message .= '.';
throw AnnotationException::syntaxError($message);
}
/**
* Annotations ::= Annotation {[ "*" ]* [Annotation]}*
*
@ -190,24 +190,24 @@ class Parser
public function Annotations()
{
$this->_isNestedAnnotation = false;
$annotations = array();
$annot = $this->Annotation();
if ($annot !== false) {
$annotations[get_class($annot)] = $annot;
}
while ($this->_lexer->lookahead !== null && $this->_lexer->isNextToken(Lexer::T_AT)) {
$this->_isNestedAnnotation = false;
$annot = $this->Annotation();
if ($annot !== false) {
$annotations[get_class($annot)] = $annot;
}
}
return $annotations;
}
@ -220,13 +220,13 @@ class Parser
* SimpleName ::= identifier
* Alias ::= identifier
*
* @return mixed False if it is not a valid Annotation; instance of Annotation subclass otherwise.
* @return mixed False if it is not a valid Annotation; instance of Annotation subclass otherwise.
*/
public function Annotation()
{
$values = array();
$nameParts = array();
$this->match(Lexer::T_AT);
$this->match(Lexer::T_IDENTIFIER);
$nameParts[] = $this->_lexer->token['value'];
@ -252,13 +252,13 @@ class Parser
// Is it really an annotation class?
if (
(! $this->_isNestedAnnotation && $this->_lexer->lookahead != null &&
! $this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS) &&
! $this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS) &&
! $this->_lexer->isNextToken(Lexer::T_AT)) ||
! class_exists($name, false) ||
! is_subclass_of($name, 'Doctrine\Common\Annotations\Annotation')
) {
$this->_lexer->skipUntil(Lexer::T_AT);
return false;
}
@ -267,11 +267,11 @@ class Parser
if ($this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) {
$this->match(Lexer::T_OPEN_PARENTHESIS);
if ( ! $this->_lexer->isNextToken(Lexer::T_CLOSE_PARENTHESIS)) {
$values = $this->Values();
}
$this->match(Lexer::T_CLOSE_PARENTHESIS);
}
@ -286,26 +286,26 @@ class Parser
public function Values()
{
$values = array();
// Handle the case of a single array as value, i.e. @Foo({....})
if ($this->_lexer->isNextToken(Lexer::T_OPEN_CURLY_BRACES)) {
$values['value'] = $this->Value();
return $values;
}
$values[] = $this->Value();
while ($this->_lexer->isNextToken(Lexer::T_COMMA)) {
$this->match(Lexer::T_COMMA);
$value = $this->Value();
if ( ! is_array($value)) {
$this->syntaxError('Value', $value);
}
$values[] = $value;
}
foreach ($values as $k => $value) {
if (is_array($value) && is_string(key($value))) {
$key = key($value);
@ -313,10 +313,10 @@ class Parser
} else {
$values['value'] = $value;
}
unset($values[$k]);
}
return $values;
}
@ -328,11 +328,11 @@ class Parser
public function Value()
{
$peek = $this->_lexer->glimpse();
if ($peek['value'] === '=') {
return $this->FieldAssignment();
}
return $this->PlainValue();
}
@ -346,7 +346,7 @@ class Parser
if ($this->_lexer->isNextToken(Lexer::T_OPEN_CURLY_BRACES)) {
return $this->Arrayx();
}
if ($this->_lexer->isNextToken(Lexer::T_AT)) {
return $this->Annotation();
}
@ -355,23 +355,23 @@ class Parser
case Lexer::T_STRING:
$this->match(Lexer::T_STRING);
return $this->_lexer->token['value'];
case Lexer::T_INTEGER:
$this->match(Lexer::T_INTEGER);
return $this->_lexer->token['value'];
case Lexer::T_FLOAT:
$this->match(Lexer::T_FLOAT);
return $this->_lexer->token['value'];
case Lexer::T_TRUE:
$this->match(Lexer::T_TRUE);
return true;
case Lexer::T_FALSE:
$this->match(Lexer::T_FALSE);
return false;
default:
$this->syntaxError('PlainValue');
}
@ -388,7 +388,7 @@ class Parser
$this->match(Lexer::T_IDENTIFIER);
$fieldName = $this->_lexer->token['value'];
$this->match(Lexer::T_EQUALS);
return array($fieldName => $this->PlainValue());
}
@ -400,27 +400,27 @@ class Parser
public function Arrayx()
{
$array = $values = array();
$this->match(Lexer::T_OPEN_CURLY_BRACES);
$values[] = $this->ArrayEntry();
while ($this->_lexer->isNextToken(Lexer::T_COMMA)) {
$this->match(Lexer::T_COMMA);
$values[] = $this->ArrayEntry();
}
$this->match(Lexer::T_CLOSE_CURLY_BRACES);
foreach ($values as $value) {
$key = key($value);
if (is_string($key)) {
$array[$key] = $value[$key];
} else {
$array[] = $value[$key];
}
}
return $array;
}
@ -434,18 +434,18 @@ class Parser
public function ArrayEntry()
{
$peek = $this->_lexer->glimpse();
if ($peek['value'] == '=') {
$this->match(
$this->_lexer->isNextToken(Lexer::T_INTEGER) ? Lexer::T_INTEGER : Lexer::T_STRING
);
$key = $this->_lexer->token['value'];
$this->match(Lexer::T_EQUALS);
return array($key => $this->PlainValue());
}
return array($this->Value());
}
}

View File

@ -18,11 +18,10 @@
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Common\Cli;
use Doctrine\Common\Util\Inflector,
Doctrine\Common\DoctrineException;
use Doctrine\Common\Util\Inflector;
/**
* Abstract CLI Namespace class
@ -42,22 +41,22 @@ abstract class AbstractNamespace
* @var Configuration CLI Configuration instance
*/
private $_configuration = null;
/**
* @var AbstractPrinter CLI Printer instance
*/
private $_printer = null;
/**
* @var AbstractNamespace CLI Namespace instance
*/
private $_parentNamespace = null;
/**
* @var array Available namespaces
*/
private $_namespaces = array();
/**
* Add a single namespace to CLI.
* Example of inclusion support to a single namespace:
@ -72,14 +71,14 @@ abstract class AbstractNamespace
public function addNamespace($name)
{
$name = self::formatName($name);
if ($this->hasNamespace($name)) {
throw DoctrineException::cannotOverrideNamespace($name);
throw CliException::cannotOverrideNamespace($name);
}
return $this->overrideNamespace($name);
}
/**
* Overrides a namespace to CLI.
* Example of inclusion support to a single namespace:
@ -92,18 +91,18 @@ abstract class AbstractNamespace
* @return AbstractNamespace Newly created CLI Namespace
*/
public function overrideNamespace($name)
{
{
$taskNamespace = new TaskNamespace($name);
$taskNamespace->setParentNamespace($this);
$taskNamespace->setPrinter($this->_printer);
$taskNamespace->setConfiguration($this->_configuration);
$this->_namespaces[$taskNamespace->getName()] = $taskNamespace;
return $taskNamespace;
}
/**
* Retrieve CLI Namespace.
* Example of usage:
@ -118,11 +117,11 @@ abstract class AbstractNamespace
public function getNamespace($name)
{
$name = self::formatName($name);
return isset($this->_namespaces[$name])
return isset($this->_namespaces[$name])
? $this->_namespaces[$name] : null;
}
/**
* Check existance of a CLI Namespace
*
@ -134,7 +133,7 @@ abstract class AbstractNamespace
{
return ($this->getNamespace($name) !== null);
}
/**
* Defines the parent CLI Namespace
*
@ -143,10 +142,10 @@ abstract class AbstractNamespace
public function setParentNamespace(AbstractNamespace $namespace)
{
$this->_parentNamespace = $namespace;
return $this;
}
/**
* Retrieves currently parent CLI Namespace
*
@ -156,7 +155,7 @@ abstract class AbstractNamespace
{
return $this->_parentNamespace;
}
/**
* Retrieve all defined CLI Tasks
*
@ -165,14 +164,14 @@ abstract class AbstractNamespace
public function getAvailableTasks()
{
$tasks = array();
foreach ($this->_namespaces as $namespace) {
$tasks = array_merge($tasks, $namespace->getAvailableTasks());
}
return $tasks;
}
/**
* Defines the CLI Output Printer
*
@ -183,10 +182,10 @@ abstract class AbstractNamespace
public function setPrinter(Printers\AbstractPrinter $printer = null)
{
$this->_printer = $printer ?: new Printers\AnsiColorPrinter;
return $this;
}
/**
* Retrieves currently used CLI Output Printer
*
@ -196,7 +195,7 @@ abstract class AbstractNamespace
{
return $this->_printer;
}
/**
* Defines the CLI Configuration
*
@ -207,10 +206,10 @@ abstract class AbstractNamespace
public function setConfiguration(Configuration $config)
{
$this->_configuration = $config;
return $this;
}
/**
* Retrieves currently used CLI Configuration
*
@ -220,7 +219,7 @@ abstract class AbstractNamespace
{
return $this->_configuration;
}
/**
* Formats the CLI Namespace name into a camel-cased name
*

View File

@ -18,10 +18,8 @@
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Common\Cli;
use Doctrine\Common\DoctrineException;
namespace Doctrine\Common\Cli;
/**
* CLI Exception class
@ -35,12 +33,12 @@ use Doctrine\Common\DoctrineException;
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class CliException extends DoctrineException
class CliException extends \Doctrine\Common\CommonException
{
public static function namespaceDoesNotExist($namespaceName, $namespacePath = '')
{
return new self(
"Namespace '{$namespaceName}' does not exist" .
"Namespace '{$namespaceName}' does not exist" .
(( ! empty($namespacePath)) ? " in '{$namespacePath}'." : '.')
);
}
@ -49,9 +47,13 @@ class CliException extends DoctrineException
{
return new self("Task '{$taskName}' does not exist in '{$namespacePath}'.");
}
public static function cannotOverrideTask($taskName)
{
return new self("Task '{$taskName}' cannot be overriden.");
}
public static function cannotOverrideNamespace($namespace) {
return new self("Namespace '$namespace' cannot be overriden. Call overrideNamespace() directly.");
}
}

View File

@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Common\Cli;
/**
@ -39,7 +39,7 @@ class TaskNamespace extends AbstractNamespace
* @var boolean CLI Tasks flag to check if they are already initialized
*/
private $_initialized = false;
/**
* @var string CLI Namespace full name
*/
@ -49,12 +49,12 @@ class TaskNamespace extends AbstractNamespace
* @var string CLI Namespace name
*/
private $_name = null;
/**
* @var array Available tasks
*/
private $_tasks = array();
/**
* The CLI namespace
*
@ -63,8 +63,8 @@ class TaskNamespace extends AbstractNamespace
public function __construct($name)
{
$this->_name = self::formatName($name);
}
}
/**
* Retrieve an instantiated CLI Task by given its name.
*
@ -74,16 +74,16 @@ class TaskNamespace extends AbstractNamespace
*/
public function getTask($name)
{
// Check if task exists in namespace
// Check if task exists in namespace
if ($this->hasTask($name)) {
$taskClass = $this->_tasks[self::formatName($name)];
return new $taskClass($this);
}
}
throw CliException::taskDoesNotExist($name, $this->getFullName());
}
/**
* Retrieve all CLI Task in this Namespace.
*
@ -93,7 +93,7 @@ class TaskNamespace extends AbstractNamespace
{
return $this->_tasks;
}
/**
* Retrieve all defined CLI Tasks
*
@ -102,16 +102,16 @@ class TaskNamespace extends AbstractNamespace
public function getAvailableTasks()
{
$tasks = parent::getAvailableTasks();
foreach ($this->_tasks as $taskName => $taskClass) {
$fullName = $this->getFullName() . ':' . $taskName;
$tasks[$fullName] = $taskClass;
}
return $tasks;
}
/**
* Add a single task to CLI Namespace.
* Example of inclusion support to a single task:
@ -127,14 +127,14 @@ class TaskNamespace extends AbstractNamespace
public function addTask($name, $class)
{
$name = self::formatName($name);
if ($this->hasTask($name)) {
throw DoctrineException::cannotOverrideTask($name);
throw CliException::cannotOverrideTask($name);
}
return $this->overrideTask($name, $class);
}
/**
* Overrides task on CLI Namespace.
* Example of inclusion support to a single task:
@ -148,14 +148,14 @@ class TaskNamespace extends AbstractNamespace
* @return TaskNamespace This object instance
*/
public function overrideTask($name, $class)
{
{
$name = self::formatName($name);
$this->_tasks[$name] = $class;
return $this;
}
/**
* Check existance of a CLI Task
*
@ -166,10 +166,10 @@ class TaskNamespace extends AbstractNamespace
public function hasTask($name)
{
$name = self::formatName($name);
return isset($this->_tasks[$name]);
}
/**
* Retrieves the CLI Namespace name
*
@ -179,7 +179,7 @@ class TaskNamespace extends AbstractNamespace
{
return $this->_name;
}
/**
* Retrieves the full CLI Namespace name
*
@ -189,20 +189,20 @@ class TaskNamespace extends AbstractNamespace
{
if ($this->_fullName === null) {
$str = $this->_name;
while (
($parentNamespace = $this->getParentNamespace()) !== null &&
($parentNamespace = $this->getParentNamespace()) !== null &&
! ($parentNamespace instanceof CliController)
) {
$str = $parentNamespace->getFullName() . ':' . $str;
}
$this->_fullName = $str;
}
return $this->_fullName;
}
/**
* Effectively instantiate and execute a given CLI Task
*
@ -213,14 +213,14 @@ class TaskNamespace extends AbstractNamespace
{
try {
$task = $this->getTask($name);
// Merge global configuration if it exists
if (($globalArgs = $this->getConfiguration()->getAttribute('globalArguments')) !== null) {
$arguments = array_merge($globalArgs, $arguments);
}
$task->setArguments($arguments);
if ((isset($arguments['help']) && $arguments['help']) || (isset($arguments['h']) && $arguments['h'])) {
$task->extendedHelp(); // User explicitly asked for help option
} else if (isset($arguments['basic-help']) && $arguments['basic-help']) {
@ -228,23 +228,23 @@ class TaskNamespace extends AbstractNamespace
} else if ($task->validate()) {
$task->run();
}
} catch (DoctrineException $e) {
} catch (CliException $e) {
$message = $this->getFullName() . ':' . $name . ' => ' . $e->getMessage();
$printer = $this->getPrinter();
// If we want the trace of calls, append to error message
if (isset($arguments['trace']) && $arguments['trace']) {
$message .= PHP_EOL . PHP_EOL . $e->getTraceAsString();
}
$printer->writeln($messageMessage, 'ERROR');
// Unable instantiate task or task is not valid
if ($task !== null) {
$printer->write(PHP_EOL);
$task->basicHelp(); // Fallback of not-valid task arguments
}
$printer->write(PHP_EOL);
}
}

View File

@ -1,138 +0,0 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Common;
/**
* Base Exception class of Doctrine
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @todo Remove
*/
class DoctrineException extends \Exception
{
/**
* @var array Lazy initialized array of error messages
* @static
*/
private static $_messages = array();
/**
* Initializes a new DoctrineException.
*
* @param string $message
* @param Exception $cause Optional Exception
*/
public function __construct($message = "", \Exception $cause = null)
{
$code = ($cause instanceof Exception) ? $cause->getCode() : 0;
parent::__construct($message, $code, $cause);
}
/**
* Throws a DoctrineException reporting not implemented method in a given class
*
* @static
* @param string $method Method name
* @param string $class Class name
* @throws DoctrineException
*/
public static function notImplemented($method = null, $class = null)
{
if ($method && $class) {
return new self("The method '$method' is not implemented in class '$class'.");
} else if ($method && ! $class) {
return new self($method);
} else {
return new self('Functionality is not implemented.');
}
}
/**
* Implementation of __callStatic magic method.
*
* Received a method name and arguments. It lookups a $_messages HashMap
* for matching Class#Method key and executes the returned string value
* translating the placeholders with arguments passed.
*
* @static
* @param string $method Method name
* @param array $arguments Optional arguments to be translated in placeholders
* @throws DoctrineException
*/
public static function __callStatic($method, $arguments = array())
{
$class = get_called_class();
$messageKey = substr($class, strrpos($class, '\\') + 1) . "#$method";
$end = end($arguments);
$innerException = null;
if ($end instanceof \Exception) {
$innerException = $end;
unset($arguments[count($arguments) - 1]);
}
if (($message = self::getExceptionMessage($messageKey)) !== false) {
$message = sprintf($message, $arguments);
} else {
//$dumper = function ($value) { return var_export($value, true); };
$message = strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $method));
$message = ucfirst(str_replace('_', ' ', $message));
/*if ($arguments) {
$message .= ' (' . implode(', ', array_map($dumper, $arguments)) . ')';
}*/
}
return new $class($message, $innerException);
}
/**
* Retrieves error string given a message key for lookup
*
* @static
* @param string $messageKey
* @return string|false Returns the error string if found; FALSE otherwise
*/
public static function getExceptionMessage($messageKey)
{
if ( ! self::$_messages) {
// Lazy-init messages
self::$_messages = array(
'QueryException#nonUniqueResult' =>
"The query contains more than one result."
);
}
if (isset(self::$_messages[$messageKey])) {
return self::$_messages[$messageKey];
}
return false;
}
}

View File

@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Common;
/**
@ -30,12 +30,12 @@ namespace Doctrine\Common;
* is also compatible with the underscore "_" namespace separator.
*
* A recommended class loading setup for optimal performance looks as follows:
*
*
* 1) Use a GlobalClassLoader.
* 2) Reduce the include_path to only the path to the PEAR packages.
* 2) Register the namespaces of any other (non-pear) class library with their
* absolute base paths, like this: $gcl->registerNamespace('Zend', '/path/to/zf-lib');
*
*
* If no base path is configured for a certain namespace, the GlobalClassLoader relies on
* the include_path.
*
@ -46,7 +46,7 @@ namespace Doctrine\Common;
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*
*
* @deprecated Use Doctrine\Common\ClassLoader instead.
*/
class GlobalClassLoader
@ -55,26 +55,26 @@ class GlobalClassLoader
* @var string File extension used for classes
*/
private $_defaultFileExtension = '.php';
/**
* @var array The custom file extensions of class libraries.
*/
private $_fileExtensions = array();
/**
* @var array Hashmap of base paths to class libraries.
*/
private $_basePaths = array();
/**
* Installs this class loader on the SPL autoload stack as the only class loader.
*
* @throws DoctrineException If the SPL autoload stack already contains other autoloaders.
*
* @throws Exception If the SPL autoload stack already contains other autoloaders.
*/
public function register()
{
if (spl_autoload_functions() !== false) {
throw new DoctrineException("Autoload stack is not empty. GlobalClassLoader does not work "
throw new CommonException("Autoload stack is not empty. GlobalClassLoader does not work "
. "in an autoload stack.");
}
spl_autoload_register(array($this, 'loadClass'));
@ -83,7 +83,7 @@ class GlobalClassLoader
/**
* Sets the default file extension of class files.
*
* @param string $extension
* @param string $extension
* @return void
*/
public function setDefaultFileExtension($extension)
@ -117,7 +117,7 @@ class GlobalClassLoader
{
$prefix = '';
$separator = '\\';
if (($pos = strpos($className, $separator)) !== false) {
$prefix = substr($className, 0, strpos($className, $separator));
} else if (($pos = strpos($className, '_')) !== false) {
@ -125,7 +125,7 @@ class GlobalClassLoader
$prefix = substr($className, 0, strpos($className, '_'));
$separator = '_';
}
require ((isset($this->_basePaths[$prefix])) ? $this->_basePaths[$prefix] . DIRECTORY_SEPARATOR : '')
. str_replace($separator, DIRECTORY_SEPARATOR, $className)
. (isset($this->_fileExtensions[$prefix]) ? $this->_fileExtensions[$prefix] : $this->_defaultFileExtension);

View File

@ -409,7 +409,7 @@ class Connection
{
$this->_transactionIsolationLevel = $level;
return $this->executeUpdate($this->_platform->getSetTransactionIsolationSql($level));
return $this->executeUpdate($this->_platform->getSetTransactionIsolationSQL($level));
}
/**
@ -493,7 +493,7 @@ class Connection
*/
public function setCharset($charset)
{
$this->executeUpdate($this->_platform->getSetCharsetSql($charset));
$this->executeUpdate($this->_platform->getSetCharsetSQL($charset));
}
/**

View File

@ -42,6 +42,7 @@ use Doctrine\DBAL\DBALException,
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @todo Remove any unnecessary methods.
*/
abstract class AbstractPlatform
{
@ -492,7 +493,7 @@ abstract class AbstractPlatform
return 'FOR UPDATE';
}
public function getDropDatabaseSql($database)
public function getDropDatabaseSQL($database)
{
return 'DROP DATABASE ' . $database;
}
@ -503,7 +504,7 @@ abstract class AbstractPlatform
* @param Table|string $table
* @return string
*/
public function getDropTableSql($table)
public function getDropTableSQL($table)
{
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
$table = $table->getName();
@ -519,12 +520,12 @@ abstract class AbstractPlatform
* @param string|Table $table
* @return string
*/
public function getDropIndexSql($index, $table=null)
public function getDropIndexSQL($index, $table=null)
{
if($index instanceof \Doctrine\DBAL\Schema\Index) {
$index = $index->getName();
} else if(!is_string($index)) {
throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSql() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
}
return 'DROP INDEX ' . $index;
@ -537,7 +538,7 @@ abstract class AbstractPlatform
* @param string|Table $table
* @return string
*/
public function getDropConstraintSql($constraint, $table)
public function getDropConstraintSQL($constraint, $table)
{
if ($constraint instanceof \Doctrine\DBAL\Schema\Constraint) {
$constraint = $constraint->getName();
@ -555,7 +556,7 @@ abstract class AbstractPlatform
* @param Table|string $table
* @return string
*/
public function getDropForeignKeySql($foreignKey, $table)
public function getDropForeignKeySQL($foreignKey, $table)
{
if ($foreignKey instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) {
$foreignKey = $foreignKey->getName();
@ -576,10 +577,10 @@ abstract class AbstractPlatform
* @param int $createFlags
* @return array The sequence of SQL statements.
*/
public function getCreateTableSql(Table $table, $createFlags=self::CREATE_INDEXES)
public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXES)
{
if (!is_int($createFlags)) {
throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSql() has to be integer.");
throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.");
}
if (count($table->getColumns()) == 0) {
@ -639,7 +640,7 @@ abstract class AbstractPlatform
}
}
return $this->_getCreateTableSql($tableName, $columns, $options);
return $this->_getCreateTableSQL($tableName, $columns, $options);
}
/**
@ -648,13 +649,13 @@ abstract class AbstractPlatform
* @param array $options
* @return array
*/
protected function _getCreateTableSql($tableName, array $columns, array $options = array())
protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
{
$columnListSql = $this->getColumnDeclarationListSql($columns);
$columnListSql = $this->getColumnDeclarationListSQL($columns);
if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
foreach ($options['uniqueConstraints'] as $name => $definition) {
$columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSql($name, $definition);
$columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($name, $definition);
}
}
@ -664,13 +665,13 @@ abstract class AbstractPlatform
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach($options['indexes'] as $index => $definition) {
$columnListSql .= ', ' . $this->getIndexDeclarationSql($index, $definition);
$columnListSql .= ', ' . $this->getIndexDeclarationSQL($index, $definition);
}
}
$query = 'CREATE TABLE ' . $tableName . ' (' . $columnListSql;
$check = $this->getCheckDeclarationSql($columns);
$check = $this->getCheckDeclarationSQL($columns);
if ( ! empty($check)) {
$query .= ', ' . $check;
}
@ -680,14 +681,14 @@ abstract class AbstractPlatform
if (isset($options['foreignKeys'])) {
foreach ((array) $options['foreignKeys'] AS $definition) {
$sql[] = $this->getCreateForeignKeySql($definition, $tableName);
$sql[] = $this->getCreateForeignKeySQL($definition, $tableName);
}
}
return $sql;
}
public function getCreateTemporaryTableSnippetSql()
public function getCreateTemporaryTableSnippetSQL()
{
return "CREATE TEMPORARY TABLE";
}
@ -698,7 +699,7 @@ abstract class AbstractPlatform
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @throws DBALException
*/
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
{
throw DBALException::notSupported(__METHOD__);
}
@ -710,7 +711,7 @@ abstract class AbstractPlatform
* @param string|Table $table
* @return string
*/
public function getCreateConstraintSql(\Doctrine\DBAL\Schema\Constraint $constraint, $table)
public function getCreateConstraintSQL(\Doctrine\DBAL\Schema\Constraint $constraint, $table)
{
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
$table = $table->getName();
@ -732,7 +733,7 @@ abstract class AbstractPlatform
$query .= ' UNIQUE';
} else {
throw new \InvalidArgumentException(
'Can only create primary or unique constraints, no common indexes with getCreateConstraintSql().'
'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'
);
}
} else if ($constraint instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) {
@ -757,7 +758,7 @@ abstract class AbstractPlatform
* @param string|Table $table name of the table on which the index is to be created
* @return string
*/
public function getCreateIndexSql(Index $index, $table)
public function getCreateIndexSQL(Index $index, $table)
{
if ($table instanceof Table) {
$table = $table->getName();
@ -776,7 +777,7 @@ abstract class AbstractPlatform
$query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table;
$query .= ' (' . $this->getIndexFieldDeclarationListSql($columns) . ')';
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')';
return $query;
}
@ -806,13 +807,13 @@ abstract class AbstractPlatform
* @param string|Table $table name of the table on which the foreign key is to be created
* @return string
*/
public function getCreateForeignKeySql(ForeignKeyConstraint $foreignKey, $table)
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
{
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
$table = $table->getName();
}
$query = 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSql($foreignKey);
$query = 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey);
return $query;
}
@ -825,7 +826,7 @@ abstract class AbstractPlatform
* @param TableDiff $diff
* @return array
*/
public function getAlterTableSql(TableDiff $diff)
public function getAlterTableSQL(TableDiff $diff)
{
throw DBALException::notSupported(__METHOD__);
}
@ -836,7 +837,7 @@ abstract class AbstractPlatform
* @param TableDiff $diff
* @return array
*/
protected function _getAlterTableIndexForeignKeySql(TableDiff $diff)
protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff)
{
if ($diff->newName !== false) {
$tableName = $diff->newName;
@ -847,26 +848,26 @@ abstract class AbstractPlatform
$sql = array();
if ($this->supportsForeignKeyConstraints()) {
foreach ($diff->removedForeignKeys AS $foreignKey) {
$sql[] = $this->getDropForeignKeySql($foreignKey, $tableName);
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
}
foreach ($diff->addedForeignKeys AS $foreignKey) {
$sql[] = $this->getCreateForeignKeySql($foreignKey, $tableName);
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName);
}
foreach ($diff->changedForeignKeys AS $foreignKey) {
$sql[] = $this->getDropForeignKeySql($foreignKey, $tableName);
$sql[] = $this->getCreateForeignKeySql($foreignKey, $tableName);
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName);
}
}
foreach ($diff->addedIndexes AS $index) {
$sql[] = $this->getCreateIndexSql($index, $tableName);
$sql[] = $this->getCreateIndexSQL($index, $tableName);
}
foreach ($diff->removedIndexes AS $index) {
$sql[] = $this->getDropIndexSql($index, $tableName);
$sql[] = $this->getDropIndexSQL($index, $tableName);
}
foreach ($diff->changedIndexes AS $index) {
$sql[] = $this->getDropIndexSql($index, $tableName);
$sql[] = $this->getCreateIndexSql($index, $tableName);
$sql[] = $this->getDropIndexSQL($index, $tableName);
$sql[] = $this->getCreateIndexSQL($index, $tableName);
}
return $sql;
@ -901,11 +902,11 @@ abstract class AbstractPlatform
*
* @return string
*/
public function getColumnDeclarationListSql(array $fields)
public function getColumnDeclarationListSQL(array $fields)
{
$queryFields = array();
foreach ($fields as $fieldName => $field) {
$query = $this->getColumnDeclarationSql($fieldName, $field);
$query = $this->getColumnDeclarationSQL($fieldName, $field);
$queryFields[] = $query;
}
return implode(', ', $queryFields);
@ -944,23 +945,23 @@ abstract class AbstractPlatform
*
* @return string DBMS specific SQL code portion that should be used to declare the column.
*/
public function getColumnDeclarationSql($name, array $field)
public function getColumnDeclarationSQL($name, array $field)
{
if (isset($field['columnDefinition'])) {
$columnDef = $this->getCustomTypeDeclarationSql($field);
$columnDef = $this->getCustomTypeDeclarationSQL($field);
} else {
$default = $this->getDefaultValueDeclarationSql($field);
$default = $this->getDefaultValueDeclarationSQL($field);
$charset = (isset($field['charset']) && $field['charset']) ?
' ' . $this->getColumnCharsetDeclarationSql($field['charset']) : '';
' ' . $this->getColumnCharsetDeclarationSQL($field['charset']) : '';
$collation = (isset($field['collation']) && $field['collation']) ?
' ' . $this->getColumnCollationDeclarationSql($field['collation']) : '';
' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : '';
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
$unique = (isset($field['unique']) && $field['unique']) ?
' ' . $this->getUniqueFieldDeclarationSql() : '';
' ' . $this->getUniqueFieldDeclarationSQL() : '';
$check = (isset($field['check']) && $field['check']) ?
' ' . $field['check'] : '';
@ -978,7 +979,7 @@ abstract class AbstractPlatform
* @param array $columnDef
* @return string
*/
public function getDecimalTypeDeclarationSql(array $columnDef)
public function getDecimalTypeDeclarationSQL(array $columnDef)
{
$columnDef['precision'] = ( ! isset($columnDef['precision']) || empty($columnDef['precision']))
? 10 : $columnDef['precision'];
@ -994,7 +995,7 @@ abstract class AbstractPlatform
* @param array $columnDef
* @return string
*/
abstract public function getBooleanTypeDeclarationSql(array $columnDef);
abstract public function getBooleanTypeDeclarationSQL(array $columnDef);
/**
* Gets the SQL snippet that declares a 4 byte integer column.
@ -1002,7 +1003,7 @@ abstract class AbstractPlatform
* @param array $columnDef
* @return string
*/
abstract public function getIntegerTypeDeclarationSql(array $columnDef);
abstract public function getIntegerTypeDeclarationSQL(array $columnDef);
/**
* Gets the SQL snippet that declares an 8 byte integer column.
@ -1010,7 +1011,7 @@ abstract class AbstractPlatform
* @param array $columnDef
* @return string
*/
abstract public function getBigIntTypeDeclarationSql(array $columnDef);
abstract public function getBigIntTypeDeclarationSQL(array $columnDef);
/**
* Gets the SQL snippet that declares a 2 byte integer column.
@ -1018,7 +1019,7 @@ abstract class AbstractPlatform
* @param array $columnDef
* @return string
*/
abstract public function getSmallIntTypeDeclarationSql(array $columnDef);
abstract public function getSmallIntTypeDeclarationSQL(array $columnDef);
/**
* Gets the SQL snippet that declares common properties of an integer column.
@ -1026,7 +1027,7 @@ abstract class AbstractPlatform
* @param array $columnDef
* @return string
*/
abstract protected function _getCommonIntegerTypeDeclarationSql(array $columnDef);
abstract protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef);
/**
* Obtain DBMS specific SQL code portion needed to set a default value
@ -1035,7 +1036,7 @@ abstract class AbstractPlatform
* @param array $field field definition array
* @return string DBMS specific SQL code portion needed to set a default value
*/
public function getDefaultValueDeclarationSql($field)
public function getDefaultValueDeclarationSQL($field)
{
$default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
@ -1044,8 +1045,8 @@ abstract class AbstractPlatform
if (isset($field['type'])) {
if (in_array((string)$field['type'], array("Integer", "BigInteger", "SmallInteger"))) {
$default = " DEFAULT ".$field['default'];
} else if ((string)$field['type'] == 'DateTime' && $field['default'] == $this->getCurrentTimestampSql()) {
$default = " DEFAULT ".$this->getCurrentTimestampSql();
} else if ((string)$field['type'] == 'DateTime' && $field['default'] == $this->getCurrentTimestampSQL()) {
$default = " DEFAULT ".$this->getCurrentTimestampSQL();
}
}
}
@ -1059,7 +1060,7 @@ abstract class AbstractPlatform
* @param array $definition check definition
* @return string DBMS specific SQL code portion needed to set a CHECK constraint
*/
public function getCheckDeclarationSql(array $definition)
public function getCheckDeclarationSQL(array $definition)
{
$constraints = array();
foreach ($definition as $field => $def) {
@ -1088,14 +1089,14 @@ abstract class AbstractPlatform
* @return string DBMS specific SQL code portion needed
* to set a constraint
*/
public function getUniqueConstraintDeclarationSql($name, Index $index)
public function getUniqueConstraintDeclarationSQL($name, Index $index)
{
if (count($index->getColumns()) == 0) {
throw \InvalidArgumentException("Incomplete definition. 'columns' required.");
}
return 'CONSTRAINT' . $name . ' UNIQUE ('
. $this->getIndexFieldDeclarationListSql($index->getColumns())
. $this->getIndexFieldDeclarationListSQL($index->getColumns())
. ')';
}
@ -1107,7 +1108,7 @@ abstract class AbstractPlatform
* @param Index $index index definition
* @return string DBMS specific SQL code portion needed to set an index
*/
public function getIndexDeclarationSql($name, Index $index)
public function getIndexDeclarationSQL($name, Index $index)
{
$type = '';
@ -1120,7 +1121,7 @@ abstract class AbstractPlatform
}
return $type . 'INDEX ' . $name . ' ('
. $this->getIndexFieldDeclarationListSql($index->getColumns())
. $this->getIndexFieldDeclarationListSQL($index->getColumns())
. ')';
}
@ -1132,7 +1133,7 @@ abstract class AbstractPlatform
*
* @return string
*/
public function getCustomTypeDeclarationSql(array $columnDef)
public function getCustomTypeDeclarationSQL(array $columnDef)
{
return $columnDef['columnDefinition'];
}
@ -1144,7 +1145,7 @@ abstract class AbstractPlatform
*
* @return string
*/
public function getIndexFieldDeclarationListSql(array $fields)
public function getIndexFieldDeclarationListSQL(array $fields)
{
$ret = array();
foreach ($fields as $field => $definition) {
@ -1171,23 +1172,22 @@ abstract class AbstractPlatform
* @return string The string required to be placed between "CREATE" and "TABLE"
* to generate a temporary table, if possible.
*/
public function getTemporaryTableSql()
public function getTemporaryTableSQL()
{
return 'TEMPORARY';
}
/**
* Get sql query to show a list of database
* Get sql query to show a list of database.
*
* @return unknown
* @return string
*/
public function getShowDatabasesSql()
public function getShowDatabasesSQL()
{
throw DBALException::notSupported(__METHOD__);
}
/**
* getForeignKeyDeclaration
* Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
* of a field declaration to be used in statements like CREATE TABLE.
*
@ -1228,10 +1228,10 @@ abstract class AbstractPlatform
* @return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
* of a field declaration.
*/
public function getForeignKeyDeclarationSql(ForeignKeyConstraint $foreignKey)
public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey)
{
$sql = $this->getForeignKeyBaseDeclarationSql($foreignKey);
$sql .= $this->getAdvancedForeignKeyOptionsSql($foreignKey);
$sql = $this->getForeignKeyBaseDeclarationSQL($foreignKey);
$sql .= $this->getAdvancedForeignKeyOptionsSQL($foreignKey);
return $sql;
}
@ -1243,14 +1243,14 @@ abstract class AbstractPlatform
* @param ForeignKeyConstraint $foreignKey foreign key definition
* @return string
*/
public function getAdvancedForeignKeyOptionsSql(ForeignKeyConstraint $foreignKey)
public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey)
{
$query = '';
if ($this->supportsForeignKeyOnUpdate() && $foreignKey->hasOption('onUpdate')) {
$query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSql($foreignKey->getOption('onUpdate'));
$query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onUpdate'));
}
if ($foreignKey->hasOption('onDelete')) {
$query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSql($foreignKey->getOption('onDelete'));
$query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onDelete'));
}
return $query;
}
@ -1263,7 +1263,7 @@ abstract class AbstractPlatform
* @param string $action foreign key referential action
* @param string foreign key referential action in uppercase
*/
public function getForeignKeyReferentialActionSql($action)
public function getForeignKeyReferentialActionSQL($action)
{
$upper = strtoupper($action);
switch ($upper) {
@ -1286,7 +1286,7 @@ abstract class AbstractPlatform
* @param ForeignKeyConstraint $foreignKey
* @return string
*/
public function getForeignKeyBaseDeclarationSql(ForeignKeyConstraint $foreignKey)
public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey)
{
$sql = '';
if (strlen($foreignKey->getName())) {
@ -1319,7 +1319,7 @@ abstract class AbstractPlatform
* @return string DBMS specific SQL code portion needed to set the UNIQUE constraint
* of a field declaration.
*/
public function getUniqueFieldDeclarationSql()
public function getUniqueFieldDeclarationSQL()
{
return 'UNIQUE';
}
@ -1332,7 +1332,7 @@ abstract class AbstractPlatform
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration.
*/
public function getColumnCharsetDeclarationSql($charset)
public function getColumnCharsetDeclarationSQL($charset)
{
return '';
}
@ -1345,7 +1345,7 @@ abstract class AbstractPlatform
* @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration.
*/
public function getColumnCollationDeclarationSql($collation)
public function getColumnCollationDeclarationSQL($collation)
{
return '';
}
@ -1402,7 +1402,7 @@ abstract class AbstractPlatform
* @param string $charset
* @return string
*/
public function getSetCharsetSql($charset)
public function getSetCharsetSQL($charset)
{
return "SET NAMES '".$charset."'";
}
@ -1412,7 +1412,7 @@ abstract class AbstractPlatform
*
* @return string
*/
public function getCurrentDateSql()
public function getCurrentDateSQL()
{
return 'CURRENT_DATE';
}
@ -1422,7 +1422,7 @@ abstract class AbstractPlatform
*
* @return string
*/
public function getCurrentTimeSql()
public function getCurrentTimeSQL()
{
return 'CURRENT_TIME';
}
@ -1432,7 +1432,7 @@ abstract class AbstractPlatform
*
* @return string
*/
public function getCurrentTimestampSql()
public function getCurrentTimestampSQL()
{
return 'CURRENT_TIMESTAMP';
}
@ -1442,7 +1442,7 @@ abstract class AbstractPlatform
*
* @param integer $level
*/
protected function _getTransactionIsolationLevelSql($level)
protected function _getTransactionIsolationLevelSQL($level)
{
switch ($level) {
case Connection::TRANSACTION_READ_UNCOMMITTED:
@ -1458,32 +1458,32 @@ abstract class AbstractPlatform
}
}
public function getListDatabasesSql()
public function getListDatabasesSQL()
{
throw DBALException::notSupported(__METHOD__);
}
public function getListSequencesSql($database)
public function getListSequencesSQL($database)
{
throw DBALException::notSupported(__METHOD__);
}
public function getListTableConstraintsSql($table)
public function getListTableConstraintsSQL($table)
{
throw DBALException::notSupported(__METHOD__);
}
public function getListTableColumnsSql($table)
public function getListTableColumnsSQL($table)
{
throw DBALException::notSupported(__METHOD__);
}
public function getListTablesSql()
public function getListTablesSQL()
{
throw DBALException::notSupported(__METHOD__);
}
public function getListUsersSql()
public function getListUsersSQL()
{
throw DBALException::notSupported(__METHOD__);
}
@ -1494,42 +1494,42 @@ abstract class AbstractPlatform
* @param string $database
* @return string
*/
public function getListViewsSql($database)
public function getListViewsSQL($database)
{
throw DBALException::notSupported(__METHOD__);
}
public function getListTableIndexesSql($table)
public function getListTableIndexesSQL($table)
{
throw DBALException::notSupported(__METHOD__);
}
public function getListTableForeignKeysSql($table)
public function getListTableForeignKeysSQL($table)
{
throw DBALException::notSupported(__METHOD__);
}
public function getCreateViewSql($name, $sql)
public function getCreateViewSQL($name, $sql)
{
throw DBALException::notSupported(__METHOD__);
}
public function getDropViewSql($name)
public function getDropViewSQL($name)
{
throw DBALException::notSupported(__METHOD__);
}
public function getDropSequenceSql($sequence)
public function getDropSequenceSQL($sequence)
{
throw DBALException::notSupported(__METHOD__);
}
public function getSequenceNextValSql($sequenceName)
public function getSequenceNextValSQL($sequenceName)
{
throw DBALException::notSupported(__METHOD__);
}
public function getCreateDatabaseSql($database)
public function getCreateDatabaseSQL($database)
{
throw DBALException::notSupported(__METHOD__);
}
@ -1539,7 +1539,7 @@ abstract class AbstractPlatform
*
* @param integer $level
*/
public function getSetTransactionIsolationSql($level)
public function getSetTransactionIsolationSQL($level)
{
throw DBALException::notSupported(__METHOD__);
}
@ -1551,7 +1551,7 @@ abstract class AbstractPlatform
* @param array $fieldDeclaration
* @return string
*/
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{
throw DBALException::notSupported(__METHOD__);
}
@ -1563,7 +1563,7 @@ abstract class AbstractPlatform
* @param array $fieldDeclaration
* @return string
*/
public function getDateTypeDeclarationSql(array $fieldDeclaration)
public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{
throw DBALException::notSupported(__METHOD__);
}
@ -1575,7 +1575,7 @@ abstract class AbstractPlatform
* @param array $fieldDeclaration
* @return string
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{
throw DBALException::notSupported(__METHOD__);
}
@ -1709,7 +1709,7 @@ abstract class AbstractPlatform
return true;
}
public function getIdentityColumnNullInsertSql()
public function getIdentityColumnNullInsertSQL()
{
return "";
}
@ -1768,14 +1768,14 @@ abstract class AbstractPlatform
*
* @param array $field
*/
abstract public function getVarcharTypeDeclarationSql(array $field);
abstract public function getVarcharTypeDeclarationSQL(array $field);
/**
* Gets the SQL snippet used to declare a CLOB column type.
*
* @param array $field
*/
abstract public function getClobTypeDeclarationSql(array $field);
abstract public function getClobTypeDeclarationSQL(array $field);
/**
* Gets the name of the platform.
@ -1790,7 +1790,7 @@ abstract class AbstractPlatform
* @param string $column The column name for which to get the correct character casing.
* @return string The column name in the character casing used in SQL result sets.
*/
public function getSqlResultCasing($column)
public function getSQLResultCasing($column)
{
return $column;
}
@ -1824,7 +1824,7 @@ abstract class AbstractPlatform
* @param string $identifierColumnName
* @return string $sql
*/
public function getEmptyIdentityInsertSql($tableName, $identifierColumnName)
public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName)
{
return 'INSERT INTO ' . $tableName . ' (' . $identifierColumnName . ') VALUES (null)';
}
@ -1839,7 +1839,7 @@ abstract class AbstractPlatform
* @param bool $cascade
* @return string
*/
public function getTruncateTableSql($tableName, $cascade = false)
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE '.$tableName;
}

View File

@ -90,7 +90,7 @@ class MsSqlPlatform extends AbstractPlatform
* @param TableDiff $diff
* @return array
*/
public function getAlterTableSql(TableDiff $diff)
public function getAlterTableSQL(TableDiff $diff)
{
$queryParts = array();
if ($diff->newName !== false) {
@ -98,7 +98,7 @@ class MsSqlPlatform extends AbstractPlatform
}
foreach ($diff->addedColumns AS $fieldName => $column) {
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSql($column->getName(), $column->toArray());
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
}
foreach ($diff->removedColumns AS $column) {
@ -109,19 +109,19 @@ class MsSqlPlatform extends AbstractPlatform
/* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
$column = $columnDiff->column;
$queryParts[] = 'CHANGE ' . ($columnDiff->oldColumnName) . ' '
. $this->getColumnDeclarationSql($column->getName(), $column->toArray());
. $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
}
foreach ($diff->renamedColumns AS $oldColumnName => $column) {
$queryParts[] = 'CHANGE ' . $oldColumnName . ' '
. $this->getColumnDeclarationSql($column->getName(), $column->toArray());
. $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
}
$sql = array();
if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff));
return $sql;
}
@ -233,12 +233,12 @@ class MsSqlPlatform extends AbstractPlatform
return false;
}
public function getShowDatabasesSql()
public function getShowDatabasesSQL()
{
return 'SHOW DATABASES';
}
public function getListTablesSql()
public function getListTablesSQL()
{
return 'SHOW TABLES';
}
@ -250,7 +250,7 @@ class MsSqlPlatform extends AbstractPlatform
* @return string
* @override
*/
public function getCreateDatabaseSql($name)
public function getCreateDatabaseSQL($name)
{
return 'CREATE DATABASE ' . $name;
}
@ -262,41 +262,41 @@ class MsSqlPlatform extends AbstractPlatform
* @return string
* @override
*/
public function getDropDatabaseSql($name)
public function getDropDatabaseSQL($name)
{
return 'DROP DATABASE ' . $name;
}
public function getSetTransactionIsolationSql($level)
public function getSetTransactionIsolationSQL($level)
{
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level);
}
/**
* @override
*/
public function getIntegerTypeDeclarationSql(array $field)
public function getIntegerTypeDeclarationSQL(array $field)
{
return 'INT' . $this->_getCommonIntegerTypeDeclarationSql($field);
return 'INT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/**
* @override
*/
public function getBigIntTypeDeclarationSql(array $field)
public function getBigIntTypeDeclarationSQL(array $field)
{
return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/**
* @override
*/
public function getSmallIntTypeDeclarationSql(array $field)
public function getSmallIntTypeDeclarationSQL(array $field)
{
return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
}
public function getVarcharTypeDeclarationSql(array $field)
public function getVarcharTypeDeclarationSQL(array $field)
{
if ( ! isset($field['length'])) {
if (array_key_exists('default', $field)) {
@ -314,7 +314,7 @@ class MsSqlPlatform extends AbstractPlatform
}
/** @override */
public function getClobTypeDeclarationSql(array $field)
public function getClobTypeDeclarationSQL(array $field)
{
return 'TEXT';
}
@ -322,7 +322,7 @@ class MsSqlPlatform extends AbstractPlatform
/**
* @override
*/
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{
$autoinc = '';
if ( ! empty($columnDef['autoincrement'])) {
@ -336,7 +336,7 @@ class MsSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{
return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
}
@ -344,7 +344,7 @@ class MsSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getDateTypeDeclarationSql(array $fieldDeclaration)
public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{
return 'CHAR(' . strlen('YYYY-MM-DD') . ')';
}
@ -352,7 +352,7 @@ class MsSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{
return 'CHAR(' . strlen('HH:MM:SS') . ')';
}
@ -360,7 +360,7 @@ class MsSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getBooleanTypeDeclarationSql(array $field)
public function getBooleanTypeDeclarationSQL(array $field)
{
return 'BIT';
}
@ -470,7 +470,7 @@ class MsSqlPlatform extends AbstractPlatform
* @param string $identifierColumnName
* @return string $sql
*/
public function getEmptyIdentityInsertSql($quotedTableName, $quotedIdentifierColumnName)
public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName)
{
return 'INSERT INTO ' . $quotedTableName . ' DEFAULT VALUES';
}
@ -478,7 +478,7 @@ class MsSqlPlatform extends AbstractPlatform
/**
* @inheritdoc
*/
public function getTruncateTableSql($tableName, $cascade = false)
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE TABLE '.$tableName;
}

View File

@ -100,27 +100,27 @@ class MySqlPlatform extends AbstractPlatform
return 'CONCAT(' . join(', ', (array) $args) . ')';
}
public function getListDatabasesSql()
public function getListDatabasesSQL()
{
return 'SHOW DATABASES';
}
public function getListTableConstraintsSql($table)
public function getListTableConstraintsSQL($table)
{
return 'SHOW INDEX FROM ' . $table;
}
public function getListTableIndexesSql($table)
public function getListTableIndexesSQL($table)
{
return 'SHOW INDEX FROM ' . $table;
}
public function getListViewsSql($database)
public function getListViewsSQL($database)
{
return "SELECT * FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '".$database."'";
}
public function getListTableForeignKeysSql($table, $database = null)
public function getListTableForeignKeysSQL($table, $database = null)
{
$sql = "SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, ".
"k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ ".
@ -138,12 +138,12 @@ class MySqlPlatform extends AbstractPlatform
return $sql;
}
public function getCreateViewSql($name, $sql)
public function getCreateViewSQL($name, $sql)
{
return 'CREATE VIEW ' . $name . ' AS ' . $sql;
}
public function getDropViewSql($name)
public function getDropViewSQL($name)
{
return 'DROP VIEW '. $name;
}
@ -153,7 +153,7 @@ class MySqlPlatform extends AbstractPlatform
*
* @params array $field
*/
public function getVarcharTypeDeclarationSql(array $field)
public function getVarcharTypeDeclarationSQL(array $field)
{
if ( ! isset($field['length'])) {
if (array_key_exists('default', $field)) {
@ -171,7 +171,7 @@ class MySqlPlatform extends AbstractPlatform
}
/** @override */
public function getClobTypeDeclarationSql(array $field)
public function getClobTypeDeclarationSQL(array $field)
{
if ( ! empty($field['length'])) {
$length = $field['length'];
@ -189,7 +189,7 @@ class MySqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{
if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) {
return 'TIMESTAMP';
@ -201,7 +201,7 @@ class MySqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getDateTypeDeclarationSql(array $fieldDeclaration)
public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{
return 'DATE';
}
@ -209,7 +209,7 @@ class MySqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{
return 'TIME';
}
@ -217,7 +217,7 @@ class MySqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getBooleanTypeDeclarationSql(array $field)
public function getBooleanTypeDeclarationSQL(array $field)
{
return 'TINYINT(1)';
}
@ -271,17 +271,17 @@ class MySqlPlatform extends AbstractPlatform
return false;
}
public function getShowDatabasesSql()
public function getShowDatabasesSQL()
{
return 'SHOW DATABASES';
}
public function getListTablesSql()
public function getListTablesSQL()
{
return 'SHOW FULL TABLES WHERE Table_type = "BASE TABLE"';
}
public function getListTableColumnsSql($table)
public function getListTableColumnsSQL($table)
{
return 'DESCRIBE ' . $table;
}
@ -293,7 +293,7 @@ class MySqlPlatform extends AbstractPlatform
* @return string
* @override
*/
public function getCreateDatabaseSql($name)
public function getCreateDatabaseSQL($name)
{
return 'CREATE DATABASE ' . $name;
}
@ -305,7 +305,7 @@ class MySqlPlatform extends AbstractPlatform
* @return string
* @override
*/
public function getDropDatabaseSql($name)
public function getDropDatabaseSQL($name)
{
return 'DROP DATABASE ' . $name;
}
@ -345,20 +345,20 @@ class MySqlPlatform extends AbstractPlatform
* @return void
* @override
*/
protected function _getCreateTableSql($tableName, array $columns, array $options = array())
protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
{
$queryFields = $this->getColumnDeclarationListSql($columns);
$queryFields = $this->getColumnDeclarationListSQL($columns);
if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
foreach ($options['uniqueConstraints'] as $index => $definition) {
$queryFields .= ', ' . $this->getUniqueConstraintDeclarationSql($index, $definition);
$queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($index, $definition);
}
}
// add all indexes
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach($options['indexes'] as $index => $definition) {
$queryFields .= ', ' . $this->getIndexDeclarationSql($index, $definition);
$queryFields .= ', ' . $this->getIndexDeclarationSQL($index, $definition);
}
}
@ -401,7 +401,7 @@ class MySqlPlatform extends AbstractPlatform
if (isset($options['foreignKeys'])) {
foreach ((array) $options['foreignKeys'] as $definition) {
$sql[] = $this->getCreateForeignKeySql($definition, $tableName);
$sql[] = $this->getCreateForeignKeySQL($definition, $tableName);
}
}
@ -497,7 +497,7 @@ class MySqlPlatform extends AbstractPlatform
* @return boolean
* @override
*/
public function getAlterTableSql(TableDiff $diff)
public function getAlterTableSQL(TableDiff $diff)
{
$queryParts = array();
if ($diff->newName !== false) {
@ -505,7 +505,7 @@ class MySqlPlatform extends AbstractPlatform
}
foreach ($diff->addedColumns AS $fieldName => $column) {
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSql($column->getName(), $column->toArray());
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
}
foreach ($diff->removedColumns AS $column) {
@ -516,19 +516,19 @@ class MySqlPlatform extends AbstractPlatform
/* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
$column = $columnDiff->column;
$queryParts[] = 'CHANGE ' . ($columnDiff->oldColumnName) . ' '
. $this->getColumnDeclarationSql($column->getName(), $column->toArray());
. $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
}
foreach ($diff->renamedColumns AS $oldColumnName => $column) {
$queryParts[] = 'CHANGE ' . $oldColumnName . ' '
. $this->getColumnDeclarationSql($column->getName(), $column->toArray());
. $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
}
$sql = array();
if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff));
return $sql;
}
@ -558,25 +558,25 @@ class MySqlPlatform extends AbstractPlatform
* declare the specified field.
* @override
*/
public function getIntegerTypeDeclarationSql(array $field)
public function getIntegerTypeDeclarationSQL(array $field)
{
return 'INT' . $this->_getCommonIntegerTypeDeclarationSql($field);
return 'INT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/** @override */
public function getBigIntTypeDeclarationSql(array $field)
public function getBigIntTypeDeclarationSQL(array $field)
{
return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/** @override */
public function getSmallIntTypeDeclarationSql(array $field)
public function getSmallIntTypeDeclarationSQL(array $field)
{
return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/** @override */
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{
$autoinc = '';
if ( ! empty($columnDef['autoincrement'])) {
@ -595,13 +595,13 @@ class MySqlPlatform extends AbstractPlatform
* @return string
* @override
*/
public function getAdvancedForeignKeyOptionsSql(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey)
public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey)
{
$query = '';
if ($foreignKey->hasOption('match')) {
$query .= ' MATCH ' . $foreignKey->getOption('match');
}
$query .= parent::getAdvancedForeignKeyOptionsSql($foreignKey);
$query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey);
return $query;
}
@ -612,18 +612,18 @@ class MySqlPlatform extends AbstractPlatform
* @param string|Table $table name of table that should be used in method
* @override
*/
public function getDropIndexSql($index, $table=null)
public function getDropIndexSQL($index, $table=null)
{
if($index instanceof \Doctrine\DBAL\Schema\Index) {
$index = $index->getName();
} else if(!is_string($index)) {
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSql() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
}
if($table instanceof \Doctrine\DBAL\Schema\Table) {
$table = $table->getName();
} else if(!is_string($table)) {
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSql() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
}
return 'DROP INDEX ' . $index . ' ON ' . $table;
@ -635,20 +635,20 @@ class MySqlPlatform extends AbstractPlatform
* @param string $table The name of table to drop.
* @override
*/
public function getDropTableSql($table)
public function getDropTableSQL($table)
{
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
$table = $table->getName();
} else if(!is_string($table)) {
throw new \InvalidArgumentException('MysqlPlatform::getDropTableSql() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
throw new \InvalidArgumentException('MysqlPlatform::getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
}
return 'DROP TABLE ' . $table;
}
public function getSetTransactionIsolationSql($level)
public function getSetTransactionIsolationSQL($level)
{
return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level);
}
/**

View File

@ -113,7 +113,7 @@ class OraclePlatform extends AbstractPlatform
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @return string
*/
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
{
return 'CREATE SEQUENCE ' . $sequence->getName() .
' START WITH ' . $sequence->getInitialValue() .
@ -127,7 +127,7 @@ class OraclePlatform extends AbstractPlatform
* @param string $sequenceName
* @override
*/
public function getSequenceNextValSql($sequenceName)
public function getSequenceNextValSQL($sequenceName)
{
return 'SELECT ' . $sequenceName . '.nextval FROM DUAL';
}
@ -138,12 +138,12 @@ class OraclePlatform extends AbstractPlatform
* @param integer $level
* @override
*/
public function getSetTransactionIsolationSql($level)
public function getSetTransactionIsolationSQL($level)
{
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level);
}
protected function _getTransactionIsolationLevelSql($level)
protected function _getTransactionIsolationLevelSQL($level)
{
switch ($level) {
case \Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED:
@ -154,14 +154,14 @@ class OraclePlatform extends AbstractPlatform
case \Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE:
return 'SERIALIZABLE';
default:
return parent::_getTransactionIsolationLevelSql($level);
return parent::_getTransactionIsolationLevelSQL($level);
}
}
/**
* @override
*/
public function getBooleanTypeDeclarationSql(array $field)
public function getBooleanTypeDeclarationSQL(array $field)
{
return 'NUMBER(1)';
}
@ -169,7 +169,7 @@ class OraclePlatform extends AbstractPlatform
/**
* @override
*/
public function getIntegerTypeDeclarationSql(array $field)
public function getIntegerTypeDeclarationSQL(array $field)
{
return 'NUMBER(10)';
}
@ -177,7 +177,7 @@ class OraclePlatform extends AbstractPlatform
/**
* @override
*/
public function getBigIntTypeDeclarationSql(array $field)
public function getBigIntTypeDeclarationSQL(array $field)
{
return 'NUMBER(20)';
}
@ -185,7 +185,7 @@ class OraclePlatform extends AbstractPlatform
/**
* @override
*/
public function getSmallIntTypeDeclarationSql(array $field)
public function getSmallIntTypeDeclarationSQL(array $field)
{
return 'NUMBER(5)';
}
@ -193,7 +193,7 @@ class OraclePlatform extends AbstractPlatform
/**
* @override
*/
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{
return 'TIMESTAMP(0) WITH TIME ZONE';
}
@ -201,7 +201,7 @@ class OraclePlatform extends AbstractPlatform
/**
* @override
*/
public function getDateTypeDeclarationSql(array $fieldDeclaration)
public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{
return 'DATE';
}
@ -209,7 +209,7 @@ class OraclePlatform extends AbstractPlatform
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{
return 'DATE';
}
@ -217,7 +217,7 @@ class OraclePlatform extends AbstractPlatform
/**
* @override
*/
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{
return '';
}
@ -228,7 +228,7 @@ class OraclePlatform extends AbstractPlatform
* @params array $field
* @override
*/
public function getVarcharTypeDeclarationSql(array $field)
public function getVarcharTypeDeclarationSQL(array $field)
{
if ( ! isset($field['length'])) {
if (array_key_exists('default', $field)) {
@ -246,17 +246,17 @@ class OraclePlatform extends AbstractPlatform
}
/** @override */
public function getClobTypeDeclarationSql(array $field)
public function getClobTypeDeclarationSQL(array $field)
{
return 'CLOB';
}
public function getListDatabasesSql()
public function getListDatabasesSQL()
{
return 'SELECT username FROM all_users';
}
public function getListSequencesSql($database)
public function getListSequencesSQL($database)
{
return "SELECT sequence_name, min_value, increment_by FROM sys.all_sequences ".
"WHERE SEQUENCE_OWNER = '".strtoupper($database)."'";
@ -269,15 +269,15 @@ class OraclePlatform extends AbstractPlatform
* @param array $options
* @return array
*/
protected function _getCreateTableSql($table, array $columns, array $options = array())
protected function _getCreateTableSQL($table, array $columns, array $options = array())
{
$indexes = isset($options['indexes']) ? $options['indexes'] : array();
$options['indexes'] = array();
$sql = parent::_getCreateTableSql($table, $columns, $options);
$sql = parent::_getCreateTableSQL($table, $columns, $options);
foreach ($columns as $name => $column) {
if (isset($column['sequence'])) {
$sql[] = $this->getCreateSequenceSql($column['sequence'], 1);
$sql[] = $this->getCreateSequenceSQL($column['sequence'], 1);
}
if (isset($column['autoincrement']) && $column['autoincrement'] ||
@ -288,7 +288,7 @@ class OraclePlatform extends AbstractPlatform
if (isset($indexes) && ! empty($indexes)) {
foreach ($indexes as $indexName => $index) {
$sql[] = $this->getCreateIndexSql($index, $table);
$sql[] = $this->getCreateIndexSQL($index, $table);
}
}
@ -301,7 +301,7 @@ class OraclePlatform extends AbstractPlatform
* @param string $table
* @return string
*/
public function getListTableIndexesSql($table)
public function getListTableIndexesSQL($table)
{
$table = strtoupper($table);
@ -315,22 +315,22 @@ class OraclePlatform extends AbstractPlatform
"WHERE uind.index_name = uind_col.index_name AND uind_col.table_name = '$table' ORDER BY uind_col.column_position ASC";
}
public function getListTablesSql()
public function getListTablesSQL()
{
return 'SELECT * FROM sys.user_tables';
}
public function getListViewsSql($database)
public function getListViewsSQL($database)
{
return 'SELECT view_name, text FROM sys.user_views';
}
public function getCreateViewSql($name, $sql)
public function getCreateViewSQL($name, $sql)
{
return 'CREATE VIEW ' . $name . ' AS ' . $sql;
}
public function getDropViewSql($name)
public function getDropViewSQL($name)
{
return 'DROP VIEW '. $name;
}
@ -353,13 +353,13 @@ class OraclePlatform extends AbstractPlatform
BEGIN
SELECT COUNT(CONSTRAINT_NAME) INTO constraints_Count FROM USER_CONSTRAINTS WHERE TABLE_NAME = \''.$table.'\' AND CONSTRAINT_TYPE = \'P\';
IF constraints_Count = 0 OR constraints_Count = \'\' THEN
EXECUTE IMMEDIATE \''.$this->getCreateConstraintSql($idx, $table).'\';
EXECUTE IMMEDIATE \''.$this->getCreateConstraintSQL($idx, $table).'\';
END IF;
END;';
$sequenceName = $table . '_SEQ';
$sequence = new \Doctrine\DBAL\Schema\Sequence($sequenceName, $start);
$sql[] = $this->getCreateSequenceSql($sequence);
$sql[] = $this->getCreateSequenceSQL($sequence);
$triggerName = $table . '_AI_PK';
$sql[] = 'CREATE TRIGGER ' . $triggerName . '
@ -393,16 +393,16 @@ END;';
if ($trigger) {
$sql[] = 'DROP TRIGGER ' . $trigger;
$sql[] = $this->getDropSequenceSql($table.'_SEQ');
$sql[] = $this->getDropSequenceSQL($table.'_SEQ');
$indexName = $table . '_AI_PK';
$sql[] = $this->getDropConstraintSql($indexName, $table);
$sql[] = $this->getDropConstraintSQL($indexName, $table);
}
return $sql;
}
public function getListTableForeignKeysSql($table)
public function getListTableForeignKeysSQL($table)
{
$table = strtoupper($table);
@ -429,13 +429,13 @@ LEFT JOIN all_cons_columns r_cols
AND alc.table_name = '".$table."'";
}
public function getListTableConstraintsSql($table)
public function getListTableConstraintsSQL($table)
{
$table = strtoupper($table);
return 'SELECT * FROM user_constraints WHERE table_name = \'' . $table . '\'';
}
public function getListTableColumnsSql($table)
public function getListTableColumnsSQL($table)
{
$table = strtoupper($table);
return "SELECT * FROM all_tab_columns WHERE table_name = '" . $table . "' ORDER BY column_name";
@ -446,7 +446,7 @@ LEFT JOIN all_cons_columns r_cols
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @return string
*/
public function getDropSequenceSql($sequence)
public function getDropSequenceSQL($sequence)
{
if ($sequence instanceof \Doctrine\DBAL\Schema\Sequence) {
$sequence = $sequence->getName();
@ -460,7 +460,7 @@ LEFT JOIN all_cons_columns r_cols
* @param Table|string $table
* @return string
*/
public function getDropForeignKeySql($foreignKey, $table)
public function getDropForeignKeySQL($foreignKey, $table)
{
if ($foreignKey instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) {
$foreignKey = $foreignKey->getName();
@ -473,7 +473,7 @@ LEFT JOIN all_cons_columns r_cols
return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $foreignKey;
}
public function getDropDatabaseSql($database)
public function getDropDatabaseSQL($database)
{
return 'DROP USER ' . $database . ' CASCADE';
}
@ -490,13 +490,13 @@ LEFT JOIN all_cons_columns r_cols
* actually perform them otherwise.
* @return array
*/
public function getAlterTableSql(TableDiff $diff)
public function getAlterTableSQL(TableDiff $diff)
{
$sql = array();
$fields = array();
foreach ($diff->addedColumns AS $column) {
$fields[] = $this->getColumnDeclarationSql($column->getName(), $column->toArray());
$fields[] = $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
}
if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ADD (' . implode(', ', $fields) . ')';
@ -505,7 +505,7 @@ LEFT JOIN all_cons_columns r_cols
$fields = array();
foreach ($diff->changedColumns AS $columnDiff) {
$column = $columnDiff->column;
$fields[] = $column->getName(). ' ' . $this->getColumnDeclarationSql('', $column->toArray());
$fields[] = $column->getName(). ' ' . $this->getColumnDeclarationSQL('', $column->toArray());
}
if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' MODIFY (' . implode(', ', $fields) . ')';
@ -527,7 +527,7 @@ LEFT JOIN all_cons_columns r_cols
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff));
return $sql;
}
@ -594,12 +594,12 @@ LEFT JOIN all_cons_columns r_cols
* @param string $column The column name for which to get the correct character casing.
* @return string The column name in the character casing used in SQL result sets.
*/
public function getSqlResultCasing($column)
public function getSQLResultCasing($column)
{
return strtoupper($column);
}
public function getCreateTemporaryTableSnippetSql()
public function getCreateTemporaryTableSnippetSQL()
{
return "CREATE GLOBAL TEMPORARY TABLE";
}
@ -646,7 +646,7 @@ LEFT JOIN all_cons_columns r_cols
/**
* @inheritdoc
*/
public function getTruncateTableSql($tableName, $cascade = false)
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE TABLE '.$tableName;
}

View File

@ -146,12 +146,12 @@ class PostgreSqlPlatform extends AbstractPlatform
return true;
}
public function getListDatabasesSql()
public function getListDatabasesSQL()
{
return 'SELECT datname FROM pg_database';
}
public function getListSequencesSql($database)
public function getListSequencesSQL($database)
{
return "SELECT
relname
@ -162,7 +162,7 @@ class PostgreSqlPlatform extends AbstractPlatform
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
}
public function getListTablesSql()
public function getListTablesSQL()
{
return "SELECT
c.relname AS table_name
@ -180,12 +180,12 @@ class PostgreSqlPlatform extends AbstractPlatform
AND c.relname !~ '^pg_'";
}
public function getListViewsSql($database)
public function getListViewsSQL($database)
{
return 'SELECT viewname, definition FROM pg_views';
}
public function getListTableForeignKeysSql($table, $database = null)
public function getListTableForeignKeysSQL($table, $database = null)
{
return "SELECT r.conname, pg_catalog.pg_get_constraintdef(r.oid, true) as condef
FROM pg_catalog.pg_constraint r
@ -199,17 +199,17 @@ class PostgreSqlPlatform extends AbstractPlatform
AND r.contype = 'f'";
}
public function getCreateViewSql($name, $sql)
public function getCreateViewSQL($name, $sql)
{
return 'CREATE VIEW ' . $name . ' AS ' . $sql;
}
public function getDropViewSql($name)
public function getDropViewSQL($name)
{
return 'DROP VIEW '. $name;
}
public function getListTableConstraintsSql($table)
public function getListTableConstraintsSQL($table)
{
return "SELECT
relname
@ -230,7 +230,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @param string $table
* @return string
*/
public function getListTableIndexesSql($table)
public function getListTableIndexesSQL($table)
{
return "SELECT relname, pg_index.indisunique, pg_index.indisprimary,
pg_index.indkey, pg_index.indrelid
@ -242,7 +242,7 @@ class PostgreSqlPlatform extends AbstractPlatform
) AND pg_index.indexrelid = oid";
}
public function getListTableColumnsSql($table)
public function getListTableColumnsSQL($table)
{
return "SELECT
a.attnum,
@ -277,7 +277,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @return void
* @override
*/
public function getCreateDatabaseSql($name)
public function getCreateDatabaseSQL($name)
{
return 'CREATE DATABASE ' . $name;
}
@ -289,7 +289,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @throws PDOException
* @access public
*/
public function getDropDatabaseSql($name)
public function getDropDatabaseSQL($name)
{
return 'DROP DATABASE ' . $name;
}
@ -303,13 +303,13 @@ class PostgreSqlPlatform extends AbstractPlatform
* @return string
* @override
*/
public function getAdvancedForeignKeyOptionsSql(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey)
public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey)
{
$query = '';
if ($foreignKey->hasOption('match')) {
$query .= ' MATCH ' . $foreignKey->getOption('match');
}
$query .= parent::getAdvancedForeignKeyOptionsSql($foreignKey);
$query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey);
if ($foreignKey->hasOption('deferrable') && $foreignKey->getOption('deferrable') !== false) {
$query .= ' DEFERRABLE';
} else {
@ -335,12 +335,12 @@ class PostgreSqlPlatform extends AbstractPlatform
* @return array
* @override
*/
public function getAlterTableSql(TableDiff $diff)
public function getAlterTableSQL(TableDiff $diff)
{
$sql = array();
foreach ($diff->addedColumns as $column) {
$query = 'ADD ' . $this->getColumnDeclarationSql($column->getName(), $column->toArray());
$query = 'ADD ' . $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
}
@ -361,7 +361,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
}
if ($columnDiff->hasChanged('default')) {
$query = 'ALTER ' . $oldColumnName . ' SET ' . $this->getDefaultValueDeclarationSql($column->toArray());
$query = 'ALTER ' . $oldColumnName . ' SET ' . $this->getDefaultValueDeclarationSQL($column->toArray());
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
}
if ($columnDiff->hasChanged('notnull')) {
@ -378,7 +378,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySql($diff));
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff));
return $sql;
}
@ -389,7 +389,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @return string
*/
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
{
return 'CREATE SEQUENCE ' . $sequence->getName() .
' INCREMENT BY ' . $sequence->getAllocationSize() .
@ -402,7 +402,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @return string
*/
public function getDropSequenceSql($sequence)
public function getDropSequenceSQL($sequence)
{
if ($sequence instanceof \Doctrine\DBAL\Schema\Sequence) {
$sequence = $sequence->getName();
@ -415,9 +415,9 @@ class PostgreSqlPlatform extends AbstractPlatform
* @param Table|string $table
* @return string
*/
public function getDropForeignKeySql($foreignKey, $table)
public function getDropForeignKeySQL($foreignKey, $table)
{
return $this->getDropConstraintSql($foreignKey, $table);
return $this->getDropConstraintSQL($foreignKey, $table);
}
/**
@ -428,9 +428,9 @@ class PostgreSqlPlatform extends AbstractPlatform
* @param array $options
* @return unknown
*/
protected function _getCreateTableSql($tableName, array $columns, array $options = array())
protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
{
$queryFields = $this->getColumnDeclarationListSql($columns);
$queryFields = $this->getColumnDeclarationListSQL($columns);
if (isset($options['primary']) && ! empty($options['primary'])) {
$keyColumns = array_unique(array_values($options['primary']));
@ -443,13 +443,13 @@ class PostgreSqlPlatform extends AbstractPlatform
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach ($options['indexes'] AS $index) {
$sql[] = $this->getCreateIndexSql($index, $tableName);
$sql[] = $this->getCreateIndexSQL($index, $tableName);
}
}
if (isset($options['foreignKeys'])) {
foreach ((array) $options['foreignKeys'] as $definition) {
$sql[] = $this->getCreateForeignKeySql($definition, $tableName);
$sql[] = $this->getCreateForeignKeySQL($definition, $tableName);
}
}
@ -478,21 +478,21 @@ class PostgreSqlPlatform extends AbstractPlatform
return $item;
}
public function getSequenceNextValSql($sequenceName)
public function getSequenceNextValSQL($sequenceName)
{
return "SELECT NEXTVAL('" . $sequenceName . "')";
}
public function getSetTransactionIsolationSql($level)
public function getSetTransactionIsolationSQL($level)
{
return 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL '
. $this->_getTransactionIsolationLevelSql($level);
. $this->_getTransactionIsolationLevelSQL($level);
}
/**
* @override
*/
public function getBooleanTypeDeclarationSql(array $field)
public function getBooleanTypeDeclarationSQL(array $field)
{
return 'BOOLEAN';
}
@ -500,7 +500,7 @@ class PostgreSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getIntegerTypeDeclarationSql(array $field)
public function getIntegerTypeDeclarationSQL(array $field)
{
if ( ! empty($field['autoincrement'])) {
return 'SERIAL';
@ -512,7 +512,7 @@ class PostgreSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getBigIntTypeDeclarationSql(array $field)
public function getBigIntTypeDeclarationSQL(array $field)
{
if ( ! empty($field['autoincrement'])) {
return 'BIGSERIAL';
@ -523,7 +523,7 @@ class PostgreSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getSmallIntTypeDeclarationSql(array $field)
public function getSmallIntTypeDeclarationSQL(array $field)
{
return 'SMALLINT';
}
@ -531,7 +531,7 @@ class PostgreSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{
return 'TIMESTAMP(0) WITH TIME ZONE';
}
@ -539,7 +539,7 @@ class PostgreSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getDateTypeDeclarationSql(array $fieldDeclaration)
public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{
return 'DATE';
}
@ -547,7 +547,7 @@ class PostgreSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{
return 'TIME';
}
@ -555,7 +555,7 @@ class PostgreSqlPlatform extends AbstractPlatform
/**
* @override
*/
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{
return '';
}
@ -566,7 +566,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @params array $field
* @override
*/
public function getVarcharTypeDeclarationSql(array $field)
public function getVarcharTypeDeclarationSQL(array $field)
{
if ( ! isset($field['length'])) {
if (array_key_exists('default', $field)) {
@ -584,7 +584,7 @@ class PostgreSqlPlatform extends AbstractPlatform
}
/** @override */
public function getClobTypeDeclarationSql(array $field)
public function getClobTypeDeclarationSQL(array $field)
{
return 'TEXT';
}
@ -607,7 +607,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @param string $column The column name for which to get the correct character casing.
* @return string The column name in the character casing used in SQL result sets.
*/
public function getSqlResultCasing($column)
public function getSQLResultCasing($column)
{
return strtolower($column);
}
@ -624,7 +624,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @param string $identifierColumnName
* @return string $sql
*/
public function getEmptyIdentityInsertSql($quotedTableName, $quotedIdentifierColumnName)
public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName)
{
return 'INSERT INTO ' . $quotedTableName . ' (' . $quotedIdentifierColumnName . ') VALUES (DEFAULT)';
}
@ -632,7 +632,7 @@ class PostgreSqlPlatform extends AbstractPlatform
/**
* @inheritdoc
*/
public function getTruncateTableSql($tableName, $cascade = false)
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE '.$tableName.' '.($cascade)?'CASCADE':'';
}

View File

@ -126,7 +126,7 @@ class SqlitePlatform extends AbstractPlatform
}
}
protected function _getTransactionIsolationLevelSql($level)
protected function _getTransactionIsolationLevelSQL($level)
{
switch ($level) {
case \Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED:
@ -136,13 +136,13 @@ class SqlitePlatform extends AbstractPlatform
case \Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE:
return 1;
default:
return parent::_getTransactionIsolationLevelSql($level);
return parent::_getTransactionIsolationLevelSQL($level);
}
}
public function getSetTransactionIsolationSql($level)
public function getSetTransactionIsolationSQL($level)
{
return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSql($level);
return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSQL($level);
}
/**
@ -156,7 +156,7 @@ class SqlitePlatform extends AbstractPlatform
/**
* @override
*/
public function getBooleanTypeDeclarationSql(array $field)
public function getBooleanTypeDeclarationSQL(array $field)
{
return 'BOOLEAN';
}
@ -164,17 +164,17 @@ class SqlitePlatform extends AbstractPlatform
/**
* @override
*/
public function getIntegerTypeDeclarationSql(array $field)
public function getIntegerTypeDeclarationSQL(array $field)
{
return $this->_getCommonIntegerTypeDeclarationSql($field);
return $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/**
* @override
*/
public function getBigIntTypeDeclarationSql(array $field)
public function getBigIntTypeDeclarationSQL(array $field)
{
return $this->_getCommonIntegerTypeDeclarationSql($field);
return $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/**
@ -182,15 +182,15 @@ class SqlitePlatform extends AbstractPlatform
*/
public function getTinyIntTypeDeclarationSql(array $field)
{
return $this->_getCommonIntegerTypeDeclarationSql($field);
return $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/**
* @override
*/
public function getSmallIntTypeDeclarationSql(array $field)
public function getSmallIntTypeDeclarationSQL(array $field)
{
return $this->_getCommonIntegerTypeDeclarationSql($field);
return $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/**
@ -198,13 +198,13 @@ class SqlitePlatform extends AbstractPlatform
*/
public function getMediumIntTypeDeclarationSql(array $field)
{
return $this->_getCommonIntegerTypeDeclarationSql($field);
return $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/**
* @override
*/
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{
return 'DATETIME';
}
@ -212,7 +212,7 @@ class SqlitePlatform extends AbstractPlatform
/**
* @override
*/
public function getDateTypeDeclarationSql(array $fieldDeclaration)
public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{
return 'DATE';
}
@ -220,7 +220,7 @@ class SqlitePlatform extends AbstractPlatform
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{
return 'TIME';
}
@ -228,7 +228,7 @@ class SqlitePlatform extends AbstractPlatform
/**
* @override
*/
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{
$autoinc = ! empty($columnDef['autoincrement']) ? ' AUTOINCREMENT' : '';
$pk = ! empty($columnDef['primary']) && ! empty($autoinc) ? ' PRIMARY KEY' : '';
@ -265,9 +265,9 @@ class SqlitePlatform extends AbstractPlatform
* @return void
* @override
*/
protected function _getCreateTableSql($name, array $columns, array $options = array())
protected function _getCreateTableSQL($name, array $columns, array $options = array())
{
$queryFields = $this->getColumnDeclarationListSql($columns);
$queryFields = $this->getColumnDeclarationListSQL($columns);
$autoinc = false;
foreach($columns as $field) {
@ -287,12 +287,12 @@ class SqlitePlatform extends AbstractPlatform
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach ($options['indexes'] as $index => $indexDef) {
$query[] = $this->getCreateIndexSql($indexDef, $name);
$query[] = $this->getCreateIndexSQL($indexDef, $name);
}
}
if (isset($options['unique']) && ! empty($options['unique'])) {
foreach ($options['unique'] as $index => $indexDef) {
$query[] = $this->getCreateIndexSql($indexDef, $name);
$query[] = $this->getCreateIndexSQL($indexDef, $name);
}
}
return $query;
@ -301,7 +301,7 @@ class SqlitePlatform extends AbstractPlatform
/**
* {@inheritdoc}
*/
public function getVarcharTypeDeclarationSql(array $field)
public function getVarcharTypeDeclarationSQL(array $field)
{
if ( ! isset($field['length'])) {
if (array_key_exists('default', $field)) {
@ -317,44 +317,44 @@ class SqlitePlatform extends AbstractPlatform
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
}
public function getClobTypeDeclarationSql(array $field)
public function getClobTypeDeclarationSQL(array $field)
{
return 'CLOB';
}
public function getListTableConstraintsSql($table)
public function getListTableConstraintsSQL($table)
{
return "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = '$table' AND sql NOT NULL ORDER BY name";
}
public function getListTableColumnsSql($table)
public function getListTableColumnsSQL($table)
{
return "PRAGMA table_info($table)";
}
public function getListTableIndexesSql($table)
public function getListTableIndexesSQL($table)
{
return "PRAGMA index_list($table)";
}
public function getListTablesSql()
public function getListTablesSQL()
{
return "SELECT name FROM sqlite_master WHERE type = 'table' AND name != 'sqlite_sequence' "
. "UNION ALL SELECT name FROM sqlite_temp_master "
. "WHERE type = 'table' ORDER BY name";
}
public function getListViewsSql($database)
public function getListViewsSQL($database)
{
return "SELECT name, sql FROM sqlite_master WHERE type='view' AND sql NOT NULL";
}
public function getCreateViewSql($name, $sql)
public function getCreateViewSQL($name, $sql)
{
return 'CREATE VIEW ' . $name . ' AS ' . $sql;
}
public function getDropViewSql($name)
public function getDropViewSQL($name)
{
return 'DROP VIEW '. $name;
}
@ -390,7 +390,7 @@ class SqlitePlatform extends AbstractPlatform
/**
* @inheritdoc
*/
public function getTruncateTableSql($tableName, $cascade = false)
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'DELETE FROM '.$tableName;
}

View File

@ -108,7 +108,7 @@ abstract class AbstractSchemaManager
*/
public function listDatabases()
{
$sql = $this->_platform->getListDatabasesSql();
$sql = $this->_platform->getListDatabasesSQL();
$databases = $this->_conn->fetchAll($sql);
@ -125,7 +125,7 @@ abstract class AbstractSchemaManager
if (is_null($database)) {
$database = $this->_conn->getDatabase();
}
$sql = $this->_platform->getListSequencesSql($database);
$sql = $this->_platform->getListSequencesSQL($database);
$sequences = $this->_conn->fetchAll($sql);
@ -147,7 +147,7 @@ abstract class AbstractSchemaManager
*/
public function listTableColumns($table)
{
$sql = $this->_platform->getListTableColumnsSql($table);
$sql = $this->_platform->getListTableColumnsSQL($table);
$tableColumns = $this->_conn->fetchAll($sql);
@ -164,7 +164,7 @@ abstract class AbstractSchemaManager
*/
public function listTableIndexes($table)
{
$sql = $this->_platform->getListTableIndexesSql($table);
$sql = $this->_platform->getListTableIndexesSQL($table);
$tableIndexes = $this->_conn->fetchAll($sql);
@ -178,7 +178,7 @@ abstract class AbstractSchemaManager
*/
public function listTableNames()
{
$sql = $this->_platform->getListTablesSql();
$sql = $this->_platform->getListTablesSQL();
$tables = $this->_conn->fetchAll($sql);
@ -233,7 +233,7 @@ abstract class AbstractSchemaManager
public function listViews()
{
$database = $this->_conn->getDatabase();
$sql = $this->_platform->getListViewsSql($database);
$sql = $this->_platform->getListViewsSQL($database);
$views = $this->_conn->fetchAll($sql);
return $this->_getPortableViewsList($views);
@ -250,7 +250,7 @@ abstract class AbstractSchemaManager
if (is_null($database)) {
$database = $this->_conn->getDatabase();
}
$sql = $this->_platform->getListTableForeignKeysSql($table, $database);
$sql = $this->_platform->getListTableForeignKeysSQL($table, $database);
$tableForeignKeys = $this->_conn->fetchAll($sql);
return $this->_getPortableTableForeignKeysList($tableForeignKeys);
@ -267,7 +267,7 @@ abstract class AbstractSchemaManager
*/
public function dropDatabase($database)
{
$this->_execSql($this->_platform->getDropDatabaseSql($database));
$this->_execSql($this->_platform->getDropDatabaseSQL($database));
}
/**
@ -277,7 +277,7 @@ abstract class AbstractSchemaManager
*/
public function dropTable($table)
{
$this->_execSql($this->_platform->getDropTableSql($table));
$this->_execSql($this->_platform->getDropTableSQL($table));
}
/**
@ -292,7 +292,7 @@ abstract class AbstractSchemaManager
$index = $index->getName();
}
$this->_execSql($this->_platform->getDropIndexSql($index, $table));
$this->_execSql($this->_platform->getDropIndexSQL($index, $table));
}
/**
@ -303,7 +303,7 @@ abstract class AbstractSchemaManager
*/
public function dropConstraint(Constraint $constraint, $table)
{
$this->_execSql($this->_platform->getDropConstraintSql($constraint, $table));
$this->_execSql($this->_platform->getDropConstraintSQL($constraint, $table));
}
/**
@ -315,7 +315,7 @@ abstract class AbstractSchemaManager
*/
public function dropForeignKey($foreignKey, $table)
{
$this->_execSql($this->_platform->getDropForeignKeySql($foreignKey, $table));
$this->_execSql($this->_platform->getDropForeignKeySQL($foreignKey, $table));
}
/**
@ -325,7 +325,7 @@ abstract class AbstractSchemaManager
*/
public function dropSequence($name)
{
$this->_execSql($this->_platform->getDropSequenceSql($name));
$this->_execSql($this->_platform->getDropSequenceSQL($name));
}
/**
@ -336,7 +336,7 @@ abstract class AbstractSchemaManager
*/
public function dropView($name)
{
$this->_execSql($this->_platform->getDropViewSql($name));
$this->_execSql($this->_platform->getDropViewSQL($name));
}
/* create*() Methods */
@ -348,7 +348,7 @@ abstract class AbstractSchemaManager
*/
public function createDatabase($database)
{
$this->_execSql($this->_platform->getCreateDatabaseSql($database));
$this->_execSql($this->_platform->getCreateDatabaseSQL($database));
}
/**
@ -360,7 +360,7 @@ abstract class AbstractSchemaManager
public function createTable(Table $table)
{
$createFlags = AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS;
$this->_execSql($this->_platform->getCreateTableSql($table, $createFlags));
$this->_execSql($this->_platform->getCreateTableSQL($table, $createFlags));
}
/**
@ -371,7 +371,7 @@ abstract class AbstractSchemaManager
*/
public function createSequence($sequence)
{
$this->_execSql($this->_platform->getCreateSequenceSql($sequence));
$this->_execSql($this->_platform->getCreateSequenceSQL($sequence));
}
/**
@ -382,7 +382,7 @@ abstract class AbstractSchemaManager
*/
public function createConstraint(Constraint $constraint, $table)
{
$this->_execSql($this->_platform->getCreateConstraintSql($constraint, $table));
$this->_execSql($this->_platform->getCreateConstraintSQL($constraint, $table));
}
/**
@ -393,7 +393,7 @@ abstract class AbstractSchemaManager
*/
public function createIndex(Index $index, $table)
{
$this->_execSql($this->_platform->getCreateIndexSql($index, $table));
$this->_execSql($this->_platform->getCreateIndexSQL($index, $table));
}
/**
@ -404,7 +404,7 @@ abstract class AbstractSchemaManager
*/
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
{
$this->_execSql($this->_platform->getCreateForeignKeySql($foreignKey, $table));
$this->_execSql($this->_platform->getCreateForeignKeySQL($foreignKey, $table));
}
/**
@ -414,7 +414,7 @@ abstract class AbstractSchemaManager
*/
public function createView(View $view)
{
$this->_execSql($this->_platform->getCreateViewSql($view->getName(), $view->getSql()));
$this->_execSql($this->_platform->getCreateViewSQL($view->getName(), $view->getSql()));
}
/* dropAndCreate*() Methods */
@ -511,7 +511,7 @@ abstract class AbstractSchemaManager
*/
public function alterTable(TableDiff $tableDiff)
{
$queries = $this->_platform->getAlterTableSql($tableDiff);
$queries = $this->_platform->getAlterTableSQL($tableDiff);
if (is_array($queries) && count($queries)) {
foreach ($queries AS $ddlQuery) {
$this->_execSql($ddlQuery);

View File

@ -31,7 +31,7 @@ namespace Doctrine\DBAL\Schema;
* @since 2.0
*/
class MsSqlSchemaManager extends AbstractSchemaManager
{
{
/**
* create a new database
*
@ -160,7 +160,7 @@ class MsSqlSchemaManager extends AbstractSchemaManager
case 'rename':
case 'change':
default:
throw \Doctrine\Common\DoctrineException::alterTableChangeNotSupported($changeName);
throw SchemaException::alterTableChangeNotSupported($changeName);
}
}
@ -225,7 +225,7 @@ class MsSqlSchemaManager extends AbstractSchemaManager
{
return 'DROP TABLE ' . $seqName;
}
/**
* lists all database sequences
*

View File

@ -128,42 +128,42 @@ class SchemaDiff
if ($platform->supportsForeignKeyConstraints() && $saveMode == false) {
foreach ($this->orphanedForeignKeys AS $orphanedForeignKey) {
$sql[] = $platform->getDropForeignKeySql($orphanedForeignKey, $orphanedForeignKey->getLocalTableName());
$sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTableName());
}
}
if ($platform->supportsSequences() == true) {
foreach ($this->changedSequences AS $sequence) {
$sql[] = $platform->getDropSequenceSql($sequence);
$sql[] = $platform->getCreateSequenceSql($sequence);
$sql[] = $platform->getDropSequenceSQL($sequence);
$sql[] = $platform->getCreateSequenceSQL($sequence);
}
if ($saveMode === false) {
foreach ($this->removedSequences AS $sequence) {
$sql[] = $platform->getDropSequenceSql($sequence);
$sql[] = $platform->getDropSequenceSQL($sequence);
}
}
foreach ($this->newSequences AS $sequence) {
$sql[] = $platform->getCreateSequenceSql($sequence);
$sql[] = $platform->getCreateSequenceSQL($sequence);
}
}
foreach ($this->newTables AS $table) {
$sql = array_merge(
$sql,
$platform->getCreateTableSql($table, AbstractPlatform::CREATE_FOREIGNKEYS|AbstractPlatform::CREATE_INDEXES)
$platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS|AbstractPlatform::CREATE_INDEXES)
);
}
if ($saveMode === false) {
foreach ($this->removedTables AS $table) {
$sql[] = $platform->getDropTableSql($table);
$sql[] = $platform->getDropTableSQL($table);
}
}
foreach ($this->changedTables AS $tableDiff) {
$sql = array_merge($sql, $platform->getAlterTableSql($tableDiff));
$sql = array_merge($sql, $platform->getAlterTableSQL($tableDiff));
}
return $sql;

View File

@ -119,4 +119,8 @@ class SchemaException extends \Doctrine\DBAL\DBALException
"unnamed."
);
}
static public function alterTableChangeNotSupported($changeName) {
return new self ("Alter table change not supported, given '$changeName'");
}
}

View File

@ -77,7 +77,7 @@ class CreateSchemaSqlCollector implements Visitor
public function acceptTable(Table $table)
{
$this->_createTableQueries = array_merge($this->_createTableQueries,
$this->_platform->getCreateTableSql($table)
$this->_platform->getCreateTableSQL($table)
);
}
@ -95,7 +95,7 @@ class CreateSchemaSqlCollector implements Visitor
// Append the foreign key constraints SQL
if ($this->_platform->supportsForeignKeyConstraints()) {
$this->_createFkConstraintQueries = array_merge($this->_createFkConstraintQueries,
(array) $this->_platform->getCreateForeignKeySql($fkConstraint, $localTable->getName())
(array) $this->_platform->getCreateForeignKeySQL($fkConstraint, $localTable->getName())
);
}
}
@ -115,7 +115,7 @@ class CreateSchemaSqlCollector implements Visitor
public function acceptSequence(Sequence $sequence)
{
$this->_createSequenceQueries = array_merge(
$this->_createSequenceQueries, (array)$this->_platform->getCreateSequenceSql($sequence)
$this->_createSequenceQueries, (array)$this->_platform->getCreateSequenceSQL($sequence)
);
}

View File

@ -83,7 +83,7 @@ class DropSchemaSqlCollector implements Visitor
*/
public function acceptTable(Table $table)
{
$this->_tables[] = $this->_platform->getDropTableSql($table->getName());
$this->_tables[] = $this->_platform->getDropTableSQL($table->getName());
}
/**
@ -104,7 +104,7 @@ class DropSchemaSqlCollector implements Visitor
throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint);
}
$this->_constraints[] = $this->_platform->getDropForeignKeySql($fkConstraint->getName(), $localTable->getName());
$this->_constraints[] = $this->_platform->getDropForeignKeySQL($fkConstraint->getName(), $localTable->getName());
}
/**
@ -121,7 +121,7 @@ class DropSchemaSqlCollector implements Visitor
*/
public function acceptSequence(Sequence $sequence)
{
$this->_sequences[] = $this->_platform->getDropSequenceSql($sequence->getName());
$this->_sequences[] = $this->_platform->getDropSequenceSQL($sequence->getName());
}
/**

View File

@ -11,7 +11,7 @@ class ArrayType extends Type
{
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getClobTypeDeclarationSql($fieldDeclaration);
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)

View File

@ -17,7 +17,7 @@ class BigIntType extends Type
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getBigIntTypeDeclarationSql($fieldDeclaration);
return $platform->getBigIntTypeDeclarationSQL($fieldDeclaration);
}
public function getTypeCode()

View File

@ -13,7 +13,7 @@ class BooleanType extends Type
{
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getBooleanTypeDeclarationSql($fieldDeclaration);
return $platform->getBooleanTypeDeclarationSQL($fieldDeclaration);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)

View File

@ -18,7 +18,7 @@ class DateTimeType extends Type
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getDateTimeTypeDeclarationSql($fieldDeclaration);
return $platform->getDateTimeTypeDeclarationSQL($fieldDeclaration);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)

View File

@ -18,7 +18,7 @@ class DateType extends Type
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getDateTypeDeclarationSql($fieldDeclaration);
return $platform->getDateTypeDeclarationSQL($fieldDeclaration);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)

View File

@ -16,7 +16,7 @@ class DecimalType extends Type
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getDecimalTypeDeclarationSql($fieldDeclaration);
return $platform->getDecimalTypeDeclarationSQL($fieldDeclaration);
}
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)

View File

@ -17,7 +17,7 @@ class IntegerType extends Type
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getIntegerTypeDeclarationSql($fieldDeclaration);
return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration);
}
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)

View File

@ -11,7 +11,7 @@ class ObjectType extends Type
{
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getClobTypeDeclarationSql($fieldDeclaration);
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)

View File

@ -16,7 +16,7 @@ class SmallIntType extends Type
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getSmallIntTypeDeclarationSql($fieldDeclaration);
return $platform->getSmallIntTypeDeclarationSQL($fieldDeclaration);
}
public function convertToPHPValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)

View File

@ -12,7 +12,7 @@ class StringType extends Type
/** @override */
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getVarcharTypeDeclarationSql($fieldDeclaration);
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
}
/** @override */

View File

@ -12,7 +12,7 @@ class TextType extends Type
/** @override */
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $platform->getClobTypeDeclarationSql($fieldDeclaration);
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}
public function getName()

View File

@ -21,7 +21,7 @@ class TimeType extends Type
*/
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getTimeTypeDeclarationSql($fieldDeclaration);
return $platform->getTimeTypeDeclarationSQL($fieldDeclaration);
}
/**

View File

@ -2,15 +2,14 @@
namespace Doctrine\DBAL\Types;
use Doctrine\Common\DoctrineException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform,
Doctrine\DBAL\DBALException;
/**
* The base class for so-called Doctrine mapping types.
*
*
* A Type object is obtained by calling the static {@link getType()} method.
*
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
@ -24,10 +23,10 @@ abstract class Type
const CODE_INT = 1;
const CODE_STR = 2;
const CODE_LOB = 3;
/** 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',
@ -45,10 +44,10 @@ abstract class Type
'decimal' => 'Doctrine\DBAL\Types\DecimalType',
'double' => 'Doctrine\DBAL\Types\DoubleType'
);
/* Prevent instantiation and force use of the factory method. */
private function __construct() {}
/**
* Converts a value from its PHP representation to its database representation
* of this type.
@ -74,7 +73,7 @@ abstract class Type
{
return $value;
}
/**
* Gets the default length of this type.
*
@ -84,7 +83,7 @@ abstract class Type
{
return null;
}
/**
* Gets the SQL declaration snippet for a field of this type.
*
@ -95,7 +94,7 @@ abstract class Type
/**
* Gets the name of this type.
*
*
* @return string
* @todo Needed?
*/
@ -103,14 +102,14 @@ abstract class Type
/**
* 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.
@ -126,13 +125,13 @@ abstract class Type
if ( ! isset(self::$_typesMap[$name])) {
throw DBALException::unknownColumnType($name);
}
self::$_typeObjects[$name] = new self::$_typesMap[$name]();
}
return self::$_typeObjects[$name];
}
/**
* Adds a custom type to the type map.
*
@ -147,10 +146,10 @@ abstract class Type
if (isset(self::$_typesMap[$name])) {
throw DBALException::typeExists($name);
}
self::$_typesMap[$name] = $className;
}
/**
* Checks if exists support for a type.
*
@ -162,7 +161,7 @@ abstract class Type
{
return isset(self::$_typesMap[$name]);
}
/**
* Overrides an already defined type to use a different implementation.
*
@ -176,7 +175,7 @@ abstract class Type
if ( ! isset(self::$_typesMap[$name])) {
throw DBALException::typeNotFound($name);
}
self::$_typesMap[$name] = $className;
}

View File

@ -227,7 +227,7 @@ abstract class AbstractQuery
public function setResultCacheDriver($resultCacheDriver = null)
{
if ($resultCacheDriver !== null && ! ($resultCacheDriver instanceof \Doctrine\Common\Cache\Cache)) {
throw DoctrineException::invalidResultCacheObject($resultCacheDriver);
throw ORMException::invalidResultCacheDriver();
}
$this->_resultCacheDriver = $resultCacheDriver;
if ($resultCacheDriver) {

View File

@ -1,4 +1,4 @@
<?php
<?php
/*
* $Id$
*
@ -31,14 +31,14 @@ namespace Doctrine\ORM;
* pair and add the option to the _attributes array with a proper default value.
*/
class Configuration extends \Doctrine\DBAL\Configuration
{
{
/**
* Creates a new configuration that can be used for Doctrine.
*/
public function __construct()
{
parent::__construct();
$this->_attributes = array_merge($this->_attributes, array(
'resultCacheImpl' => null,
'queryCacheImpl' => null,
@ -73,7 +73,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
{
return $this->_attributes['proxyDir'];
}
/**
* Gets a boolean flag that indicates whether proxy classes should always be regenerated
* during each script execution.
@ -84,7 +84,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
{
return $this->_attributes['autoGenerateProxyClasses'];
}
/**
* Sets a boolean flag that indicates whether proxy classes should always be regenerated
* during each script execution.
@ -95,12 +95,12 @@ class Configuration extends \Doctrine\DBAL\Configuration
{
$this->_attributes['autoGenerateProxyClasses'] = $bool;
}
public function getProxyNamespace()
{
return $this->_attributes['proxyNamespace'];
}
public function setProxyNamespace($ns)
{
$this->_attributes['proxyNamespace'] = $ns;
@ -148,7 +148,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
/**
* Set the entity alias map
*
* @param array $entityAliasMap
* @param array $entityAliasMap
* @return void
*/
public function setEntityNamespaces(array $entityNamespaces)
@ -231,32 +231,32 @@ class Configuration extends \Doctrine\DBAL\Configuration
{
$this->_attributes['metadataCacheImpl'] = $cacheImpl;
}
/**
* Gets a boolean flag that indicates whether Doctrine should make use of the
* C extension.
*
*
* @return boolean TRUE if Doctrine is configured to use the C extension, FALSE otherwise.
*/
public function getUseCExtension()
{
return $this->_attributes['useCExtension'];
}
/**
* Sets a boolean flag that indicates whether Doctrine should make use of the
* C extension.
*
*
* @param boolean $boolean Whether to make use of the C extension or not.
*/
public function setUseCExtension($boolean)
{
$this->_attributes['useCExtension'] = $boolean;
}
/**
* Adds a named DQL query to the configuration.
*
*
* @param string $name The name of the query.
* @param string $dql The DQL query string.
*/
@ -264,10 +264,10 @@ class Configuration extends \Doctrine\DBAL\Configuration
{
$this->_attributes['namedQueries'][$name] = $dql;
}
/**
* Gets a previously registered named DQL query.
*
*
* @param string $name The name of the query.
* @return string The DQL query.
*/
@ -275,22 +275,22 @@ class Configuration extends \Doctrine\DBAL\Configuration
{
return $this->_attributes['namedQueries'][$name];
}
/**
* Adds a named native query to the configuration.
*
*
* @param string $name The name of the query.
* @param string $sql The native SQL query string.
* @param string $sql The native SQL query string.
* @param ResultSetMapping $rsm The ResultSetMapping used for the results of the SQL query.
*/
public function addNamedNativeQuery($name, $sql, Query\ResultSetMapping $rsm)
{
$this->_attributes['namedNativeQueries'][$name] = array($sql, $rsm);
}
/**
* Gets the components of a previously registered named native query.
*
*
* @param string $name The name of the query.
* @return array A tuple with the first element being the SQL string and the second
* element being the ResultSetMapping.
@ -299,13 +299,13 @@ class Configuration extends \Doctrine\DBAL\Configuration
{
return $this->_attributes['namedNativeQueries'][$name];
}
/**
* Ensures that this Configuration instance contains settings that are
* suitable for a production environment.
*
* @throws DoctrineException If a configuration setting has a value that is not
* suitable for a production environment.
*
* @throws ORMException If a configuration setting has a value that is not
* suitable for a production environment.
*/
public function ensureProductionSettings()
{

View File

@ -61,7 +61,7 @@ class SequenceGenerator extends AbstractIdGenerator implements \Serializable
if ($this->_maxValue === null || $this->_nextValue == $this->_maxValue) {
// Allocate new values
$conn = $em->getConnection();
$sql = $conn->getDatabasePlatform()->getSequenceNextValSql($this->_sequenceName);
$sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);
$this->_nextValue = $conn->fetchColumn($sql);
$this->_maxValue = $this->_nextValue + $this->_allocationSize;
}

View File

@ -5,7 +5,7 @@ namespace Doctrine\ORM\Id;
use Doctrine\ORM\EntityManager;
/**
* Id generator that uses a single-row database table and a hi/lo algorithm.
* Id generator that uses a single-row database table and a hi/lo algorithm.
*
* @since 2.0
* @todo Implementation
@ -14,6 +14,6 @@ class TableGenerator extends AbstractIdGenerator
{
public function generate(EntityManager $em, $entity)
{
throw \Doctrine\Common\DoctrineException::notImplemented(__CLASS__ . '::' . __FUNCTION__);
throw new \BadMethodCallException(__CLASS__."::".__FUNCTION__." not implemented.");
}
}

View File

@ -79,19 +79,18 @@ class CommitOrderCalculator
$this->_visitNode($node);
}
}
$sorted = array_reverse($this->_sorted);
$this->_sorted =
$this->_nodeStates = array();
$this->_sorted = $this->_nodeStates = array();
return $sorted;
}
private function _visitNode($node)
{
$this->_nodeStates[$node->name] = self::IN_PROGRESS;
if (isset($this->_relatedClasses[$node->name])) {
foreach ($this->_relatedClasses[$node->name] as $relatedNode) {
if ($this->_nodeStates[$relatedNode->name] == self::NOT_VISITED) {
@ -99,7 +98,7 @@ class CommitOrderCalculator
}
}
}
$this->_nodeStates[$node->name] = self::VISITED;
$this->_sorted[] = $node;
}

View File

@ -176,15 +176,6 @@ class ClassMetadata extends ClassMetadataInfo
return array($this->identifier[0] => $this->reflFields[$this->identifier[0]]->getValue($entity));
}
}
public function getColumnValues($entity, array $columns)
{
$values = array();
foreach ($columns as $column) {
$values[] = $this->reflFields[$this->fieldNames[$column]]->getValue($entity);
}
return $values;
}
/**
* Populates the entity identifier of an entity.
@ -287,21 +278,7 @@ class ClassMetadata extends ClassMetadataInfo
$platform->quoteIdentifier($this->primaryTable['name']) :
$this->primaryTable['name'];
}
/**
* Gets the (possibly quoted) name of the discriminator column for safe use
* in an SQL statement.
*
* @param AbstractPlatform $platform
* @return string
*/
public function getQuotedDiscriminatorColumnName($platform)
{
return isset($this->discriminatorColumn['quoted']) ?
$platform->quoteIdentifier($this->discriminatorColumn['name']) :
$this->discriminatorColumn['name'];
}
/**
* Creates a string representation of this instance.
*

View File

@ -130,12 +130,13 @@ class ClassMetadataFactory
if ( ! isset($this->_loadedMetadata[$className])) {
$realClassName = $className;
// Check for namespace alias
if (strpos($className, ':') !== false) {
list($namespaceAlias, $simpleClassName) = explode(':', $className);
$realClassName = $this->_em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
if (isset($this->_loadedMetadata[$realClassName])) {
// We do not have the alias reference, include it
// We do not have the alias name in the map, include it
$this->_loadedMetadata[$className] = $this->_loadedMetadata[$realClassName];
return $this->_loadedMetadata[$realClassName];
@ -158,9 +159,8 @@ class ClassMetadataFactory
$this->_loadMetadata($realClassName);
}
// Include the alias of this situation:
// CMS:CmsUser => Doctrine\Tests\ORM\Models\CMS\CmsUser
if ($className != $realClassName) {
// We do not have the alias name in the map, include it
$this->_loadedMetadata[$className] = $this->_loadedMetadata[$realClassName];
}
}

View File

@ -42,13 +42,13 @@ require __DIR__ . '/DoctrineAnnotations.php';
*/
class AnnotationDriver implements Driver
{
/**
/**
* The AnnotationReader.
*
* @var AnnotationReader
*/
private $_reader;
/**
* The paths where to look for mapping files.
*
@ -66,7 +66,7 @@ class AnnotationDriver implements Driver
/**
* @param array
*/
protected $_classNames = null;
protected $_classNames;
/**
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
@ -93,7 +93,7 @@ class AnnotationDriver implements Driver
{
$this->_paths = array_unique(array_merge($this->_paths, $paths));
}
/**
* Retrieve the defined metadata lookup paths.
*
@ -131,7 +131,7 @@ class AnnotationDriver implements Driver
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{
$class = $metadata->getReflectionClass();
$classAnnotations = $this->_reader->getClassAnnotations($class);
// Evaluate Entity annotation
@ -151,7 +151,7 @@ class AnnotationDriver implements Driver
'name' => $tableAnnot->name,
'schema' => $tableAnnot->schema
);
if ($tableAnnot->indexes !== null) {
foreach ($tableAnnot->indexes as $indexAnnot) {
$primaryTable['indexes'][$indexAnnot->name] = array(
@ -159,7 +159,7 @@ class AnnotationDriver implements Driver
);
}
}
if ($tableAnnot->uniqueConstraints !== null) {
foreach ($tableAnnot->uniqueConstraints as $uniqueConstraint) {
$primaryTable['uniqueConstraints'][$uniqueConstraint->name] = array(
@ -167,7 +167,7 @@ class AnnotationDriver implements Driver
);
}
}
$metadata->setPrimaryTable($primaryTable);
}
@ -214,7 +214,7 @@ class AnnotationDriver implements Driver
// Check for JoinColummn/JoinColumns annotations
$joinColumns = array();
if ($joinColumnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) {
$joinColumns[] = array(
'name' => $joinColumnAnnot->name,
@ -245,7 +245,7 @@ class AnnotationDriver implements Driver
if ($columnAnnot->type == null) {
throw MappingException::propertyTypeIsRequired($className, $property->getName());
}
$mapping['type'] = $columnAnnot->type;
$mapping['length'] = $columnAnnot->length;
$mapping['precision'] = $columnAnnot->precision;
@ -255,27 +255,27 @@ class AnnotationDriver implements Driver
if ($columnAnnot->options) {
$mapping['options'] = $columnAnnot->options;
}
if (isset($columnAnnot->name)) {
$mapping['columnName'] = $columnAnnot->name;
}
if (isset($columnAnnot->columnDefinition)) {
$mapping['columnDefinition'] = $columnAnnot->columnDefinition;
}
if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
$mapping['id'] = true;
}
if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\GeneratedValue')) {
$metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
}
if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Version')) {
$metadata->setVersionMapping($mapping);
}
$metadata->mapField($mapping);
// Check for SequenceGenerator/TableGenerator definition
@ -316,13 +316,13 @@ class AnnotationDriver implements Driver
$metadata->mapManyToOne($mapping);
} else if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) {
$joinTable = array();
if ($joinTableAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinTable')) {
$joinTable = array(
'name' => $joinTableAnnot->name,
'schema' => $joinTableAnnot->schema
);
foreach ($joinTableAnnot->joinColumns as $joinColumn) {
$joinTable['joinColumns'][] = array(
'name' => $joinColumn->name,
@ -347,7 +347,7 @@ class AnnotationDriver implements Driver
);
}
}
$mapping['joinTable'] = $joinTable;
$mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
$mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
@ -361,37 +361,37 @@ class AnnotationDriver implements Driver
$metadata->mapManyToMany($mapping);
}
}
// Evaluate HasLifecycleCallbacks annotation
if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
foreach ($class->getMethods() as $method) {
if ($method->isPublic()) {
$annotations = $this->_reader->getMethodAnnotations($method);
if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::prePersist);
}
if (isset($annotations['Doctrine\ORM\Mapping\PostPersist'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postPersist);
}
if (isset($annotations['Doctrine\ORM\Mapping\PreUpdate'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preUpdate);
}
if (isset($annotations['Doctrine\ORM\Mapping\PostUpdate'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postUpdate);
}
if (isset($annotations['Doctrine\ORM\Mapping\PreRemove'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preRemove);
}
if (isset($annotations['Doctrine\ORM\Mapping\PostRemove'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postRemove);
}
if (isset($annotations['Doctrine\ORM\Mapping\PostLoad'])) {
$metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postLoad);
}
@ -412,11 +412,11 @@ class AnnotationDriver implements Driver
public function isTransient($className)
{
$classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className));
return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) &&
! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']);
}
/**
* {@inheritDoc}
*/
@ -427,32 +427,32 @@ class AnnotationDriver implements Driver
}
$classes = array();
if ($this->_paths) {
$declared = get_declared_classes();
foreach ((array) $this->_paths as $path) {
if ( ! is_dir($path)) {
throw MappingException::annotationDriverRequiresConfiguredDirectoryPath();
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath();
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path),
\RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($iterator as $file) {
if (($fileName = $file->getBasename($this->_fileExtension)) == $file->getBasename()) {
continue;
}
require_once $file->getPathName();
}
}
$declared = array_diff(get_declared_classes(), $declared);
foreach ($declared as $className) {
foreach ($declared as $className) {
if ( ! $this->isTransient($className)) {
$classes[] = $className;
}
@ -460,8 +460,8 @@ class AnnotationDriver implements Driver
}
$this->_classNames = $classes;
return $classes;
}
}

View File

@ -126,27 +126,19 @@ class ManyToManyMapping extends AssociationMapping
);
}
foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) {
if ($joinColumn['name'][0] == '`') {
$joinColumn['name'] = trim($joinColumn['name'], '`');
$joinColumn['quoted'] = true;
}
foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
$this->relationToSourceKeyColumns[$joinColumn['name']] = $joinColumn['referencedColumnName'];
$this->joinTableColumns[] = $joinColumn['name'];
}
foreach ($mapping['joinTable']['inverseJoinColumns'] as &$inverseJoinColumn) {
if ($inverseJoinColumn['name'][0] == '`') {
$inverseJoinColumn['name'] = trim($inverseJoinColumn['name'], '`');
$inverseJoinColumn['quoted'] = true;
}
foreach ($mapping['joinTable']['inverseJoinColumns'] as $inverseJoinColumn) {
$this->relationToTargetKeyColumns[$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName'];
$this->joinTableColumns[] = $inverseJoinColumn['name'];
}
}
if (isset($mapping['orderBy'])) {
if (!is_array($mapping['orderBy'])) {
if ( ! is_array($mapping['orderBy'])) {
throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
}
$this->orderBy = $mapping['orderBy'];
@ -212,26 +204,8 @@ class ManyToManyMapping extends AssociationMapping
$persister->loadManyToManyCollection($this, $joinTableConditions, $targetCollection);
}
/**
* {@inheritdoc}
*/
public function isManyToMany()
{
return true;
}
/**
* Gets the (possibly quoted) column name of a join column that is safe to use
* in an SQL statement.
*
* @param string $joinColumn
* @param AbstractPlatform $platform
* @return string
*/
public function getQuotedJoinColumnName($joinColumn, $platform)
{
return isset($this->joinTable['joinColumns'][$joinColumn]['quoted']) ?
$platform->quoteIdentifier($joinColumn) :
$joinColumn;
}
}

View File

@ -166,9 +166,9 @@ class MappingException extends \Doctrine\ORM\ORMException
);
}
public static function annotationDriverRequiresConfiguredDirectoryPath()
public static function fileMappingDriversRequireConfiguredDirectoryPath()
{
return new self('The annotation driver needs to have a directory path');
return new self('File mapping drivers must have a directory path');
}
/**

View File

@ -54,7 +54,7 @@ class OneToManyMapping extends AssociationMapping
/**
* Order this collection by the given SQL snippet.
*/
public $orderBy = null;
public $orderBy;
/**
* Initializes a new OneToManyMapping.

View File

@ -119,11 +119,7 @@ class OneToOneMapping extends AssociationMapping
'referencedColumnName' => 'id'
));
}
foreach ($mapping['joinColumns'] as &$joinColumn) {
if ($joinColumn['name'][0] == '`') {
$joinColumn['name'] = trim($joinColumn['name'], '`');
$joinColumn['quoted'] = true;
}
foreach ($mapping['joinColumns'] as $joinColumn) {
$this->sourceToTargetKeyColumns[$joinColumn['name']] = $joinColumn['referencedColumnName'];
$this->joinColumnFieldNames[$joinColumn['name']] = isset($joinColumn['fieldName'])
? $joinColumn['fieldName'] : $joinColumn['name'];
@ -194,22 +190,7 @@ class OneToOneMapping extends AssociationMapping
{
return true;
}
/**
* Gets the (possibly quoted) column name of a join column that is safe to use
* in an SQL statement.
*
* @param string $joinColumn
* @param AbstractPlatform $platform
* @return string
*/
public function getQuotedJoinColumnName($joinColumn, $platform)
{
return isset($this->joinColumns[$joinColumn]['quoted']) ?
$platform->quoteIdentifier($joinColumn) :
$joinColumn;
}
/**
* {@inheritdoc}
*

View File

@ -70,6 +70,14 @@ class ORMException extends \Exception
);
}
public static function invalidResultCacheDriver() {
return new self("Invalid result cache driver; it must implement \Doctrine\Common\Cache\Cache.");
}
public static function notSupported() {
return new self("This behaviour is (currently) not supported by Doctrine 2");
}
public static function queryCacheNotConfigured()
{
return new self('Query Cache is not configured.');

View File

@ -103,6 +103,7 @@ class JoinedSubclassPersister extends StandardEntityPersister
$this->_owningTableMap[$fieldName] = $this->_class->primaryTable['name'];
}
}
return $this->_owningTableMap[$fieldName];
}
@ -130,18 +131,18 @@ class JoinedSubclassPersister extends StandardEntityPersister
$this->_class : $this->_em->getClassMetadata($this->_class->rootEntityName);
$rootPersister = $this->_em->getUnitOfWork()->getEntityPersister($rootClass->name);
$rootTableName = $rootClass->primaryTable['name'];
$rootTableStmt = $this->_conn->prepare($rootPersister->getInsertSql());
$rootTableStmt = $this->_conn->prepare($rootPersister->getInsertSQL());
if ($this->_sqlLogger !== null) {
$sql = array();
$sql[$rootTableName] = $rootPersister->getInsertSql();
$sql[$rootTableName] = $rootPersister->getInsertSQL();
}
// Prepare statements for sub tables.
$subTableStmts = array();
if ($rootClass !== $this->_class) {
$subTableStmts[$this->_class->primaryTable['name']] = $this->_conn->prepare($this->getInsertSql());
$subTableStmts[$this->_class->primaryTable['name']] = $this->_conn->prepare($this->getInsertSQL());
if ($this->_sqlLogger !== null) {
$sql[$this->_class->primaryTable['name']] = $this->getInsertSql();
$sql[$this->_class->primaryTable['name']] = $this->getInsertSQL();
}
}
foreach ($this->_class->parentClasses as $parentClassName) {
@ -149,9 +150,9 @@ class JoinedSubclassPersister extends StandardEntityPersister
$parentTableName = $parentClass->primaryTable['name'];
if ($parentClass !== $rootClass) {
$parentPersister = $this->_em->getUnitOfWork()->getEntityPersister($parentClassName);
$subTableStmts[$parentTableName] = $this->_conn->prepare($parentPersister->getInsertSql());
$subTableStmts[$parentTableName] = $this->_conn->prepare($parentPersister->getInsertSQL());
if ($this->_sqlLogger !== null) {
$sql[$parentTableName] = $parentPersister->getInsertSql();
$sql[$parentTableName] = $parentPersister->getInsertSQL();
}
}
}
@ -299,65 +300,55 @@ class JoinedSubclassPersister extends StandardEntityPersister
* @return string
* @override
*/
protected function _getSelectEntitiesSql(array &$criteria, $assoc = null, $orderBy = null)
protected function _getSelectEntitiesSQL(array &$criteria, $assoc = null, $orderBy = null)
{
$tableAliases = array();
$aliasIndex = 1;
$idColumns = $this->_class->getIdentifierColumnNames();
$baseTableAlias = 't0';
$setResultColumnNames = empty($this->_resultColumnNames);
foreach (array_merge($this->_class->subClasses, $this->_class->parentClasses) as $className) {
$tableAliases[$className] = 't' . $aliasIndex++;
}
$baseTableAlias = $this->_getSQLTableAlias($this->_class);
// Add regular columns
$columnList = '';
foreach ($this->_class->fieldMappings as $fieldName => $mapping) {
$tableAlias = isset($mapping['inherited']) ?
$tableAliases[$mapping['inherited']] : $baseTableAlias;
if ($columnList != '') $columnList .= ', ';
$columnList .= $tableAlias . '.' . $this->_class->getQuotedColumnName($fieldName, $this->_platform);
if ($setResultColumnNames) {
$resultColumnName = $this->_platform->getSqlResultCasing($mapping['columnName']);
$this->_resultColumnNames[$resultColumnName] = $mapping['columnName'];
if ($this->_selectColumnListSql === null) {
// Add regular columns
$columnList = '';
foreach ($this->_class->fieldMappings as $fieldName => $mapping) {
if ($columnList != '') $columnList .= ', ';
$columnList .= $this->_getSelectColumnSQL($fieldName,
isset($mapping['inherited']) ? $this->_em->getClassMetadata($mapping['inherited']) : $this->_class);
}
}
// Add foreign key columns
foreach ($this->_class->associationMappings as $assoc2) {
if ($assoc2->isOwningSide && $assoc2->isOneToOne()) {
foreach ($assoc2->targetToSourceKeyColumns as $srcColumn) {
$columnList .= ', ' . $assoc2->getQuotedJoinColumnName($srcColumn, $this->_platform);
if ($setResultColumnNames) {
$resultColumnName = $this->_platform->getSqlResultCasing($srcColumn);
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
// Add foreign key columns
foreach ($this->_class->associationMappings as $assoc) {
if ($assoc->isOwningSide && $assoc->isOneToOne()) {
$tableAlias = isset($this->_class->inheritedAssociationFields[$assoc->sourceFieldName]) ?
$this->_getSQLTableAlias($this->_em->getClassMetadata($this->_class->inheritedAssociationFields[$assoc->sourceFieldName]))
: $baseTableAlias;
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
$columnAlias = $srcColumn . $this->_sqlAliasCounter++;
$columnList .= ", $tableAlias.$srcColumn AS $columnAlias";
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
}
}
}
}
}
// Add discriminator column
if ($this->_class->rootEntityName == $this->_class->name) {
$columnList .= ', ' . $baseTableAlias . '.' .
$this->_class->getQuotedDiscriminatorColumnName($this->_platform);
} else {
$columnList .= ', ' . $tableAliases[$this->_class->rootEntityName] . '.' .
$this->_class->getQuotedDiscriminatorColumnName($this->_platform);
}
if ($setResultColumnNames) {
$resultColumnName = $this->_platform->getSqlResultCasing($this->_class->discriminatorColumn['name']);
$this->_resultColumnNames[$resultColumnName] = $this->_class->discriminatorColumn['name'];
// Add discriminator column (DO NOT ALIAS THIS COLUMN).
$discrColumn = $this->_class->discriminatorColumn['name'];
if ($this->_class->rootEntityName == $this->_class->name) {
$columnList .= ", $baseTableAlias.$discrColumn";
} else {
$columnList .= ', ' . $this->_getSQLTableAlias($this->_em->getClassMetadata($this->_class->rootEntityName))
. ".$discrColumn";
}
$resultColumnName = $this->_platform->getSQLResultCasing($discrColumn);
$this->_resultColumnNames[$resultColumnName] = $discrColumn;
}
// INNER JOIN parent tables
$joinSql = '';
foreach ($this->_class->parentClasses as $parentClassName) {
$parentClass = $this->_em->getClassMetadata($parentClassName);
$tableAlias = $tableAliases[$parentClassName];
$tableAlias = $this->_getSQLTableAlias($parentClass);
$joinSql .= ' INNER JOIN ' . $parentClass->getQuotedTableName($this->_platform) . ' ' . $tableAlias . ' ON ';
$first = true;
foreach ($idColumns as $idColumn) {
@ -369,35 +360,32 @@ class JoinedSubclassPersister extends StandardEntityPersister
// OUTER JOIN sub tables
foreach ($this->_class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName);
$tableAlias = $tableAliases[$subClassName];
$tableAlias = $this->_getSQLTableAlias($subClass);
// Add subclass columns
foreach ($subClass->fieldMappings as $fieldName => $mapping) {
if (isset($mapping['inherited'])) {
continue;
if ($this->_selectColumnListSql === null) {
// Add subclass columns
foreach ($subClass->fieldMappings as $fieldName => $mapping) {
if (isset($mapping['inherited'])) {
continue;
}
$columnList .= ', ' . $this->_getSelectColumnSQL($fieldName, $subClass);
}
$columnList .= ', ' . $tableAlias . '.' . $subClass->getQuotedColumnName($fieldName, $this->_platform);
if ($setResultColumnNames) {
$resultColumnName = $this->_platform->getSqlResultCasing($mapping['columnName']);
$this->_resultColumnNames[$resultColumnName] = $mapping['columnName'];
}
}
// Add join columns (foreign keys)
foreach ($subClass->associationMappings as $assoc2) {
if ($assoc2->isOwningSide && $assoc2->isOneToOne() && ! isset($subClass->inheritedAssociationFields[$assoc2->sourceFieldName])) {
foreach ($assoc2->targetToSourceKeyColumns as $srcColumn) {
$columnList .= ', ' . $tableAlias . '.' . $assoc2->getQuotedJoinColumnName($srcColumn, $this->_platform);
if ($setResultColumnNames) {
$resultColumnName = $this->_platform->getSqlResultCasing($srcColumn);
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
// Add join columns (foreign keys)
foreach ($subClass->associationMappings as $assoc2) {
if ($assoc2->isOwningSide && $assoc2->isOneToOne() && ! isset($subClass->inheritedAssociationFields[$assoc2->sourceFieldName])) {
foreach ($assoc2->targetToSourceKeyColumns as $srcColumn) {
$columnAlias = $srcColumn . $this->_sqlAliasCounter++;
$columnList .= ', ' . $tableAlias . ".$srcColumn AS $columnAlias";
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
}
}
}
}
}
// Add LEFT JOIN
$joinSql .= ' LEFT JOIN ' . $subClass->getQuotedTableName($this->_platform) . ' ' . $tableAlias . ' ON ';
$first = true;
@ -414,7 +402,7 @@ class JoinedSubclassPersister extends StandardEntityPersister
if (isset($this->_class->columnNames[$field])) {
$conditionSql .= $this->_class->getQuotedColumnName($field, $this->_platform);
} else if ($assoc !== null) {
$conditionSql .= $assoc->getQuotedJoinColumnName($field, $this->_platform);
$conditionSql .= $field;
} else {
throw ORMException::unrecognizedField($field);
}
@ -423,19 +411,29 @@ class JoinedSubclassPersister extends StandardEntityPersister
$orderBySql = '';
if ($orderBy !== null) {
$orderBySql = $this->_getCollectionOrderBySql($orderBy, $baseTableAlias, $tableAliases);
$orderBySql = $this->_getCollectionOrderBySQL($orderBy, $baseTableAlias);
}
return 'SELECT ' . $columnList
if ($this->_selectColumnListSql === null) {
$this->_selectColumnListSql = $columnList;
}
return 'SELECT ' . $this->_selectColumnListSql
. ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $baseTableAlias
. $joinSql
. ($conditionSql != '' ? ' WHERE ' . $conditionSql : '') . $orderBySql;
}
/** @override */
protected function _processSqlResult(array $sqlResult)
/** Ensure this is never called. This persister overrides _getSelectEntitiesSQL directly. */
protected function _getSelectColumnListSQL()
{
return $this->_processSqlResultInheritanceAware($sqlResult);
throw new \BadMethodCallException("Illegal invocation of ".__METHOD__." on JoinedSubclassPersister.");
}
/** @override */
protected function _processSQLResult(array $sqlResult)
{
return $this->_processSQLResultInheritanceAware($sqlResult);
}
/** @override */
@ -455,7 +453,7 @@ class JoinedSubclassPersister extends StandardEntityPersister
$assoc = $this->_class->associationMappings[$name];
if ($assoc->isOneToOne() && $assoc->isOwningSide) {
foreach ($assoc->targetToSourceKeyColumns as $sourceCol) {
$columns[] = $assoc->getQuotedJoinColumnName($sourceCol, $this->_platform);
$columns[] = $sourceCol;
}
}
} else if ($this->_class->name != $this->_class->rootEntityName ||
@ -466,7 +464,7 @@ class JoinedSubclassPersister extends StandardEntityPersister
// Add discriminator column if it is the topmost class.
if ($this->_class->name == $this->_class->rootEntityName) {
$columns[] = $this->_class->getQuotedDiscriminatorColumnName($this->_platform);
$columns[] = $this->_class->discriminatorColumn['name'];
}
return $columns;

View File

@ -21,7 +21,7 @@
namespace Doctrine\ORM\Persisters;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Mapping\ClassMetadata;
/**
* Persister for entities that participate in a hierarchy mapped with the
@ -41,46 +41,41 @@ class SingleTablePersister extends StandardEntityPersister
parent::_prepareData($entity, $result, $isInsert);
// Populate the discriminator column
if ($isInsert) {
$discColumn = $this->_class->getQuotedDiscriminatorColumnName($this->_platform);
$discColumn = $this->_class->discriminatorColumn['name'];
$result[$this->_class->getQuotedTableName($this->_platform)][$discColumn] =
$this->_class->discriminatorValue;
}
}
/** @override */
protected function _getSelectColumnList()
protected function _getSelectColumnListSQL()
{
$setResultColumnNames = empty($this->_resultColumnNames);
$columnList = parent::_getSelectColumnList();
$columnList = parent::_getSelectColumnListSQL();
// Append discriminator column
$columnList .= ', ' . $this->_class->getQuotedDiscriminatorColumnName($this->_platform);
if ($setResultColumnNames) {
$resultColumnName = $this->_platform->getSqlResultCasing($this->_class->discriminatorColumn['name']);
$this->_resultColumnNames[$resultColumnName] = $this->_class->discriminatorColumn['name'];
}
///$tableAlias = $this->_class->getQuotedTableName($this->_platform);
$discrColumn = $this->_class->discriminatorColumn['name'];
$columnList .= ", $discrColumn";
$rootClass = $this->_em->getClassMetadata($this->_class->rootEntityName);
$tableAlias = $this->_getSQLTableAlias($rootClass);
$resultColumnName = $this->_platform->getSQLResultCasing($discrColumn);
$this->_resultColumnNames[$resultColumnName] = $discrColumn;
foreach ($this->_class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName);
// Append subclass columns
foreach ($subClass->fieldMappings as $fieldName => $mapping) {
if ( ! isset($mapping['inherited'])) {
$columnList .= ', ' . $subClass->getQuotedColumnName($fieldName, $this->_platform);
if ($setResultColumnNames) {
$resultColumnName = $this->_platform->getSqlResultCasing($mapping['columnName']);
$this->_resultColumnNames[$resultColumnName] = $mapping['columnName'];
}
$columnList .= ', ' . $this->_getSelectColumnSQL($fieldName, $subClass);
}
}
// Append subclass foreign keys
foreach ($subClass->associationMappings as $assoc) {
if ($assoc->isOwningSide && $assoc->isOneToOne() && ! isset($subClass->inheritedAssociationFields[$assoc->sourceFieldName])) {
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
$columnList .= ', ' /*. $tableAlias . '.'*/ . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform);
if ($setResultColumnNames) {
$resultColumnName = $this->_platform->getSqlResultCasing($srcColumn);
$columnAlias = $srcColumn . $this->_sqlAliasCounter++;
$columnList .= ', ' . $tableAlias . ".$srcColumn AS $columnAlias";
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
}
}
@ -90,20 +85,32 @@ class SingleTablePersister extends StandardEntityPersister
return $columnList;
}
/** @override */
protected function _getInsertColumnList()
{
$columns = parent::_getInsertColumnList();
// Add discriminator column to the INSERT SQL
$columns[] = $this->_class->getQuotedDiscriminatorColumnName($this->_platform);
$columns[] = $this->_class->discriminatorColumn['name'];
return $columns;
}
/** @override */
protected function _processSqlResult(array $sqlResult)
protected function _processSQLResult(array $sqlResult)
{
return $this->_processSqlResultInheritanceAware($sqlResult);
return $this->_processSQLResultInheritanceAware($sqlResult);
}
/** @override */
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++;
$this->_sqlTableAliases[$class->rootEntityName] = $tableAlias;
return $tableAlias;
}
}

View File

@ -86,7 +86,7 @@ class StandardEntityPersister
* @var array
*/
protected $_queuedInserts = array();
/**
* Mappings of column names as they appear in an SQL result set to
* column names as they are defined in the mapping.
@ -94,7 +94,7 @@ class StandardEntityPersister
* @var array
*/
protected $_resultColumnNames = array();
/**
* The INSERT SQL statement used for entities handled by this persister.
*
@ -102,6 +102,34 @@ class StandardEntityPersister
*/
private $_insertSql;
/**
* The SELECT column list SQL fragment used for querying entities by this persister.
*
* @var string
*/
protected $_selectColumnListSql;
/**
* Map from column names to class names that declare the field the column is mapped to.
*
* @var array
*/
protected $_declaringClassMap = array();
/**
* Counter for creating unique SQL table and column aliases.
*
* @var integer
*/
protected $_sqlAliasCounter = 0;
/**
* Map from class names to the corresponding generated SQL table aliases.
*
* @var array
*/
protected $_sqlTableAliases = array();
/**
* Initializes a new <tt>StandardEntityPersister</tt> that uses the given EntityManager
* and persists instances of the class described by the given class metadata descriptor.
@ -146,7 +174,7 @@ class StandardEntityPersister
$idGen = $this->_class->idGenerator;
$isPostInsertId = $idGen->isPostInsertGenerator();
$stmt = $this->_conn->prepare($this->getInsertSql());
$stmt = $this->_conn->prepare($this->getInsertSQL());
$primaryTableName = $this->_class->primaryTable['name'];
foreach ($this->_queuedInserts as $entity) {
@ -161,14 +189,14 @@ class StandardEntityPersister
$params[$paramIndex] = $value;
$stmt->bindValue($paramIndex++, $value);
}
$this->_sqlLogger->logSql($this->getInsertSql(), $params);
$this->_sqlLogger->logSql($this->getInsertSQL(), $params);
} else {
foreach ($insertData[$primaryTableName] as $value) {
$stmt->bindValue($paramIndex++, $value);
}
}
} else if ($this->_sqlLogger !== null) {
$this->_sqlLogger->logSql($this->getInsertSql());
$this->_sqlLogger->logSql($this->getInsertSQL());
}
$stmt->execute();
@ -243,7 +271,6 @@ class StandardEntityPersister
protected function _doUpdate($entity, $tableName, $data, $where)
{
// Note: $tableName and column names in $data are already quoted for SQL.
$set = array();
foreach ($data as $columnName => $value) {
$set[] = $columnName . ' = ?';
@ -364,11 +391,10 @@ class StandardEntityPersister
$owningTable = $this->getOwningTable($field);
foreach ($assocMapping->sourceToTargetKeyColumns as $sourceColumn => $targetColumn) {
$quotedSourceColumn = $assocMapping->getQuotedJoinColumnName($sourceColumn, $this->_platform);
if ($newVal === null) {
$result[$owningTable][$quotedSourceColumn] = null;
$result[$owningTable][$sourceColumn] = null;
} else {
$result[$owningTable][$quotedSourceColumn] = $newValId[$targetClass->fieldNames[$targetColumn]];
$result[$owningTable][$sourceColumn] = $newValId[$targetClass->fieldNames[$targetColumn]];
}
}
} else if ($newVal === null) {
@ -406,13 +432,13 @@ class StandardEntityPersister
*/
public function load(array $criteria, $entity = null, $assoc = null, array $hints = array())
{
$sql = $this->_getSelectEntitiesSql($criteria, $assoc);
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc);
$params = array_values($criteria);
if ($this->_sqlLogger !== null) {
$this->_sqlLogger->logSql($sql, $params);
}
$stmt = $this->_conn->prepare($sql);
$stmt->execute($params);
$result = $stmt->fetch(Connection::FETCH_ASSOC);
@ -429,7 +455,7 @@ class StandardEntityPersister
*/
final public function refresh(array $id, $entity)
{
$sql = $this->_getSelectEntitiesSql($id);
$sql = $this->_getSelectEntitiesSQL($id);
$params = array_values($id);
if ($this->_sqlLogger !== null) {
@ -446,7 +472,7 @@ class StandardEntityPersister
// Refresh simple state
foreach ($result as $column => $value) {
$column = isset($this->_resultColumnNames[$column]) ? $this->_resultColumnNames[$column] : $column;
$column = $this->_resultColumnNames[$column];
if (isset($this->_class->fieldNames[$column])) {
$fieldName = $this->_class->fieldNames[$column];
$type = Type::getType($this->_class->fieldMappings[$fieldName]['type']);
@ -519,7 +545,7 @@ class StandardEntityPersister
{
$entities = array();
$sql = $this->_getSelectEntitiesSql($criteria);
$sql = $this->_getSelectEntitiesSQL($criteria);
$params = array_values($criteria);
if ($this->_sqlLogger !== null) {
@ -549,7 +575,7 @@ class StandardEntityPersister
{
$owningAssoc = $this->_class->associationMappings[$coll->getMapping()->mappedByFieldName];
$sql = $this->_getSelectEntitiesSql($criteria, $owningAssoc, $assoc->orderBy);
$sql = $this->_getSelectEntitiesSQL($criteria, $owningAssoc, $assoc->orderBy);
$params = array_values($criteria);
@ -574,7 +600,7 @@ class StandardEntityPersister
*/
public function loadManyToManyCollection($assoc, array $criteria, PersistentCollection $coll)
{
$sql = $this->_getSelectManyToManyEntityCollectionSql($assoc, $criteria);
$sql = $this->_getSelectManyToManyEntityCollectionSQL($assoc, $criteria);
$params = array_values($criteria);
if ($this->_sqlLogger !== null) {
@ -629,11 +655,11 @@ class StandardEntityPersister
* @return array A tuple where the first value is the actual type of the entity and
* the second value the data of the entity.
*/
protected function _processSqlResult(array $sqlResult)
protected function _processSQLResult(array $sqlResult)
{
$data = array();
foreach ($sqlResult as $column => $value) {
$column = isset($this->_resultColumnNames[$column]) ? $this->_resultColumnNames[$column] : $column;
$column = $this->_resultColumnNames[$column];
if (isset($this->_class->fieldNames[$column])) {
$field = $this->_class->fieldNames[$column];
$data[$field] = Type::getType($this->_class->fieldMappings[$field]['type'])
@ -642,7 +668,7 @@ class StandardEntityPersister
$data[$column] = $value;
}
}
return array($this->_class->name, $data);
}
@ -654,7 +680,7 @@ class StandardEntityPersister
* @param string $orderBy
* @return string
*/
protected function _getSelectEntitiesSql(array &$criteria, $assoc = null, $orderBy = null)
protected function _getSelectEntitiesSQL(array &$criteria, $assoc = null, $orderBy = null)
{
// Construct WHERE conditions
$conditionSql = '';
@ -668,7 +694,7 @@ class StandardEntityPersister
} else if (isset($this->_class->fieldNames[$field])) {
$conditionSql .= $this->_class->getQuotedColumnName($this->_class->fieldNames[$field], $this->_platform);
} else if ($assoc !== null) {
$conditionSql .= $assoc->getQuotedJoinColumnName($field, $this->_platform);
$conditionSql .= $field;
} else {
throw ORMException::unrecognizedField($field);
}
@ -677,13 +703,14 @@ class StandardEntityPersister
$orderBySql = '';
if ($orderBy !== null) {
$orderBySql = $this->_getCollectionOrderBySql(
$orderBy, $this->_class->getQuotedTableName($this->_platform)
$orderBySql = $this->_getCollectionOrderBySQL(
$orderBy, $this->_getSQLTableAlias($this->_class)
);
}
return 'SELECT ' . $this->_getSelectColumnList()
. ' FROM ' . $this->_class->getQuotedTableName($this->_platform)
return 'SELECT ' . $this->_getSelectColumnListSQL()
. ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' '
. $this->_getSQLTableAlias($this->_class)
. ($conditionSql ? ' WHERE ' . $conditionSql : '') . $orderBySql;
}
@ -693,65 +720,53 @@ class StandardEntityPersister
* @param array $orderBy
* @return string
*/
protected function _getCollectionOrderBySql(array $orderBy, $baseTableAlias, $tableAliases = array())
protected function _getCollectionOrderBySQL(array $orderBy, $baseTableAlias)
{
$orderBySql = '';
foreach ($orderBy AS $fieldName => $orientation) {
if (!isset($this->_class->fieldMappings[$fieldName])) {
foreach ($orderBy as $fieldName => $orientation) {
if ( ! isset($this->_class->fieldMappings[$fieldName])) {
ORMException::unrecognizedField($fieldName);
}
$tableAlias = isset($this->_class->fieldMappings['inherited']) ?
$tableAliases[$this->_class->fieldMappings['inherited']] : $baseTableAlias;
$tableAlias = isset($this->_class->fieldMappings[$fieldName]['inherited']) ?
$this->_getSQLTableAlias($this->_em->getClassMetadata($this->_class->fieldMappings[$fieldName]['inherited']))
: $baseTableAlias;
$columnName = $this->_class->getQuotedColumnName($fieldName, $this->_platform);
if ($orderBySql != '') {
$orderBySql .= ', ';
} else {
$orderBySql = ' ORDER BY ';
}
$orderBySql .= $tableAlias . '.' . $columnName . ' '.$orientation;
$orderBySql .= $tableAlias . '.' . $columnName . ' ' . $orientation;
}
return $orderBySql;
}
/**
* Gets the SQL fragment with the list of columns to select when querying for
* a entity of the type of this persister.
* an entity within this persister.
*
* @return string The SQL fragment.
* @todo Rename: _getSelectColumnListSQL()
*/
protected function _getSelectColumnList()
protected function _getSelectColumnListSQL()
{
if ($this->_selectColumnListSql !== null) {
return $this->_selectColumnListSql;
}
$columnList = '';
$tableName = $this->_class->getQuotedTableName($this->_platform);
$setResultColumnNames = empty($this->_resultColumnNames);
// Add regular columns to select list
foreach ($this->_class->fieldNames as $field) {
if ($columnList != '') $columnList .= ', ';
$columnList .= $tableName . '.' . $this->_class->getQuotedColumnName($field, $this->_platform);
if ($setResultColumnNames) {
$resultColumnName = $this->_platform->getSqlResultCasing($this->_class->columnNames[$field]);
$this->_resultColumnNames[$resultColumnName] = $this->_class->columnNames[$field];
}
$columnList .= $this->_getSelectColumnSQL($field, $this->_class);
}
// Add join columns (foreign keys) to select list
foreach ($this->_class->associationMappings as $assoc) {
if ($assoc->isOwningSide && $assoc->isOneToOne()) {
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
$columnList .= ', ' . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform);
if ($setResultColumnNames) {
$resultColumnName = $this->_platform->getSqlResultCasing($srcColumn);
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
}
}
}
}
return $columnList;
$this->_selectColumnListSql = $columnList . $this->_getSelectJoinColumnsSQL($this->_class);
return $this->_selectColumnListSql;
}
/**
@ -761,7 +776,7 @@ class StandardEntityPersister
* @param array $criteria
* @return string
*/
protected function _getSelectManyToManyEntityCollectionSql($manyToMany, array &$criteria)
protected function _getSelectManyToManyEntityCollectionSQL($manyToMany, array &$criteria)
{
if ($manyToMany->isOwningSide) {
$owningAssoc = $manyToMany;
@ -776,50 +791,50 @@ class StandardEntityPersister
$joinSql = '';
foreach ($joinClauses as $joinTableColumn => $sourceColumn) {
if ($joinSql != '') $joinSql .= ' AND ';
$joinSql .= $this->_class->getQuotedTableName($this->_platform) .
$joinSql .= $this->_getSQLTableAlias($this->_class) .
'.' . $this->_class->getQuotedColumnName($this->_class->fieldNames[$sourceColumn], $this->_platform) . ' = '
. $joinTableName
. '.' . $owningAssoc->getQuotedJoinColumnName($joinTableColumn, $this->_platform);
. $joinTableName . '.' . $joinTableColumn;
}
$joinSql = ' INNER JOIN ' . $joinTableName . ' ON ' . $joinSql;
$conditionSql = '';
foreach ($criteria as $joinColumn => $value) {
if ($conditionSql != '') $conditionSql .= ' AND ';
$columnName = $joinTableName . '.' . $owningAssoc->getQuotedJoinColumnName($joinColumn, $this->_platform);
$columnName = $joinTableName . '.' . $joinColumn;
$conditionSql .= $columnName . ' = ?';
}
$orderBySql = '';
if ($manyToMany->orderBy !== null) {
$orderBySql = $this->_getCollectionOrderBySql(
$manyToMany->orderBy, $this->_class->getQuotedTableName($this->_platform)
$orderBySql = $this->_getCollectionOrderBySQL(
$manyToMany->orderBy, $this->_getSQLTableAlias($this->_class)
);
}
return 'SELECT ' . $this->_getSelectColumnList()
. ' FROM ' . $this->_class->getQuotedTableName($this->_platform)
return 'SELECT ' . $this->_getSelectColumnListSQL()
. ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' '
. $this->_getSQLTableAlias($this->_class)
. $joinSql
. ' WHERE ' . $conditionSql . $orderBySql;
}
/** @override */
final protected function _processSqlResultInheritanceAware(array $sqlResult)
final protected function _processSQLResultInheritanceAware(array $sqlResult)
{
$data = array();
$entityName = $this->_class->name;
$entityName = $this->_class->discriminatorMap[$sqlResult[$this->_class->discriminatorColumn['name']]];
unset($sqlResult[$this->_class->discriminatorColumn['name']]);
foreach ($sqlResult as $column => $value) {
$column = isset($this->_resultColumnNames[$column]) ? $this->_resultColumnNames[$column] : $column;
if (($class = $this->_findDeclaringClass($column)) !== false) {
$field = $class->fieldNames[$column];
$data[$field] = Type::getType($class->fieldMappings[$field]['type'])
->convertToPHPValue($value, $this->_platform);
} else if ($column == $this->_class->discriminatorColumn['name']) {
$entityName = $this->_class->discriminatorMap[$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[$column] = $value;
$data[$realColumnName] = $value;
}
}
@ -831,10 +846,10 @@ class StandardEntityPersister
*
* @return string
*/
public function getInsertSql()
public function getInsertSQL()
{
if ($this->_insertSql === null) {
$this->_insertSql = $this->_generateInsertSql();
$this->_insertSql = $this->_generateInsertSQL();
}
return $this->_insertSql;
@ -844,6 +859,7 @@ class StandardEntityPersister
* Gets the list of columns to put in the INSERT SQL statement.
*
* @return array The list of columns.
* @internal INSERT SQL is cached by getInsertSQL() per request.
*/
protected function _getInsertColumnList()
{
@ -856,7 +872,7 @@ class StandardEntityPersister
$assoc = $this->_class->associationMappings[$name];
if ($assoc->isOwningSide && $assoc->isOneToOne()) {
foreach ($assoc->targetToSourceKeyColumns as $sourceCol) {
$columns[] = $assoc->getQuotedJoinColumnName($sourceCol, $this->_platform);
$columns[] = $sourceCol;
}
}
} else if ($this->_class->generatorType != ClassMetadata::GENERATOR_TYPE_IDENTITY ||
@ -872,13 +888,14 @@ class StandardEntityPersister
* Generates the INSERT SQL used by the persister to persist entities.
*
* @return string
* @internal Result is cached by getInsertSQL() per request.
*/
protected function _generateInsertSql()
protected function _generateInsertSQL()
{
$insertSql = '';
$columns = $this->_getInsertColumnList();
if (empty($columns)) {
$insertSql = $this->_platform->getEmptyIdentityInsertSql(
$insertSql = $this->_platform->getEmptyIdentityInsertSQL(
$this->_class->getQuotedTableName($this->_platform),
$this->_class->getQuotedColumnName($this->_class->identifier[0], $this->_platform)
);
@ -893,29 +910,66 @@ class StandardEntityPersister
return $insertSql;
}
private function _findDeclaringClass($column)
/**
* Gets the SQL snippet of a qualified column name for the given field name.
*
* @param string $field The field name.
* @param ClassMetadata $class The class that declares this field. The table this class if
* mapped to must own the column for the given field.
*/
protected function _getSelectColumnSQL($field, ClassMetadata $class)
{
static $cache = array();
if (isset($cache[$column])) {
return $cache[$column];
$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;
}
if (isset($this->_class->fieldNames[$column])) {
$cache[$column] = $this->_class;
return $this->_class;
}
foreach ($this->_class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName);
if (isset($subClass->fieldNames[$column])) {
$cache[$column] = $subClass;
return $subClass;
return "$sql AS $columnAlias";
}
/**
* Gets the SQL snippet for all join columns of the given class that are to be
* placed in an SQL SELECT statement.
*
* @return string
*/
protected function _getSelectJoinColumnsSQL(ClassMetadata $class)
{
$sql = '';
foreach ($class->associationMappings as $assoc) {
if ($assoc->isOwningSide && $assoc->isOneToOne()) {
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
$columnAlias = $srcColumn . $this->_sqlAliasCounter++;
$sql .= ', ' . $this->_getSQLTableAlias($this->_class) . ".$srcColumn AS $columnAlias";
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
}
}
}
}
return $sql;
}
/**
* Gets the SQL table alias for the given class.
*
* @param ClassMetadata $class
* @return string The SQL table alias.
*/
protected function _getSQLTableAlias(ClassMetadata $class)
{
if (isset($this->_sqlTableAliases[$class->name])) {
return $this->_sqlTableAliases[$class->name];
}
$tableAlias = $class->primaryTable['name'][0] . $this->_sqlAliasCounter++;
$this->_sqlTableAliases[$class->name] = $tableAlias;
$cache[$column] = false;
return false;
return $tableAlias;
}
}

View File

@ -23,8 +23,7 @@ namespace Doctrine\ORM\Proxy;
use Doctrine\ORM\EntityManager,
Doctrine\ORM\Mapping\ClassMetadata,
Doctrine\ORM\Mapping\AssociationMapping,
Doctrine\Common\DoctrineException;
Doctrine\ORM\Mapping\AssociationMapping;
/**
* This factory is used to create proxy objects for entities at runtime.
@ -56,17 +55,17 @@ class ProxyFactory
public function __construct(EntityManager $em, $proxyDir, $proxyNs, $autoGenerate = false)
{
if ( ! $proxyDir) {
throw DoctrineException::proxyDirectoryRequired();
throw ProxyException::proxyDirectoryRequired();
}
if ( ! $proxyNs) {
throw DoctrineException::proxyNamespaceRequired();
throw ProxyException::proxyNamespaceRequired();
}
$this->_em = $em;
$this->_proxyDir = $proxyDir;
$this->_autoGenerate = $autoGenerate;
$this->_proxyNamespace = $proxyNs;
}
}
/**
* Gets a reference proxy instance for the entity of the given type and identified by
* the given identifier.
@ -79,25 +78,25 @@ class ProxyFactory
{
$proxyClassName = str_replace('\\', '', $className) . 'Proxy';
$fqn = $this->_proxyNamespace . '\\' . $proxyClassName;
if ($this->_autoGenerate && ! class_exists($fqn, false)) {
$fileName = $this->_proxyDir . DIRECTORY_SEPARATOR . $proxyClassName . '.php';
$this->_generateProxyClass($this->_em->getClassMetadata($className), $proxyClassName, $fileName, self::$_proxyClassTemplate);
require $fileName;
}
if ( ! $this->_em->getMetadataFactory()->hasMetadataFor($fqn)) {
$this->_em->getMetadataFactory()->setMetadataFor($fqn, $this->_em->getClassMetadata($className));
}
$entityPersister = $this->_em->getUnitOfWork()->getEntityPersister($className);
return new $fqn($entityPersister, $identifier);
}
/**
* Generates proxy classes for all given classes.
*
*
* @param array $classes The classes (ClassMetadata instances) for which to generate proxies.
* @param string $toDir The target directory of the proxy classes. If not specified, the
* directory configured on the Configuration of the EntityManager used
@ -113,10 +112,10 @@ class ProxyFactory
$this->_generateProxyClass($class, $proxyClassName, $proxyFileName, self::$_proxyClassTemplate);
}
}
/**
* Generates a (reference or association) proxy class.
*
*
* @param $class
* @param $originalClassName
* @param $proxyClassName
@ -144,33 +143,33 @@ class ProxyFactory
$proxyClassName, $className,
$methods, $sleepImpl
);
$file = str_replace($placeholders, $replacements, $file);
file_put_contents($fileName, $file);
}
/**
* Generates the methods of a proxy class.
*
*
* @param ClassMetadata $class
* @return string The code of the generated methods.
*/
private function _generateMethods(ClassMetadata $class)
{
$methods = '';
foreach ($class->reflClass->getMethods() as $method) {
/* @var $method ReflectionMethod */
if ($method->isConstructor() || strtolower($method->getName()) == "__sleep") {
continue;
}
if ($method->isPublic() && ! $method->isFinal() && ! $method->isStatic()) {
$methods .= PHP_EOL . ' public function ' . $method->getName() . '(';
$firstParam = true;
$parameterString = $argumentString = '';
foreach ($method->getParameters() as $param) {
if ($firstParam) {
$firstParam = false;
@ -178,68 +177,68 @@ class ProxyFactory
$parameterString .= ', ';
$argumentString .= ', ';
}
// We need to pick the type hint class too
if (($paramClass = $param->getClass()) !== null) {
$parameterString .= '\\' . $paramClass->getName() . ' ';
} else if ($param->isArray()) {
$parameterString .= 'array ';
}
if ($param->isPassedByReference()) {
$parameterString .= '&';
}
$parameterString .= '$' . $param->getName();
$argumentString .= '$' . $param->getName();
if ($param->isDefaultValueAvailable()) {
$parameterString .= ' = ' . var_export($param->getDefaultValue(), true);
}
}
$methods .= $parameterString . ') {' . PHP_EOL;
$methods .= ' $this->_load();' . PHP_EOL;
$methods .= ' return parent::' . $method->getName() . '(' . $argumentString . ');';
$methods .= PHP_EOL . ' }' . PHP_EOL;
}
}
return $methods;
}
/**
* Generates the code for the __sleep method for a proxy class.
*
*
* @param $class
* @return string
*/
private function _generateSleep(ClassMetadata $class)
{
$sleepImpl = '';
if ($class->reflClass->hasMethod('__sleep')) {
$sleepImpl .= 'return parent::__sleep();';
} else {
$sleepImpl .= 'return array(';
$first = true;
foreach ($class->getReflectionProperties() as $name => $prop) {
if ($first) {
$first = false;
} else {
$sleepImpl .= ', ';
}
$sleepImpl .= "'" . $name . "'";
}
$sleepImpl .= ');';
}
return $sleepImpl;
}
/** Reference Proxy class code template */
private static $_proxyClassTemplate =
'<?php

View File

@ -41,7 +41,7 @@ class CurrentDateFunction extends FunctionNode
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return $sqlWalker->getConnection()->getDatabasePlatform()->getCurrentDateSql();
return $sqlWalker->getConnection()->getDatabasePlatform()->getCurrentDateSQL();
}
/**

View File

@ -41,7 +41,7 @@ class CurrentTimeFunction extends FunctionNode
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return $sqlWalker->getConnection()->getDatabasePlatform()->getCurrentTimeSql();
return $sqlWalker->getConnection()->getDatabasePlatform()->getCurrentTimeSQL();
}
/**

View File

@ -20,7 +20,7 @@ class CurrentTimestampFunction extends FunctionNode
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return $sqlWalker->getConnection()->getDatabasePlatform()->getCurrentTimestampSql();
return $sqlWalker->getConnection()->getDatabasePlatform()->getCurrentTimestampSQL();
}
/**

View File

@ -95,8 +95,8 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor
'type' => \Doctrine\DBAL\Types\Type::getType($rootClass->getTypeOfColumn($idColumnName))
);
}
$this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSql() . ' ' . $tempTable . ' ('
. $conn->getDatabasePlatform()->getColumnDeclarationListSql($columnDefinitions)
$this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
. $conn->getDatabasePlatform()->getColumnDeclarationListSQL($columnDefinitions)
. ', PRIMARY KEY(' . $idColumnList . '))';
$this->_dropTempTableSql = 'DROP TABLE ' . $tempTable;
}

View File

@ -127,8 +127,8 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
'type' => \Doctrine\DBAL\Types\Type::getType($rootClass->getTypeOfColumn($idColumnName))
);
}
$this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSql() . ' ' . $tempTable . ' ('
. $platform->getColumnDeclarationListSql($columnDefinitions)
$this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
. $platform->getColumnDeclarationListSQL($columnDefinitions)
. ', PRIMARY KEY(' . $idColumnList . '))';
$this->_dropTempTableSql = 'DROP TABLE ' . $tempTable;
}

View File

@ -21,8 +21,7 @@
namespace Doctrine\ORM\Query;
use Doctrine\Common\DoctrineException, //TODO: Remove
Doctrine\ORM\Query;
use Doctrine\ORM\Query;
/**
* An LL(*) recursive-descent parser for the context-free grammar of the Doctrine Query Language.
@ -94,7 +93,7 @@ class Parser
* @var EnityManager
*/
private $_em;
/**
* The Query to parse.
*
@ -108,24 +107,24 @@ class Parser
* @var array
*/
private $_queryComponents = array();
/**
* Keeps the nesting level of defined ResultVariables
*
* @var integer
*/
private $_nestingLevel = 0;
/**
* Any additional custom tree walkers that modify the AST.
*
* @var array
*/
private $_customTreeWalkers = array();
/**
* The custom last tree walker, if any, that is responsible for producing the output.
*
*
* @var TreeWalker
*/
private $_customOutputWalker;
@ -146,17 +145,17 @@ class Parser
/**
* Sets a custom tree walker that produces output.
* This tree walker will be run last over the AST, after any other walkers.
*
*
* @param string $className
*/
public function setCustomOutputTreeWalker($className)
{
$this->_customOutputWalker = $className;
}
/**
* Adds a custom tree walker for modifying the AST.
*
*
* @param string $className
*/
public function addCustomTreeWalker($className)
@ -183,7 +182,7 @@ class Parser
{
return $this->_parserResult;
}
/**
* Gets the EntityManager used by the parser.
*
@ -193,7 +192,7 @@ class Parser
{
return $this->_em;
}
/**
* Registers a custom function that returns strings.
*
@ -275,7 +274,7 @@ class Parser
{
// Parse & build AST
$AST = $this->QueryLanguage();
// Process any deferred validations of some nodes in the AST.
// This also allows post-processing of the AST for modification purposes.
$this->_processDeferredIdentificationVariables();
@ -296,11 +295,11 @@ class Parser
// Run any custom tree walkers over the AST
if ($this->_customTreeWalkers) {
$treeWalkerChain = new TreeWalkerChain($this->_query, $this->_parserResult, $this->_queryComponents);
foreach ($this->_customTreeWalkers as $walker) {
$treeWalkerChain->addTreeWalker($walker);
}
if ($AST instanceof AST\SelectStatement) {
$treeWalkerChain->walkSelectStatement($AST);
} else if ($AST instanceof AST\UpdateStatement) {
@ -309,7 +308,7 @@ class Parser
$treeWalkerChain->walkDeleteStatement($AST);
}
}
if ($this->_customOutputWalker) {
$outputWalker = new $this->_customOutputWalker(
$this->_query, $this->_parserResult, $this->_queryComponents
@ -325,7 +324,7 @@ class Parser
return $this->_parserResult;
}
/**
* Generates a new syntax error.
*
@ -371,17 +370,17 @@ class Parser
if ($token === null) {
$token = $this->_lexer->lookahead;
}
// Minimum exposed chars ahead of token
$distance = 12;
// Find a position of a final word to display in error string
$dql = $this->_query->getDql();
$length = strlen($dql);
$pos = $token['position'] + $distance;
$pos = strpos($dql, ' ', ($length > $pos) ? $pos : $length);
$length = ($pos !== false) ? $pos - $token['position'] : $distance;
// Building informative message
$message = 'line 0, col ' . (
(isset($token['position']) && $token['position'] > 0) ? $token['position'] : '-1'
@ -389,7 +388,7 @@ class Parser
throw \Doctrine\ORM\Query\QueryException::semanticalError($message);
}
/**
* Peeks beyond the specified token and returns the first token after that one.
*
@ -424,7 +423,7 @@ class Parser
// We deny the COUNT(SELECT * FROM User u) here. COUNT won't be considered a function
return ($peek['value'] === '(' && $nextpeek['type'] !== Lexer::T_SELECT);
}
/**
* Checks whether the function with the given name is a string function
* (a function that returns strings).
@ -457,7 +456,7 @@ class Parser
{
return isset(self::$_DATETIME_FUNCTIONS[strtolower($funcName)]);
}
/**
* Checks whether the given token type indicates an aggregate function.
*
@ -497,7 +496,7 @@ class Parser
}
/**
* Validates that the given <tt>IdentificationVariable</tt> is a semantically correct.
* Validates that the given <tt>IdentificationVariable</tt> is a semantically correct.
* It must exist in query components list.
*
* @return void
@ -553,9 +552,9 @@ class Parser
}
}
}
/**
* Validates that the given <tt>ResultVariable</tt> is a semantically correct.
* Validates that the given <tt>ResultVariable</tt> is a semantically correct.
* It must exist in query components list.
*
* @return void
@ -621,7 +620,7 @@ class Parser
// Check if it is not in a state field
if ($fieldType & AST\PathExpression::TYPE_STATE_FIELD) {
$this->semanticalError(
'Cannot navigate through state field named ' . $field . ' on ' . $parentField,
'Cannot navigate through state field named ' . $field . ' on ' . $parentField,
$deferredItem['token']
);
}
@ -629,7 +628,7 @@ class Parser
// Check if it is not a collection field
if ($fieldType & AST\PathExpression::TYPE_COLLECTION_VALUED_ASSOCIATION) {
$this->semanticalError(
'Cannot navigate through collection field named ' . $field . ' on ' . $parentField,
'Cannot navigate through collection field named ' . $field . ' on ' . $parentField,
$deferredItem['token']
);
}
@ -637,7 +636,7 @@ class Parser
// Check if field or association exists
if ( ! isset($class->associationMappings[$field]) && ! isset($class->fieldMappings[$field])) {
$this->semanticalError(
'Class ' . $class->name . ' has no field or association named ' . $field,
'Class ' . $class->name . ' has no field or association named ' . $field,
$deferredItem['token']
);
}
@ -733,14 +732,14 @@ class Parser
/**
* QueryLanguage ::= SelectStatement | UpdateStatement | DeleteStatement
*
* @return \Doctrine\ORM\Query\AST\SelectStatement |
* \Doctrine\ORM\Query\AST\UpdateStatement |
* @return \Doctrine\ORM\Query\AST\SelectStatement |
* \Doctrine\ORM\Query\AST\UpdateStatement |
* \Doctrine\ORM\Query\AST\DeleteStatement
*/
public function QueryLanguage()
{
$this->_lexer->moveNext();
switch ($this->_lexer->lookahead['type']) {
case Lexer::T_SELECT:
$statement = $this->SelectStatement();
@ -760,7 +759,7 @@ class Parser
if ($this->_lexer->lookahead !== null) {
$this->syntaxError('end of string');
}
return $statement;
}
@ -784,7 +783,7 @@ class Parser
$selectStatement->orderByClause = $this->_lexer->isNextToken(Lexer::T_ORDER)
? $this->OrderByClause() : null;
return $selectStatement;
}
@ -796,7 +795,7 @@ class Parser
public function UpdateStatement()
{
$updateStatement = new AST\UpdateStatement($this->UpdateClause());
$updateStatement->whereClause = $this->_lexer->isNextToken(Lexer::T_WHERE)
$updateStatement->whereClause = $this->_lexer->isNextToken(Lexer::T_WHERE)
? $this->WhereClause() : null;
return $updateStatement;
@ -810,7 +809,7 @@ class Parser
public function DeleteStatement()
{
$deleteStatement = new AST\DeleteStatement($this->DeleteClause());
$deleteStatement->whereClause = $this->_lexer->isNextToken(Lexer::T_WHERE)
$deleteStatement->whereClause = $this->_lexer->isNextToken(Lexer::T_WHERE)
? $this->WhereClause() : null;
return $deleteStatement;
@ -844,10 +843,10 @@ class Parser
public function AliasIdentificationVariable()
{
$this->match(Lexer::T_IDENTIFIER);
$aliasIdentVariable = $this->_lexer->token['value'];
$exists = isset($this->_queryComponents[$aliasIdentVariable]);
if ($exists) {
$this->semanticalError(
"'$aliasIdentVariable' is already defined.", $this->_lexer->token
@ -890,16 +889,16 @@ class Parser
public function AliasResultVariable()
{
$this->match(Lexer::T_IDENTIFIER);
$resultVariable = $this->_lexer->token['value'];
$exists = isset($this->_queryComponents[$resultVariable]);
if ($exists) {
$this->semanticalError(
"'$resultVariable' is already defined.", $this->_lexer->token
);
}
return $resultVariable;
}
@ -911,16 +910,16 @@ class Parser
public function ResultVariable()
{
$this->match(Lexer::T_IDENTIFIER);
$resultVariable = $this->_lexer->token['value'];
// Defer ResultVariable validation
$this->_deferredResultVariables[] = array(
'expression' => $resultVariable,
'nestingLevel' => $this->_nestingLevel,
'token' => $this->_lexer->token,
);
return $resultVariable;
}
@ -932,7 +931,7 @@ class Parser
public function JoinAssociationPathExpression()
{
$token = $this->_lexer->lookahead;
$identVariable = $this->IdentificationVariable();
$this->match(Lexer::T_DOT);
$this->match($this->_lexer->lookahead['type']);
@ -941,16 +940,16 @@ class Parser
// Validate association field
$qComp = $this->_queryComponents[$identVariable];
$class = $qComp['metadata'];
if ( ! isset($class->associationMappings[$field])) {
$this->semanticalError('Class ' . $class->name . ' has no association named ' . $field);
}
return new AST\JoinAssociationPathExpression($identVariable, $field);
}
}
/**
* Parses an arbitrary path expression and defers semantical validation
* Parses an arbitrary path expression and defers semantical validation
* based on expected types.
*
* PathExpression ::= IdentificationVariable {"." identifier}* "." identifier
@ -967,13 +966,13 @@ class Parser
do {
$this->match(Lexer::T_DOT);
$this->match(Lexer::T_IDENTIFIER);
$parts[] = $this->_lexer->token['value'];
} while ($this->_lexer->isNextToken(Lexer::T_DOT));
// Creating AST node
$pathExpr = new AST\PathExpression($expectedTypes, $identVariable, $parts);
// Defer PathExpression validation if requested to be defered
$this->_deferredPathExpressions[] = array(
'expression' => $pathExpr,
@ -1049,14 +1048,14 @@ class Parser
{
$pathExpression = $this->PathExpression(AST\PathExpression::TYPE_STATE_FIELD);
$parts = $pathExpression->parts;
if (count($parts) > 1) {
$this->semanticalError(
"Invalid SimpleStateFieldPathExpression. " .
"Invalid SimpleStateFieldPathExpression. " .
"Expected state field, got association '{$parts[0]}'."
);
}
return $pathExpression;
}
@ -1116,13 +1115,13 @@ class Parser
$this->match(Lexer::T_UPDATE);
$token = $this->_lexer->lookahead;
$abstractSchemaName = $this->AbstractSchemaName();
if ($this->_lexer->isNextToken(Lexer::T_AS)) {
$this->match(Lexer::T_AS);
}
$aliasIdentificationVariable = $this->AliasIdentificationVariable();
$class = $this->_em->getClassMetadata($abstractSchemaName);
// Building queryComponent
@ -1137,7 +1136,7 @@ class Parser
$this->_queryComponents[$aliasIdentificationVariable] = $queryComponent;
$this->match(Lexer::T_SET);
$updateItems = array();
$updateItems[] = $this->UpdateItem();
@ -1167,16 +1166,16 @@ class Parser
$token = $this->_lexer->lookahead;
$deleteClause = new AST\DeleteClause($this->AbstractSchemaName());
if ($this->_lexer->isNextToken(Lexer::T_AS)) {
$this->match(Lexer::T_AS);
}
$aliasIdentificationVariable = $this->AliasIdentificationVariable();
$deleteClause->aliasIdentificationVariable = $aliasIdentificationVariable;
$class = $this->_em->getClassMetadata($deleteClause->abstractSchemaName);
// Building queryComponent
$queryComponent = array(
'metadata' => $class,
@ -1303,21 +1302,21 @@ class Parser
{
// Increase query nesting level
$this->_nestingLevel++;
$subselect = new AST\Subselect($this->SimpleSelectClause(), $this->SubselectFromClause());
$subselect->whereClause = $this->_lexer->isNextToken(Lexer::T_WHERE)
$subselect->whereClause = $this->_lexer->isNextToken(Lexer::T_WHERE)
? $this->WhereClause() : null;
$subselect->groupByClause = $this->_lexer->isNextToken(Lexer::T_GROUP)
$subselect->groupByClause = $this->_lexer->isNextToken(Lexer::T_GROUP)
? $this->GroupByClause() : null;
$subselect->havingClause = $this->_lexer->isNextToken(Lexer::T_HAVING)
$subselect->havingClause = $this->_lexer->isNextToken(Lexer::T_HAVING)
? $this->HavingClause() : null;
$subselect->orderByClause = $this->_lexer->isNextToken(Lexer::T_ORDER)
$subselect->orderByClause = $this->_lexer->isNextToken(Lexer::T_ORDER)
? $this->OrderByClause() : null;
// Decrease query nesting level
$this->_nestingLevel--;
@ -1332,23 +1331,23 @@ class Parser
public function UpdateItem()
{
$token = $this->_lexer->lookahead;
$identVariable = $this->IdentificationVariable();
$this->match(Lexer::T_DOT);
$this->match(Lexer::T_IDENTIFIER);
$field = $this->_lexer->token['value'];
// Check if field exists
$class = $this->_queryComponents[$identVariable]['metadata'];
if ( ! isset($class->associationMappings[$field]) && ! isset($class->fieldMappings[$field])) {
$this->semanticalError(
'Class ' . $class->name . ' has no field named ' . $field, $token
);
}
$this->match(Lexer::T_EQUALS);
$newValue = $this->NewValue();
$updateItem = new AST\UpdateItem($field, $newValue);
@ -1366,7 +1365,7 @@ class Parser
{
// We need to check if we are in a IdentificationVariable or SingleValuedPathExpression
$glimpse = $this->_lexer->glimpse();
if ($glimpse['value'] != '.') {
$token = $this->_lexer->lookahead;
$identVariable = $this->IdentificationVariable();
@ -1380,7 +1379,7 @@ class Parser
/**
* OrderByItem ::= (ResultVariable | StateFieldPathExpression) ["ASC" | "DESC"]
*
* @todo Post 2.0 release. Support general SingleValuedPathExpression instead
* @todo Post 2.0 release. Support general SingleValuedPathExpression instead
* of only StateFieldPathExpression.
*
* @return \Doctrine\ORM\Query\AST\OrderByItem
@ -1388,17 +1387,17 @@ class Parser
public function OrderByItem()
{
$type = 'ASC';
// We need to check if we are in a ResultVariable or StateFieldPathExpression
$glimpse = $this->_lexer->glimpse();
if ($glimpse['value'] != '.') {
$token = $this->_lexer->lookahead;
$expr = $this->ResultVariable();
} else {
$expr = $this->StateFieldPathExpression();
}
$item = new AST\OrderByItem($expr);
if ($this->_lexer->isNextToken(Lexer::T_ASC)) {
@ -1407,7 +1406,7 @@ class Parser
$this->match(Lexer::T_DESC);
$type = 'DESC';
}
$item->type = $type;
return $item;
}
@ -1418,7 +1417,7 @@ class Parser
*
* NOTE: Since it is not possible to correctly recognize individual types, here is the full
* grammar that needs to be supported:
*
*
* NewValue ::= SimpleArithmeticExpression | "NULL"
*
* SimpleArithmeticExpression covers all *Primary grammar rules and also SimplEntityExpression
@ -1432,7 +1431,7 @@ class Parser
$this->match(Lexer::T_INPUT_PARAMETER);
return new AST\InputParameter($this->_lexer->token['value']);
}
return $this->SimpleArithmeticExpression();
}
@ -1504,7 +1503,7 @@ class Parser
public function RangeVariableDeclaration()
{
$abstractSchemaName = $this->AbstractSchemaName();
if ($this->_lexer->isNextToken(Lexer::T_AS)) {
$this->match(Lexer::T_AS);
}
@ -1530,18 +1529,18 @@ class Parser
/**
* PartialObjectExpression ::= "PARTIAL" IdentificationVariable "." PartialFieldSet
* PartialFieldSet ::= "{" SimpleStateField {"," SimpleStateField}* "}"
*
*
* @return array
*/
public function PartialObjectExpression()
{
$this->match(Lexer::T_PARTIAL);
$this->match(Lexer::T_PARTIAL);
$partialFieldSet = array();
$identificationVariable = $this->IdentificationVariable();
$this->match(Lexer::T_DOT);
$this->match(Lexer::T_OPEN_CURLY_BRACE);
$this->match(Lexer::T_IDENTIFIER);
$partialFieldSet[] = $this->_lexer->token['value'];
@ -1551,16 +1550,16 @@ class Parser
$partialFieldSet[] = $this->_lexer->token['value'];
}
$this->match(Lexer::T_CLOSE_CURLY_BRACE);
$partialObjectExpression = new AST\PartialObjectExpression($identificationVariable, $partialFieldSet);
// Defer PartialObjectExpression validation
$this->_deferredPartialObjectExpressions[] = array(
'expression' => $partialObjectExpression,
'nestingLevel' => $this->_nestingLevel,
'token' => $this->_lexer->token,
);
return $partialObjectExpression;
}
@ -1657,7 +1656,7 @@ class Parser
* ScalarExpression ::= SimpleArithmeticExpression | StringPrimary | DateTimePrimary |
* StateFieldPathExpression | BooleanPrimary | CaseExpression |
* EntityTypeExpression
*
*
* @return mixed One of the possible expressions or subexpressions.
*/
public function ScalarExpression()
@ -1668,7 +1667,7 @@ class Parser
$this->_lexer->peek(); // lookahead => token after '.'
$peek = $this->_lexer->peek(); // lookahead => token after the token after the '.'
$this->_lexer->resetPeek();
if ($peek['value'] == '+' || $peek['value'] == '-' || $peek['value'] == '/' || $peek['value'] == '*') {
return $this->SimpleArithmeticExpression();
}
@ -1737,7 +1736,7 @@ class Parser
if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) {
$expression = $this->AggregateExpression();
} else {
// Shortcut: ScalarExpression => Function
// Shortcut: ScalarExpression => Function
$expression = $this->FunctionDeclaration();
}
} else if ($this->_lexer->lookahead['type'] == Lexer::T_PARTIAL) {
@ -1752,7 +1751,7 @@ class Parser
. ' | AggregateExpression | "(" Subselect ")" | ScalarExpression',
$this->_lexer->lookahead);
}
if ($supportsAlias) {
if ($this->_lexer->isNextToken(Lexer::T_AS)) {
$this->match(Lexer::T_AS);
@ -1761,7 +1760,7 @@ class Parser
if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) {
$token = $this->_lexer->lookahead;
$fieldAliasIdentificationVariable = $this->AliasResultVariable();
// Include AliasResultVariable in query components.
$this->_queryComponents[$fieldAliasIdentificationVariable] = array(
'resultVariable' => $expression,
@ -1793,7 +1792,7 @@ class Parser
return new AST\SimpleSelectExpression($this->_lexer->token['value']);
}
$expr = new AST\SimpleSelectExpression($this->AggregateExpression());
if ($this->_lexer->isNextToken(Lexer::T_AS)) {
@ -1804,7 +1803,7 @@ class Parser
$token = $this->_lexer->lookahead;
$resultVariable = $this->AliasResultVariable();
$expr->fieldIdentificationVariable = $resultVariable;
// Include AliasResultVariable in query components.
$this->_queryComponents[$resultVariable] = array(
'resultvariable' => $expr,
@ -1868,7 +1867,7 @@ class Parser
$condFactor = new AST\ConditionalFactor($this->ConditionalPrimary());
$condFactor->not = $not;
return $condFactor;
}
@ -1880,11 +1879,11 @@ class Parser
public function ConditionalPrimary()
{
$condPrimary = new AST\ConditionalPrimary;
if ($this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) {
// Peek beyond the matching closing paranthesis ')'
$peek = $this->_peekBeyondClosingParenthesis();
if (in_array($peek['value'], array("=", "<", "<=", "<>", ">", ">=", "!=")) ||
$peek['type'] === Lexer::T_NOT ||
$peek['type'] === Lexer::T_BETWEEN ||
@ -1901,7 +1900,7 @@ class Parser
} else {
$condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression();
}
return $condPrimary;
}
@ -1924,7 +1923,7 @@ class Parser
}
$peek = $this->_lexer->glimpse();
if ($token['type'] === Lexer::T_IDENTIFIER || $token['type'] === Lexer::T_INPUT_PARAMETER) {
if ($peek['value'] == '(') {
// Peek beyond the matching closing paranthesis ')'
@ -1976,7 +1975,7 @@ class Parser
return $this->ComparisonExpression();
}
}
private function _peekBeyondClosingParenthesis()
{
$numUnmatched = 1;
@ -1990,7 +1989,7 @@ class Parser
$token = $this->_lexer->peek();
}
$this->_lexer->resetPeek();
return $token;
}
@ -2018,17 +2017,17 @@ class Parser
/**
* CollectionMemberExpression ::= EntityExpression ["NOT"] "MEMBER" ["OF"] CollectionValuedPathExpression
*
*
* EntityExpression ::= SingleValuedAssociationPathExpression | SimpleEntityExpression
* SimpleEntityExpression ::= IdentificationVariable | InputParameter
*
*
* @return \Doctrine\ORM\Query\AST\CollectionMemberExpression
*/
public function CollectionMemberExpression()
{
$not = false;
$entityExpr = $this->EntityExpression();
$entityExpr = $this->EntityExpression();
if ($this->_lexer->isNextToken(Lexer::T_NOT)) {
$not = true;
@ -2045,7 +2044,7 @@ class Parser
$entityExpr, $this->CollectionValuedPathExpression()
);
$collMemberExpr->not = $not;
return $collMemberExpr;
}
@ -2060,21 +2059,21 @@ class Parser
case Lexer::T_STRING:
$this->match(Lexer::T_STRING);
return new AST\Literal(AST\Literal::STRING, $this->_lexer->token['value']);
case Lexer::T_INTEGER:
case Lexer::T_FLOAT:
$this->match(
$this->_lexer->isNextToken(Lexer::T_INTEGER) ? Lexer::T_INTEGER : Lexer::T_FLOAT
);
return new AST\Literal(AST\Literal::NUMERIC, $this->_lexer->token['value']);
case Lexer::T_TRUE:
case Lexer::T_FALSE:
$this->match(
$this->_lexer->isNextToken(Lexer::T_TRUE) ? Lexer::T_TRUE : Lexer::T_FALSE
);
return new AST\Literal(AST\Literal::BOOLEAN, $this->_lexer->token['value']);
default:
$this->syntaxError('Literal');
}
@ -2090,7 +2089,7 @@ class Parser
if ($this->_lexer->lookahead['type'] == Lexer::T_INPUT_PARAMETER) {
return $this->InputParameter();
}
return $this->Literal();
}
@ -2164,7 +2163,7 @@ class Parser
while (($isMult = $this->_lexer->isNextToken(Lexer::T_MULTIPLY)) || $this->_lexer->isNextToken(Lexer::T_DIVIDE)) {
$this->match(($isMult) ? Lexer::T_MULTIPLY : Lexer::T_DIVIDE);
$factors[] = $this->_lexer->token['value'];
$factors[] = $this->ArithmeticFactor();
}
@ -2185,7 +2184,7 @@ class Parser
$this->match(($isPlus) ? Lexer::T_PLUS : Lexer::T_MINUS);
$sign = $isPlus;
}
return new AST\ArithmeticFactor($this->ArithmeticPrimary(), $sign);
}
@ -2199,7 +2198,7 @@ class Parser
if ($this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) {
$this->match(Lexer::T_OPEN_PARENTHESIS);
$expr = $this->SimpleArithmeticExpression();
$this->match(Lexer::T_CLOSE_PARENTHESIS);
return $expr;
@ -2297,11 +2296,11 @@ class Parser
public function EntityExpression()
{
$glimpse = $this->_lexer->glimpse();
if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER) && $glimpse['value'] === '.') {
return $this->SingleValuedAssociationPathExpression();
}
return $this->SimpleEntityExpression();
}
@ -2315,7 +2314,7 @@ class Parser
if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) {
return $this->InputParameter();
}
return $this->IdentificationVariable();
}
@ -2513,7 +2512,7 @@ class Parser
$likeExpr = new AST\LikeExpression($stringExpr, $stringPattern, $escapeChar);
$likeExpr->not = $not;
return $likeExpr;
}
@ -2630,7 +2629,7 @@ class Parser
} else if ($this->_isDatetimeFunction($funcName)) {
return $this->FunctionsReturningDatetime();
}
$this->syntaxError('Known function.');
}

View File

@ -35,18 +35,18 @@ use Doctrine\ORM\Query\AST\PathExpression;
* @author Roman Borschel <roman@code-factory.org>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class QueryException extends \Doctrine\Common\DoctrineException
class QueryException extends \Doctrine\ORM\ORMException
{
public static function syntaxError($message)
{
return new self('[Syntax Error] ' . $message);
}
public static function semanticalError($message)
{
return new self('[Semantical Error] ' . $message);
}
public static function invalidParameterPosition($pos)
{
return new self('Invalid parameter position: ' . $pos);
@ -66,15 +66,19 @@ class QueryException extends \Doctrine\Common\DoctrineException
{
return new self("Invalid parameter: token ".$key." is not defined in the query.");
}
public static function invalidPathExpression($pathExpr)
{
return new self(
"Invalid PathExpression '" . $pathExpr->identificationVariable .
"Invalid PathExpression '" . $pathExpr->identificationVariable .
"." . implode('.', $pathExpr->parts) . "'."
);
}
public static function invalidLiteral($literal) {
return new self("Invalid literal '$literal'");
}
/**
* @param Doctrine\ORM\Mapping\AssociationMapping $assoc
*/
@ -85,7 +89,7 @@ class QueryException extends \Doctrine\Common\DoctrineException
"in class ".$assoc->sourceEntityName." assocation ".$assoc->sourceFieldName
);
}
public static function partialObjectsAreDangerous()
{
return new self(
@ -103,7 +107,7 @@ class QueryException extends \Doctrine\Common\DoctrineException
"Use WITH to append additional join conditions to the association."
);
}
public static function associationPathInverseSideNotSupported()
{
return new self(
@ -111,7 +115,12 @@ class QueryException extends \Doctrine\Common\DoctrineException
" in DQL queries. Use an explicit join instead."
);
}
// TODO: Add the $assoc to the error message
public static function iterateWithFetchJoinNotAllowed($assoc) {
return new self("Iterate with fetch join not allowed");
}
public static function associationPathCompositeKeyNotSupported()
{
return new self(

View File

@ -161,6 +161,7 @@ class ResultSetMapping
*
* @param string $alias
* @return boolean
* @todo Rename: isIndexed($alias)
*/
public function hasIndexBy($alias)
{
@ -380,11 +381,11 @@ class ResultSetMapping
}
/**
* Adds a meta column (foreign key or discriminator column) to the result set.
*
* @param $alias
* @param $columnName
* @param $fieldName
* @return unknown_type
*/
public function addMetaResult($alias, $columnName, $fieldName)
{

View File

@ -22,8 +22,7 @@
namespace Doctrine\ORM\Query;
use Doctrine\ORM\Query,
Doctrine\ORM\Query\QueryException,
Doctrine\Common\DoctrineException;
Doctrine\ORM\Query\QueryException;
/**
* The SqlWalker is a TreeWalker that walks over a DQL AST and constructs
@ -40,59 +39,59 @@ class SqlWalker implements TreeWalker
* @var ResultSetMapping
*/
private $_rsm;
/** Counters for generating unique column aliases, table aliases and parameter indexes. */
private $_aliasCounter = 0;
private $_tableAliasCounter = 0;
private $_scalarResultCounter = 1;
private $_sqlParamIndex = 1;
/**
* @var ParserResult
*/
private $_parserResult;
/**
* @var EntityManager
*/
private $_em;
/**
* @var Doctrine\DBAL\Connection
*/
private $_conn;
/**
* @var AbstractQuery
*/
private $_query;
private $_tableAliasMap = array();
/** Map from result variable names to their SQL column alias names. */
private $_scalarResultAliasMap = array();
/** Map of all components/classes that appear in the DQL query. */
private $_queryComponents;
/** A list of classes that appear in non-scalar SelectExpressions. */
private $_selectedClasses = array();
/**
* The DQL alias of the root class of the currently traversed query.
* TODO: May need to be turned into a stack for usage in subqueries
*/
private $_currentRootAlias;
/**
* Flag that indicates whether to generate SQL table aliases in the SQL.
* These should only be generated for SELECT queries, not for UPDATE/DELETE.
*/
private $_useSqlTableAliases = true;
/**
* The database platform abstraction.
*
*
* @var AbstractPlatform
*/
private $_platform;
@ -110,10 +109,10 @@ class SqlWalker implements TreeWalker
$this->_conn = $this->_em->getConnection();
$this->_platform = $this->_conn->getDatabasePlatform();
}
/**
* Gets the Query instance used by the walker.
*
*
* @return Query.
*/
public function getQuery()
@ -123,27 +122,27 @@ class SqlWalker implements TreeWalker
/**
* Gets the Connection used by the walker.
*
*
* @return Connection
*/
public function getConnection()
{
return $this->_conn;
}
/**
* Gets the EntityManager used by the walker.
*
*
* @return EntityManager
*/
public function getEntityManager()
{
return $this->_em;
}
/**
* Gets the information about a single query component.
*
*
* @param string $dqlAlias The DQL alias.
* @return array
*/
@ -151,10 +150,10 @@ class SqlWalker implements TreeWalker
{
return $this->_queryComponents[$dqlAlias];
}
/**
* Gets an executor that can be used to execute the result of this walker.
*
*
* @return AbstractExecutor
*/
public function getExecutor($AST)
@ -166,7 +165,7 @@ class SqlWalker implements TreeWalker
$primaryClass = $this->_em->getClassMetadata(
$AST->deleteClause->abstractSchemaName
);
if ($primaryClass->isInheritanceTypeJoined()) {
return new Exec\MultiTableDeleteExecutor($AST, $this);
} else {
@ -176,17 +175,17 @@ class SqlWalker implements TreeWalker
$primaryClass = $this->_em->getClassMetadata(
$AST->updateClause->abstractSchemaName
);
if ($primaryClass->isInheritanceTypeJoined()) {
return new Exec\MultiTableUpdateExecutor($AST, $this);
} else {
return new Exec\SingleTableDeleteUpdateExecutor($AST, $this);
}
}
return new Exec\SingleSelectExecutor($AST, $this);
}
/**
* Generates a unique, short SQL table alias.
*
@ -196,14 +195,14 @@ class SqlWalker implements TreeWalker
public function getSqlTableAlias($tableName, $dqlAlias = '')
{
$tableName .= $dqlAlias;
if ( ! isset($this->_tableAliasMap[$tableName])) {
$this->_tableAliasMap[$tableName] = strtolower(substr($tableName, 0, 1)) . $this->_tableAliasCounter++ . '_';
}
return $this->_tableAliasMap[$tableName];
}
/**
* Forces the SqlWalker to use a specific alias for a table name, rather than
* generating an alias on its own.
@ -214,7 +213,7 @@ class SqlWalker implements TreeWalker
public function setSqlTableAlias($tableName, $alias)
{
$this->_tableAliasMap[$tableName] = $alias;
return $alias;
}
@ -247,16 +246,16 @@ class SqlWalker implements TreeWalker
foreach ($class->parentClasses as $parentClassName) {
$parentClass = $this->_em->getClassMetadata($parentClassName);
$tableAlias = $this->getSqlTableAlias($parentClass->primaryTable['name'], $dqlAlias);
$sql .= ' INNER JOIN ' . $parentClass->getQuotedTableName($this->_platform)
$sql .= ' INNER JOIN ' . $parentClass->getQuotedTableName($this->_platform)
. ' ' . $tableAlias . ' ON ';
$first = true;
foreach ($class->identifier as $idField) {
if ($first) $first = false; else $sql .= ' AND ';
$columnName = $class->getQuotedColumnName($idField, $this->_platform);
$sql .= $baseTableAlias . '.' . $columnName
. ' = '
. ' = '
. $tableAlias . '.' . $columnName;
}
}
@ -291,7 +290,7 @@ class SqlWalker implements TreeWalker
$qComp = $this->_queryComponents[$dqlAlias];
if (isset($qComp['relation']) && ($qComp['relation']->isManyToMany() || $qComp['relation']->isOneToMany())
&& $qComp['relation']->orderBy != null) {
foreach ($qComp['relation']->orderBy AS $fieldName => $orientation) {
if ($qComp['metadata']->isInheritanceTypeJoined()) {
$tableName = $this->_em->getUnitOfWork()->getEntityPersister($class->name)->getOwningTable($fieldName);
@ -319,29 +318,29 @@ class SqlWalker implements TreeWalker
private function _generateDiscriminatorColumnConditionSql($dqlAlias)
{
$sql = '';
if ($dqlAlias) {
$class = $this->_queryComponents[$dqlAlias]['metadata'];
if ($class->isInheritanceTypeSingleTable()) {
$conn = $this->_em->getConnection();
$values = array($conn->quote($class->discriminatorValue));
foreach ($class->subClasses as $subclassName) {
$values[] = $conn->quote($this->_em->getClassMetadata($subclassName)->discriminatorValue);
}
$sql .= (($this->_useSqlTableAliases)
$sql .= (($this->_useSqlTableAliases)
? $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias) . '.' : ''
) . $class->getQuotedDiscriminatorColumnName($this->_platform)
) . $class->discriminatorColumn['name']
. ' IN (' . implode(', ', $values) . ')';
}
}
return $sql;
}
/**
* Walks down a SelectStatement AST node, thereby generating the appropriate SQL.
*
@ -351,7 +350,7 @@ class SqlWalker implements TreeWalker
{
$sql = $this->walkSelectClause($AST->selectClause);
$sql .= $this->walkFromClause($AST->fromClause);
if (($whereClause = $AST->whereClause) !== null) {
$sql .= $this->walkWhereClause($whereClause);
} else if (($discSql = $this->_generateDiscriminatorColumnConditionSql($this->_currentRootAlias)) !== '') {
@ -374,7 +373,7 @@ class SqlWalker implements TreeWalker
return $sql;
}
/**
* Walks down an UpdateStatement AST node, thereby generating the appropriate SQL.
*
@ -385,13 +384,13 @@ class SqlWalker implements TreeWalker
{
$this->_useSqlTableAliases = false;
$sql = $this->walkUpdateClause($AST->updateClause);
if (($whereClause = $AST->whereClause) !== null) {
$sql .= $this->walkWhereClause($whereClause);
} else if (($discSql = $this->_generateDiscriminatorColumnConditionSql($this->_currentRootAlias)) !== '') {
$sql .= ' WHERE ' . $discSql;
}
return $sql;
}
@ -405,17 +404,17 @@ class SqlWalker implements TreeWalker
{
$this->_useSqlTableAliases = false;
$sql = $this->walkDeleteClause($AST->deleteClause);
if (($whereClause = $AST->whereClause) !== null) {
$sql .= $this->walkWhereClause($whereClause);
} else if (($discSql = $this->_generateDiscriminatorColumnConditionSql($this->_currentRootAlias)) !== '') {
$sql .= ' WHERE ' . $discSql;
}
return $sql;
}
/**
* Walks down an IdentificationVariable (no AST node associated), thereby generating the SQL.
*
@ -425,14 +424,14 @@ class SqlWalker implements TreeWalker
public function walkIdentificationVariable($identificationVariable, $fieldName = null)
{
$class = $this->_queryComponents[$identificationVariable]['metadata'];
if (
$fieldName !== null && $class->isInheritanceTypeJoined() &&
$fieldName !== null && $class->isInheritanceTypeJoined() &&
isset($class->fieldMappings[$fieldName]['inherited'])
) {
$class = $this->_em->getClassMetadata($class->fieldMappings[$fieldName]['inherited']);
}
return $this->getSqlTableAlias($class->primaryTable['name'], $identificationVariable);
}
@ -457,7 +456,7 @@ class SqlWalker implements TreeWalker
$sql .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.';
}
$sql .= $class->getQuotedColumnName($fieldName, $this->_platform);
$sql .= $class->getQuotedColumnName($fieldName, $this->_platform);
break;
case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION:
// 1- the owning side:
@ -467,14 +466,14 @@ class SqlWalker implements TreeWalker
$dqlAlias = $pathExpr->identificationVariable;
$class = $this->_queryComponents[$dqlAlias]['metadata'];
$assoc = $class->associationMappings[$fieldName];
if ($assoc->isOwningSide) {
// COMPOSITE KEYS NOT (YET?) SUPPORTED
if (count($assoc->sourceToTargetKeyColumns) > 1) {
throw QueryException::associationPathCompositeKeyNotSupported();
}
$sql .= $this->walkIdentificationVariable($dqlAlias) . '.'
. $assoc->getQuotedJoinColumnName(reset($assoc->targetToSourceKeyColumns), $this->_platform);
. reset($assoc->targetToSourceKeyColumns);
} else {
// 2- Inverse side: NOT (YET?) SUPPORTED
throw QueryException::associationPathInverseSideNotSupported();
@ -483,7 +482,7 @@ class SqlWalker implements TreeWalker
default:
throw QueryException::invalidPathExpression($pathExpr);
}
return $sql;
}
@ -516,20 +515,19 @@ class SqlWalker implements TreeWalker
$this->_queryComponents[$dqlAlias]['relation']->sourceFieldName
);
}
if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()) {
// Add discriminator columns to SQL
$rootClass = $this->_em->getClassMetadata($class->rootEntityName);
$tblAlias = $this->getSqlTableAlias($rootClass->primaryTable['name'], $dqlAlias);
$discrColumn = $rootClass->discriminatorColumn;
$columnAlias = $this->getSqlColumnAlias($discrColumn['name']);
$sql .= ", $tblAlias." . $rootClass->getQuotedDiscriminatorColumnName($this->_platform)
. ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$sql .= ", $tblAlias." . $discrColumn['name'] . ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->setDiscriminatorColumn($dqlAlias, $columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSqlResultCasing($columnAlias), $discrColumn['fieldName']);
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSQLResultCasing($columnAlias), $discrColumn['fieldName']);
// Add foreign key columns to SQL, if necessary
if ($addMetaColumns) {
//FIXME: Include foreign key columns of child classes also!!??
@ -544,10 +542,9 @@ class SqlWalker implements TreeWalker
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
$columnAlias = $this->getSqlColumnAlias($srcColumn);
$sql .= ", $sqlTableAlias." . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform)
. ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSqlResultCasing($columnAlias), $srcColumn);
$sql .= ", $sqlTableAlias." . $srcColumn . ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn);
}
}
}
@ -560,9 +557,9 @@ class SqlWalker implements TreeWalker
if ($assoc->isOwningSide && $assoc->isOneToOne()) {
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
$columnAlias = $this->getSqlColumnAlias($srcColumn);
$sql .= ', ' . $sqlTableAlias . '.' . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform) . ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSqlResultCasing($columnAlias), $srcColumn);
$sql .= ', ' . $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn);
}
}
}
@ -587,9 +584,9 @@ class SqlWalker implements TreeWalker
$dqlAlias = $rangeDecl->aliasIdentificationVariable;
$this->_currentRootAlias = $dqlAlias;
$class = $this->_em->getClassMetadata($rangeDecl->abstractSchemaName);
$sql .= $class->getQuotedTableName($this->_platform) . ' '
$sql .= $class->getQuotedTableName($this->_platform) . ' '
. $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias);
if ($class->isInheritanceTypeJoined()) {
@ -642,7 +639,7 @@ class SqlWalker implements TreeWalker
{
$sql = '';
$expr = $orderByItem->expression;
if ($expr instanceof AST\PathExpression) {
$sql = $this->walkPathExpression($expr);
} else {
@ -650,7 +647,7 @@ class SqlWalker implements TreeWalker
$sql = $this->_scalarResultAliasMap[$columnName];
}
return $sql . ' ' . strtoupper($orderByItem->type);;
}
@ -677,7 +674,7 @@ class SqlWalker implements TreeWalker
{
$join = $joinVarDecl->join;
$joinType = $join->joinType;
if ($joinType == AST\Join::JOIN_TYPE_LEFT || $joinType == AST\Join::JOIN_TYPE_LEFTOUTER) {
$sql = ' LEFT JOIN ';
} else {
@ -690,7 +687,7 @@ class SqlWalker implements TreeWalker
$targetClass = $targetQComp['metadata'];
$relation = $targetQComp['relation'];
$sourceClass = $this->_queryComponents[$joinAssocPathExpr->identificationVariable]['metadata'];
$targetTableName = $targetClass->getQuotedTableName($this->_platform);
$targetTableAlias = $this->getSqlTableAlias($targetClass->getTableName(), $joinedDqlAlias);
$sourceTableAlias = $this->getSqlTableAlias(
@ -717,18 +714,16 @@ class SqlWalker implements TreeWalker
foreach ($assoc->sourceToTargetKeyColumns as $sourceColumn => $targetColumn) {
if ( ! $first) $sql .= ' AND '; else $first = false;
$quotedSourceColumn = $assoc->getQuotedJoinColumnName($sourceColumn, $this->_platform);
if ($relation->isOwningSide) {
$quotedTargetColumn = $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->_platform);
$sql .= $sourceTableAlias . '.' . $quotedSourceColumn
$sql .= $sourceTableAlias . '.' . $sourceColumn
. ' = '
. $targetTableAlias . '.' . $quotedTargetColumn;
} else {
$quotedTargetColumn = $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$targetColumn], $this->_platform);
$sql .= $sourceTableAlias . '.' . $quotedTargetColumn
. ' = '
. $targetTableAlias . '.' . $quotedSourceColumn;
. $targetTableAlias . '.' . $sourceColumn;
}
}
} else if ($assoc->isManyToMany()) {
@ -736,18 +731,18 @@ class SqlWalker implements TreeWalker
$joinTable = $assoc->getJoinTable();
$joinTableAlias = $this->getSqlTableAlias($joinTable['name'], $joinedDqlAlias);
$sql .= $assoc->getQuotedJoinTableName($this->_platform) . ' ' . $joinTableAlias . ' ON ';
if ($relation->isOwningSide) {
foreach ($assoc->relationToSourceKeyColumns as $relationColumn => $sourceColumn) {
$sql .= $sourceTableAlias . '.' . $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$sourceColumn], $this->_platform)
. ' = '
. $joinTableAlias . '.' . $assoc->getQuotedJoinColumnName($relationColumn, $this->_platform);
. $joinTableAlias . '.' . $relationColumn;
}
} else {
foreach ($assoc->relationToTargetKeyColumns as $relationColumn => $targetColumn) {
$sql .= $sourceTableAlias . '.' . $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->_platform)
. ' = '
. $joinTableAlias . '.' . $assoc->getQuotedJoinColumnName($relationColumn, $this->_platform);
. $joinTableAlias . '.' . $relationColumn;
}
}
@ -760,13 +755,13 @@ class SqlWalker implements TreeWalker
foreach ($assoc->relationToTargetKeyColumns as $relationColumn => $targetColumn) {
$sql .= $targetTableAlias . '.' . $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->_platform)
. ' = '
. $joinTableAlias . '.' . $assoc->getQuotedJoinColumnName($relationColumn, $this->_platform);
. $joinTableAlias . '.' . $relationColumn;
}
} else {
foreach ($assoc->relationToSourceKeyColumns as $relationColumn => $sourceColumn) {
$sql .= $targetTableAlias . '.' . $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$sourceColumn], $this->_platform)
. ' = '
. $joinTableAlias . '.' . $assoc->getQuotedJoinColumnName($relationColumn, $this->_platform);
. $joinTableAlias . '.' . $relationColumn;
}
}
}
@ -779,7 +774,7 @@ class SqlWalker implements TreeWalker
}
$discrSql = $this->_generateDiscriminatorColumnConditionSql($joinedDqlAlias);
if ($discrSql) {
$sql .= ' AND ' . $discrSql;
}
@ -787,7 +782,7 @@ class SqlWalker implements TreeWalker
if ($targetClass->isInheritanceTypeJoined()) {
$sql .= $this->_generateClassTableInheritanceJoins($targetClass, $joinedDqlAlias);
}
return $sql;
}
@ -801,7 +796,7 @@ class SqlWalker implements TreeWalker
{
$sql = '';
$expr = $selectExpression->expression;
if ($expr instanceof AST\PathExpression) {
if ($expr->type == AST\PathExpression::TYPE_STATE_FIELD) {
$parts = $expr->parts;
@ -809,7 +804,7 @@ class SqlWalker implements TreeWalker
$dqlAlias = $expr->identificationVariable . (( ! empty($parts)) ? '.' . implode('.', $parts) : '');
$qComp = $this->_queryComponents[$dqlAlias];
$class = $qComp['metadata'];
if ( ! $selectExpression->fieldIdentificationVariable) {
$resultAlias = $fieldName;
} else {
@ -821,13 +816,13 @@ class SqlWalker implements TreeWalker
} else {
$tableName = $class->getTableName();
}
$sqlTableAlias = $this->getSqlTableAlias($tableName, $dqlAlias);
$columnName = $class->getQuotedColumnName($fieldName, $this->_platform);
$columnAlias = $this->getSqlColumnAlias($columnName);
$sql .= $sqlTableAlias . '.' . $columnName . ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
} else {
throw QueryException::invalidPathExpression($expr->type);
@ -839,12 +834,12 @@ class SqlWalker implements TreeWalker
} else {
$resultAlias = $selectExpression->fieldIdentificationVariable;
}
$columnAlias = 'sclr' . $this->_aliasCounter++;
$sql .= $this->walkAggregateExpression($expr) . ' AS ' . $columnAlias;
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
}
else if ($expr instanceof AST\Subselect) {
@ -858,7 +853,7 @@ class SqlWalker implements TreeWalker
$sql .= '(' . $this->walkSubselect($expr) . ') AS '.$columnAlias;
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
}
else if ($expr instanceof AST\Functions\FunctionNode) {
@ -871,8 +866,8 @@ class SqlWalker implements TreeWalker
$columnAlias = 'sclr' . $this->_aliasCounter++;
$sql .= $this->walkFunction($expr) . ' AS ' . $columnAlias;
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
}
else if ($expr instanceof AST\SimpleArithmeticExpression) {
@ -881,12 +876,12 @@ class SqlWalker implements TreeWalker
} else {
$resultAlias = $selectExpression->fieldIdentificationVariable;
}
$columnAlias = 'sclr' . $this->_aliasCounter++;
$sql .= $this->walkSimpleArithmeticExpression($expr) . ' AS ' . $columnAlias;
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
} else {
// IdentificationVariable or PartialObjectExpression
@ -897,7 +892,7 @@ class SqlWalker implements TreeWalker
$dqlAlias = $expr;
$partialFieldSet = array();
}
$queryComp = $this->_queryComponents[$dqlAlias];
$class = $queryComp['metadata'];
@ -911,21 +906,21 @@ class SqlWalker implements TreeWalker
if ($partialFieldSet && !in_array($fieldName, $partialFieldSet)) {
continue;
}
if (isset($mapping['inherited'])) {
$tableName = $this->_em->getClassMetadata($mapping['inherited'])->primaryTable['name'];
} else {
$tableName = $class->primaryTable['name'];
}
if ($beginning) $beginning = false; else $sql .= ', ';
$sqlTableAlias = $this->getSqlTableAlias($tableName, $dqlAlias);
$columnAlias = $this->getSqlColumnAlias($mapping['columnName']);
$sql .= $sqlTableAlias . '.' . $class->getQuotedColumnName($fieldName, $this->_platform)
. ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name);
}
@ -948,10 +943,10 @@ class SqlWalker implements TreeWalker
$sql .= $sqlTableAlias . '.' . $subClass->getQuotedColumnName($fieldName, $this->_platform)
. ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSqlResultCasing($columnAlias);
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $subClassName);
}
// Add join columns (foreign keys) of the subclass
//TODO: Probably better do this in walkSelectClause to honor the INCLUDE_META_COLUMNS hint
foreach ($subClass->associationMappings as $fieldName => $assoc) {
@ -959,16 +954,15 @@ class SqlWalker implements TreeWalker
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
if ($beginning) $beginning = false; else $sql .= ', ';
$columnAlias = $this->getSqlColumnAlias($srcColumn);
$sql .= $sqlTableAlias . '.' . $assoc->getQuotedJoinColumnName($srcColumn, $this->_platform)
. ' AS ' . $columnAlias;
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSqlResultCasing($columnAlias), $srcColumn);
$sql .= $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias;
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn);
}
}
}
}
}
}
return $sql;
}
@ -980,7 +974,7 @@ class SqlWalker implements TreeWalker
*/
public function walkQuantifiedExpression($qExpr)
{
return ' ' . strtoupper($qExpr->type)
return ' ' . strtoupper($qExpr->type)
. '(' . $this->walkSubselect($qExpr->subselect) . ')';
}
@ -994,14 +988,14 @@ class SqlWalker implements TreeWalker
{
$useAliasesBefore = $this->_useSqlTableAliases;
$this->_useSqlTableAliases = true;
$sql = $this->walkSimpleSelectClause($subselect->simpleSelectClause);
$sql .= $this->walkSubselectFromClause($subselect->subselectFromClause);
$sql .= $subselect->whereClause ? $this->walkWhereClause($subselect->whereClause) : '';
$sql .= $subselect->groupByClause ? $this->walkGroupByClause($subselect->groupByClause) : '';
$sql .= $subselect->havingClause ? $this->walkHavingClause($subselect->havingClause) : '';
$sql .= $subselect->orderByClause ? $this->walkOrderByClause($subselect->orderByClause) : '';
$this->_useSqlTableAliases = $useAliasesBefore;
return $sql;
@ -1020,7 +1014,7 @@ class SqlWalker implements TreeWalker
$rangeDecl = $firstIdentificationVarDecl->rangeVariableDeclaration;
$class = $this->_em->getClassMetadata($rangeDecl->abstractSchemaName);
$dqlAlias = $rangeDecl->aliasIdentificationVariable;
$sql = ' FROM ' . $class->getQuotedTableName($this->_platform) . ' '
. $this->getSqlTableAlias($class->primaryTable['name'], $dqlAlias);
@ -1053,7 +1047,7 @@ class SqlWalker implements TreeWalker
{
$sql = '';
$expr = $simpleSelectExpression->expression;
if ($expr instanceof AST\PathExpression) {
$sql .= ' ' . $this->walkPathExpression($expr);
} else if ($expr instanceof AST\AggregateExpression) {
@ -1072,7 +1066,7 @@ class SqlWalker implements TreeWalker
$sql .= ' ' . $this->getSqlTableAlias($class->getTableName(), $expr) . '.'
. $class->getQuotedColumnName($class->identifier[0], $this->_platform);
}
return $sql;
}
@ -1123,11 +1117,11 @@ class SqlWalker implements TreeWalker
$sql = 'DELETE FROM ';
$class = $this->_em->getClassMetadata($deleteClause->abstractSchemaName);
$sql .= $class->getQuotedTableName($this->_platform);
if ($this->_useSqlTableAliases) {
$sql .= ' ' . $this->getSqlTableAlias($class->getTableName());
}
$this->_currentRootAlias = $deleteClause->aliasIdentificationVariable;
return $sql;
@ -1144,17 +1138,17 @@ class SqlWalker implements TreeWalker
$sql = 'UPDATE ';
$class = $this->_em->getClassMetadata($updateClause->abstractSchemaName);
$sql .= $class->getQuotedTableName($this->_platform);
if ($this->_useSqlTableAliases) {
$sql .= ' ' . $this->getSqlTableAlias($class->getTableName());
}
$this->_currentRootAlias = $updateClause->aliasIdentificationVariable;
$sql .= ' SET ' . implode(
', ', array_map(array($this, 'walkUpdateItem'), $updateClause->updateItems)
);
return $sql;
}
@ -1168,7 +1162,7 @@ class SqlWalker implements TreeWalker
{
$useTableAliasesBefore = $this->_useSqlTableAliases;
$this->_useSqlTableAliases = false;
$sql = '';
$dqlAlias = $updateItem->identificationVariable;
$qComp = $this->_queryComponents[$dqlAlias];
@ -1176,7 +1170,7 @@ class SqlWalker implements TreeWalker
if ($this->_useSqlTableAliases) {
$sql .= $this->getSqlTableAlias($qComp['metadata']->getTableName()) . '.';
}
$sql .= $qComp['metadata']->getQuotedColumnName($updateItem->field, $this->_platform) . ' = ';
$newValue = $updateItem->newValue;
@ -1190,7 +1184,7 @@ class SqlWalker implements TreeWalker
$sql .= $this->_conn->quote($newValue);
}
}
$this->_useSqlTableAliases = $useTableAliasesBefore;
return $sql;
@ -1206,13 +1200,13 @@ class SqlWalker implements TreeWalker
{
$sql = ' WHERE ';
$condExpr = $whereClause->conditionalExpression;
$sql .= implode(
' OR ', array_map(array($this, 'walkConditionalTerm'), $condExpr->conditionalTerms)
);
$discrSql = $this->_generateDiscriminatorColumnConditionSql($this->_currentRootAlias);
if ($discrSql) {
$sql .= ' AND ' . $discrSql;
}
@ -1242,19 +1236,19 @@ class SqlWalker implements TreeWalker
public function walkConditionalFactor($factor)
{
$sql = ($factor->not) ? 'NOT ' : '';
$primary = $factor->conditionalPrimary;
if ($primary->isSimpleConditionalExpression()) {
$sql .= $primary->simpleConditionalExpression->dispatch($this);
} else if ($primary->isConditionalExpression()) {
$condExpr = $primary->conditionalExpression;
$sql .= '(' . implode(
' OR ', array_map(array($this, 'walkConditionalTerm'), $condExpr->conditionalTerms)
) . ')';
}
return $sql;
}
@ -1267,12 +1261,12 @@ class SqlWalker implements TreeWalker
public function walkExistsExpression($existsExpr)
{
$sql = ($existsExpr->not) ? 'NOT ' : '';
$sql .= 'EXISTS (' . $this->walkSubselect($existsExpr->subselect) . ')';
return $sql;
}
/**
* Walks down a CollectionMemberExpression AST node, thereby generating the appropriate SQL.
*
@ -1297,7 +1291,7 @@ class SqlWalker implements TreeWalker
$entity = $this->_query->getParameter($dqlParamKey);
} else {
//TODO
throw DoctrineException::notImplemented();
throw new \BadMethodCallException("Not implemented");
}
$assoc = $class->associationMappings[$fieldName];
@ -1319,7 +1313,7 @@ class SqlWalker implements TreeWalker
$sql .= $sourceTableAlias . '.' . $class->getQuotedColumnName($class->fieldNames[$targetColumn], $this->_platform)
. ' = '
. $targetTableAlias . '.' . $owningAssoc->getQuotedJoinColumnName($sourceColumn, $this->_platform);
. $targetTableAlias . '.' . $sourceColumn;
}
$sql .= ' AND ';
@ -1359,9 +1353,7 @@ class SqlWalker implements TreeWalker
foreach ($joinColumns as $joinColumn) {
if ($first) $first = false; else $sql .= ' AND ';
$sql .= $joinTableAlias . '.' . $owningAssoc->getQuotedJoinColumnName(
$joinColumn['name'], $this->_platform)
. ' = '
$sql .= $joinTableAlias . '.' . $joinColumn['name'] . ' = '
. $sourceTableAlias . '.' . $referencedColumnClass->getQuotedColumnName(
$referencedColumnClass->fieldNames[$joinColumn['referencedColumnName']],
$this->_platform);
@ -1377,8 +1369,7 @@ class SqlWalker implements TreeWalker
foreach ($joinColumns as $joinColumn) {
if ($first) $first = false; else $sql .= ' AND ';
$sql .= $joinTableAlias . '.' . $owningAssoc->getQuotedJoinColumnName($joinColumn['name'], $this->_platform)
. ' = '
$sql .= $joinTableAlias . '.' . $joinColumn['name'] . ' = '
. $targetTableAlias . '.' . $referencedColumnClass->getQuotedColumnName(
$referencedColumnClass->fieldNames[$joinColumn['referencedColumnName']],
$this->_platform);
@ -1409,7 +1400,7 @@ class SqlWalker implements TreeWalker
{
$sizeFunc = new AST\Functions\SizeFunction('size');
$sizeFunc->collectionPathExpression = $emptyCollCompExpr->expression;
return $sizeFunc->getSql($this) . ($emptyCollCompExpr->not ? ' > 0' : ' = 0');
}
@ -1423,7 +1414,7 @@ class SqlWalker implements TreeWalker
{
$sql = '';
$innerExpr = $nullCompExpr->expression;
if ($innerExpr instanceof AST\InputParameter) {
$dqlParamKey = $innerExpr->name;
$this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++);
@ -1431,9 +1422,9 @@ class SqlWalker implements TreeWalker
} else {
$sql .= $this->walkPathExpression($innerExpr);
}
$sql .= ' IS' . ($nullCompExpr->not ? ' NOT' : '') . ' NULL';
return $sql;
}
@ -1445,20 +1436,20 @@ class SqlWalker implements TreeWalker
*/
public function walkInExpression($inExpr)
{
$sql = $this->walkPathExpression($inExpr->pathExpression)
$sql = $this->walkPathExpression($inExpr->pathExpression)
. ($inExpr->not ? ' NOT' : '') . ' IN (';
if ($inExpr->subselect) {
$sql .= $this->walkSubselect($inExpr->subselect);
} else {
$sql .= implode(', ', array_map(array($this, 'walkInParameter'), $inExpr->literals));
}
$sql .= ')';
return $sql;
}
public function walkInParameter($inParam)
{
return $inParam instanceof AST\InputParameter ?
@ -1484,7 +1475,7 @@ class SqlWalker implements TreeWalker
case AST\Literal::NUMERIC:
return $literal->value;
default:
throw QueryException::invalidLiteral($literal);
throw QueryException::invalidLiteral($literal);
}
}
@ -1497,12 +1488,12 @@ class SqlWalker implements TreeWalker
public function walkBetweenExpression($betweenExpr)
{
$sql = $this->walkArithmeticExpression($betweenExpr->expression);
if ($betweenExpr->not) $sql .= ' NOT';
$sql .= ' BETWEEN ' . $this->walkArithmeticExpression($betweenExpr->leftBetweenExpression)
. ' AND ' . $this->walkArithmeticExpression($betweenExpr->rightBetweenExpression);
return $sql;
}
@ -1516,7 +1507,7 @@ class SqlWalker implements TreeWalker
{
$stringExpr = $likeExpr->stringExpression;
$sql = $stringExpr->dispatch($this) . ($likeExpr->not ? ' NOT' : '') . ' LIKE ';
if ($likeExpr->stringPattern instanceof AST\InputParameter) {
$inputParam = $likeExpr->stringPattern;
$dqlParamKey = $inputParam->name;
@ -1525,11 +1516,11 @@ class SqlWalker implements TreeWalker
} else {
$sql .= $this->_conn->quote($likeExpr->stringPattern);
}
if ($likeExpr->escapeChar) {
$sql .= ' ESCAPE ' . $this->_conn->quote($likeExpr->escapeChar);
}
return $sql;
}
@ -1561,7 +1552,7 @@ class SqlWalker implements TreeWalker
} else {
$sql .= is_numeric($leftExpr) ? $leftExpr : $this->_conn->quote($leftExpr);
}
$sql .= ' ' . $compExpr->operator . ' ';
if ($rightExpr instanceof AST\Node) {
@ -1582,7 +1573,7 @@ class SqlWalker implements TreeWalker
public function walkInputParameter($inputParam)
{
$this->_parserResult->addParameterMapping($inputParam->name, $this->_sqlParamIndex++);
return '?';
}
@ -1622,8 +1613,8 @@ class SqlWalker implements TreeWalker
*/
public function walkStringPrimary($stringPrimary)
{
return (is_string($stringPrimary))
? $this->_conn->quote($stringPrimary)
return (is_string($stringPrimary))
? $this->_conn->quote($stringPrimary)
: $stringPrimary->dispatch($this);
}
@ -1639,7 +1630,7 @@ class SqlWalker implements TreeWalker
$sql = ($factor->isNegativeSigned() ? '-' : ($factor->isPositiveSigned() ? '+' : ''));
$primary = $factor->arithmeticPrimary;
if ($primary instanceof AST\SimpleArithmeticExpression) {
$sql .= '(' . $this->walkSimpleArithmeticExpression($primary) . ')';
} else if ($primary instanceof AST\Node) {

View File

@ -21,8 +21,7 @@
namespace Doctrine\ORM\Tools;
use Doctrine\Common\DoctrineException,
Doctrine\ORM\Mapping\ClassMetadataInfo,
use Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Tools\Export\Driver\AbstractExporter,
Doctrine\Common\Util\Inflector;
@ -56,7 +55,7 @@ class ConvertDoctrine1Schema
* Constructor passes the directory or array of directories
* to convert the Doctrine 1 schema files from
*
* @param string $from
* @param string $from
* @author Jonathan Wage
*/
public function __construct($from)
@ -169,7 +168,7 @@ class ConvertDoctrine1Schema
$column['type'] = $this->_legacyTypeMap[$column['type']];
}
if ( ! \Doctrine\DBAL\Types\Type::hasType($column['type'])) {
throw DoctrineException::couldNotMapDoctrine1Type($column['type']);
throw ToolsException::couldNotMapDoctrine1Type($column['type']);
}
$fieldMapping = array();
@ -215,7 +214,7 @@ class ConvertDoctrine1Schema
foreach ($model['indexes'] as $name => $index) {
$type = (isset($index['type']) && $index['type'] == 'unique')
? 'uniqueConstraints' : 'indexes';
$metadata->primaryTable[$type][$name] = array(
'columns' => $index['fields']
);

View File

@ -25,21 +25,21 @@ namespace Doctrine\ORM\Tools\Export;
use Doctrine\ORM\EntityManager,
Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Mapping\ClassMetadata,
Doctrine\Common\DoctrineException;
Doctrine\ORM\Mapping\MappingException;
/**
* Class used for converting your mapping information between the
* Class used for converting your mapping information between the
* supported formats: yaml, xml, and php/annotation.
*
* [php]
* // Unify all your mapping information which is written in php, xml, yml
* // and convert it to a single set of yaml files.
*
*
* $cme = new Doctrine\ORM\Tools\Export\ClassMetadataExporter();
* $cme->addMappingSource(__DIR__ . '/Entities', 'php');
* $cme->addMappingSource(__DIR__ . '/xml', 'xml');
* $cme->addMappingSource(__DIR__ . '/yaml', 'yaml');
*
*
* $exporter = $cme->getExporter('yaml');
* $exporter->setOutputDir(__DIR__ . '/new_yaml');
*
@ -89,7 +89,7 @@ class ClassMetadataExporter
public function addMappingSource($source, $type)
{
if ( ! isset($this->_mappingDrivers[$type])) {
throw DoctrineException::invalidMappingDriverType($type);
throw ExportException::invalidMappingDriverType($type);
}
$driver = $this->getMappingDriver($type, $source);
@ -114,17 +114,17 @@ class ClassMetadataExporter
}
$class = $this->_mappingDrivers[$type];
if (is_subclass_of($class, 'Doctrine\ORM\Mapping\Driver\AbstractFileDriver')) {
if (is_null($source)) {
throw DoctrineException::fileMappingDriversRequireDirectoryPath();
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath();
}
$driver = new $class($source);
} else if ($class == 'Doctrine\ORM\Mapping\Driver\AnnotationDriver') {
$reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache);
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, $source);
} else {
$driver = new $class($source);
@ -158,16 +158,16 @@ class ClassMetadataExporter
list($source, $driver) = $d;
$allClasses = $driver->getAllClassNames();
foreach ($allClasses as $className) {
if (class_exists($className, false)) {
$metadata = new ClassMetadata($className);
} else {
$metadata = new ClassMetadataInfo($className);
$metadata = new ClassMetadataInfo($className);
}
$driver->loadMetadataForClass($className, $metadata);
if ( ! $metadata->isMappedSuperclass) {
$classes[$metadata->name] = $metadata;
}
@ -187,11 +187,11 @@ class ClassMetadataExporter
public function getExporter($type, $source = null)
{
if ( ! isset($this->_exporterDrivers[$type])) {
throw DoctrineException::invalidExporterDriverType($type);
throw ExportException::invalidExporterDriverType($type);
}
$class = $this->_exporterDrivers[$type];
return new $class($source);
}
}

View File

@ -21,7 +21,8 @@
namespace Doctrine\ORM\Tools;
use Doctrine\DBAL\Types\Type,
use Doctrine\ORM\ORMException,
Doctrine\DBAL\Types\Type,
Doctrine\ORM\EntityManager,
Doctrine\ORM\Internal\CommitOrderCalculator;
@ -80,7 +81,7 @@ class SchemaTool
{
$createSchemaSql = $this->getCreateSchemaSql($classes);
$conn = $this->_em->getConnection();
foreach ($createSchemaSql as $sql) {
$conn->execute($sql);
}
@ -130,11 +131,11 @@ class SchemaTool
}
$columns = array(); // table columns
if ($class->isInheritanceTypeSingleTable()) {
$columns = $this->_gatherColumns($class, $table);
$this->_gatherRelationsSql($class, $table, $schema);
// Add the discriminator column
$discrColumnDef = $this->_getDiscriminatorColumnDefinition($class, $table);
@ -143,7 +144,7 @@ class SchemaTool
// Parent class information is already contained in this class
$processedClasses[$parentClassName] = true;
}
foreach ($class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName);
$this->_gatherColumns($subClass, $table);
@ -175,12 +176,12 @@ class SchemaTool
$idMapping = $class->fieldMappings[$class->identifier[0]];
$this->_gatherColumn($class, $idMapping, $table);
$columnName = $class->getQuotedColumnName($class->identifier[0], $this->_platform);
$pkColumns[] = $columnName;
if ($table->isIdGeneratorIdentity()) {
$table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_NONE);
}
// Add a FK constraint on the ID column
$table->addUnnamedForeignKeyConstraint(
$this->_em->getClassMetadata($class->rootEntityName)->getQuotedTableName($this->_platform),
@ -191,18 +192,18 @@ class SchemaTool
$table->setPrimaryKey($pkColumns);
} else if ($class->isInheritanceTypeTablePerClass()) {
throw DoctrineException::notSupported();
throw ORMException::notSupported();
} else {
$this->_gatherColumns($class, $table);
$this->_gatherRelationsSql($class, $table, $schema);
}
if (isset($class->primaryTable['indexes'])) {
foreach ($class->primaryTable['indexes'] AS $indexName => $indexData) {
$table->addIndex($indexData['columns'], $indexName);
}
}
if (isset($class->primaryTable['uniqueConstraints'])) {
foreach ($class->primaryTable['uniqueConstraints'] AS $indexName => $indexData) {
$table->addUniqueIndex($indexData['columns'], $indexName);
@ -223,14 +224,14 @@ class SchemaTool
}
}
}
return $schema;
}
/**
* Gets a portable column definition as required by the DBAL for the discriminator
* column of a class.
*
*
* @param ClassMetadata $class
* @return array The portable column definition of the discriminator column as required by
* the DBAL.
@ -245,7 +246,7 @@ class SchemaTool
}
$table->addColumn(
$class->getQuotedDiscriminatorColumnName($this->_platform),
$discrColumn['name'],
$discrColumn['type'],
array('length' => $discrColumn['length'], 'notnull' => true)
);
@ -263,10 +264,10 @@ class SchemaTool
{
$columns = array();
$pkColumns = array();
foreach ($class->fieldMappings as $fieldName => $mapping) {
$column = $this->_gatherColumn($class, $mapping, $table);
if ($class->isIdentifier($mapping['fieldName'])) {
$pkColumns[] = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform);
}
@ -276,13 +277,13 @@ class SchemaTool
if(!$table->hasIndex('primary')) {
$table->setPrimaryKey($pkColumns);
}
return $columns;
}
/**
* Creates a column definition as required by the DBAL from an ORM field mapping definition.
*
*
* @param ClassMetadata $class The class that owns the field mapping.
* @param array $mapping The field mapping.
* @param Table $table
@ -307,15 +308,15 @@ class SchemaTool
if (isset($mapping['precision'])) {
$options['precision'] = $mapping['precision'];
}
if (isset($mapping['scale'])) {
$options['scale'] = $mapping['scale'];
}
if (isset($mapping['default'])) {
$options['default'] = $mapping['default'];
}
if (isset($mapping['columnDefinition'])) {
$options['columnDefinition'] = $mapping['columnDefinition'];
}
@ -336,7 +337,7 @@ class SchemaTool
/**
* Gathers the SQL for properly setting up the relations of the given class.
* This includes the SQL for foreign key constraints and join tables.
*
*
* @param ClassMetadata $class
* @param \Doctrine\DBAL\Schema\Table $table
* @param \Doctrine\DBAL\Schema\Schema $schema
@ -357,7 +358,7 @@ class SchemaTool
$this->_gatherRelationJoinColumns($mapping->getJoinColumns(), $table, $foreignClass, $mapping, $primaryKeyColumns, $uniqueConstraints);
} else if ($mapping->isOneToMany() && $mapping->isOwningSide) {
//... create join table, one-many through join table supported later
throw DoctrineException::notSupported();
throw ORMException::notSupported();
} else if ($mapping->isManyToMany() && $mapping->isOwningSide) {
// create join table
$joinTable = $mapping->getJoinTable();
@ -385,7 +386,7 @@ class SchemaTool
/**
* Gather columns and fk constraints that are required for one part of relationship.
*
*
* @param array $joinColumns
* @param \Doctrine\DBAL\Schema\Table $theJoinTable
* @param ClassMetadata $class
@ -400,12 +401,11 @@ class SchemaTool
$fkOptions = array();
foreach ($joinColumns as $joinColumn) {
// Note that this thing might be quoted, i.e. `foo`, [foo], ...
$columnName = $mapping->getQuotedJoinColumnName($joinColumn['name'], $this->_platform);
$columnName = $joinColumn['name'];
$referencedFieldName = $class->getFieldName($joinColumn['referencedColumnName']);
if (!$class->hasField($referencedFieldName)) {
throw new \Doctrine\Common\DoctrineException(
if ( ! $class->hasField($referencedFieldName)) {
throw new \Doctrine\ORM\ORMException(
"Column name `".$joinColumn['referencedColumnName']."` referenced for relation from ".
"$mapping->sourceEntityName towards $mapping->targetEntityName does not exist."
);
@ -455,7 +455,7 @@ class SchemaTool
$class->getQuotedTableName($this->_platform), $localColumns, $foreignColumns, $fkOptions
);
}
/**
* Drops the database schema for the given classes.
*
@ -470,15 +470,15 @@ class SchemaTool
{
$dropSchemaSql = $this->getDropSchemaSql($classes, $mode);
$conn = $this->_em->getConnection();
foreach ($dropSchemaSql as $sql) {
$conn->execute($sql);
}
}
/**
* Gets the SQL needed to drop the database schema for the given classes.
*
*
* @param array $classes
* @param string $mode
* @return array
@ -496,13 +496,13 @@ class SchemaTool
/**
* Drop all tables of the database connection.
*
*
* @return array
*/
private function _getDropSchemaTablesDatabaseMode($classes)
{
$conn = $this->_em->getConnection();
$sm = $conn->getSchemaManager();
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
@ -521,7 +521,7 @@ class SchemaTool
private function _getDropSchemaTablesMetadataMode(array $classes)
{
$orderedTables = array();
$commitOrder = $this->_getCommitOrder($classes);
$associationTables = $this->_getAssociationTables($commitOrder);
@ -546,11 +546,11 @@ class SchemaTool
return $orderedTables;
}
/**
* Updates the database schema of the given classes by comparing the ClassMetadata
* instances to the current database schema that is inspected.
*
*
* @param array $classes
* @return void
*/
@ -563,11 +563,11 @@ class SchemaTool
$conn->execute($sql);
}
}
/**
* Gets the sequence of SQL statements that need to be performed in order
* to bring the given class mappings in-synch with the relational schema.
*
*
* @param array $classes The classes to consider.
* @return array The sequence of SQL statements.
*/
@ -587,23 +587,23 @@ class SchemaTool
return $schemaDiff->toSql($this->_platform);
}
}
private function _getCommitOrder(array $classes)
{
$calc = new CommitOrderCalculator;
// Calculate dependencies
foreach ($classes as $class) {
$calc->addClass($class);
foreach ($class->associationMappings as $assoc) {
if ($assoc->isOwningSide) {
$targetClass = $this->_em->getClassMetadata($assoc->targetEntityName);
if ( ! $calc->hasClass($targetClass->name)) {
$calc->addClass($targetClass);
}
// add dependency ($targetClass before $class)
$calc->addDependency($targetClass, $class);
}
@ -612,11 +612,11 @@ class SchemaTool
return $calc->getCommitOrder();
}
private function _getAssociationTables(array $classes)
{
$associationTables = array();
foreach ($classes as $class) {
foreach ($class->associationMappings as $assoc) {
if ($assoc->isOwningSide && $assoc->isManyToMany()) {
@ -624,7 +624,7 @@ class SchemaTool
}
}
}
return $associationTables;
}
}

View File

@ -375,7 +375,7 @@ class UnitOfWork implements PropertyChangedListener
*
* @Internal
*
* @Todo inline _computeChangeSet to here?
* @Todo inline _computeEntityChanges to here?
*
* @param ClassMetadata $class
* @param object $entity

View File

@ -23,7 +23,6 @@ class AllTests
{
$suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Common Tests');
$suite->addTestSuite('Doctrine\Tests\Common\DoctrineExceptionTest');
$suite->addTestSuite('Doctrine\Tests\Common\ClassLoaderTest');
$suite->addTestSuite('Doctrine\Tests\Common\EventManagerTest');

View File

@ -11,15 +11,15 @@ class ClassLoaderTest extends \Doctrine\Tests\DoctrineTestCase
{
public function testGlobalClassLoaderThrowsExceptionIfPutInChain()
{
$this->setExpectedException('Doctrine\Common\DoctrineException');
$this->setExpectedException('Doctrine\Common\CommonException');
$classLoader1 = new IsolatedClassLoader('Foo');
$classLoader1->register();
$globalClassLoader = new GlobalClassLoader;
$globalClassLoader->register();
}
/*public function testIsolatedClassLoaderReturnsFalseOnClassExists()
{
$classLoader = new IsolatedClassLoader('ClassLoaderTest');

View File

@ -1,39 +0,0 @@
<?php
namespace Doctrine\Tests\Common;
require_once __DIR__ . '/../TestInit.php';
class DoctrineExceptionTest extends \Doctrine\Tests\DoctrineTestCase
{
/*public function testStaticCall()
{
$e = \Doctrine\Common\DoctrineException::testingStaticCallBuildsErrorMessageWithParams('param1', 'param2');
$this->assertEquals($e->getMessage(), "Testing static call builds error message with params ('param1', 'param2')");
}*/
public function testInnerException()
{
$e1 = \Doctrine\Common\DoctrineException::testException();
$e2 = \Doctrine\Common\DoctrineException::testException2('param1', $e1);
$this->assertEquals($e1, $e2->getPrevious());
}
public function testNotImplemented()
{
$e = \Doctrine\Common\DoctrineException::notImplemented('testMethod', 'SomeClass');
$this->assertEquals("The method 'testMethod' is not implemented in class 'SomeClass'.", $e->getMessage());
}
public function testGetExceptionMessage()
{
$this->assertEquals('The query contains more than one result.', \Doctrine\Common\DoctrineException::getExceptionMessage('QueryException#nonUniqueResult'));
}
public function testUseGetExceptionMessage()
{
$q = \Doctrine\ORM\Query\QueryException::nonUniqueResult();
$this->assertEquals('The query contains more than one result.', $q->getMessage());
}
}

View File

@ -6,19 +6,19 @@ use Doctrine\DBAL\Platforms;
class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform
{
public function getBooleanTypeDeclarationSql(array $columnDef) {}
public function getIntegerTypeDeclarationSql(array $columnDef) {}
public function getBigIntTypeDeclarationSql(array $columnDef) {}
public function getSmallIntTypeDeclarationSql(array $columnDef) {}
public function _getCommonIntegerTypeDeclarationSql(array $columnDef) {}
public function getBooleanTypeDeclarationSQL(array $columnDef) {}
public function getIntegerTypeDeclarationSQL(array $columnDef) {}
public function getBigIntTypeDeclarationSQL(array $columnDef) {}
public function getSmallIntTypeDeclarationSQL(array $columnDef) {}
public function _getCommonIntegerTypeDeclarationSQL(array $columnDef) {}
public function getVarcharTypeDeclarationSql(array $field)
public function getVarcharTypeDeclarationSQL(array $field)
{
return "DUMMYVARCHAR()";
}
/** @override */
public function getClobTypeDeclarationSql(array $field)
public function getClobTypeDeclarationSQL(array $field)
{
return 'DUMMYCLOB';
}

View File

@ -21,7 +21,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$table = new \Doctrine\DBAL\Schema\Table('test');
$this->setExpectedException('Doctrine\DBAL\DBALException');
$sql = $this->_platform->getCreateTableSql($table);
$sql = $this->_platform->getCreateTableSQL($table);
}
public function testGeneratesTableCreationSql()
@ -32,7 +32,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$table->setPrimaryKey(array('id'));
$table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_IDENTITY);
$sql = $this->_platform->getCreateTableSql($table);
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals($this->getGenerateTableSql(), $sql[0]);
}
@ -45,7 +45,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255));
$table->addUniqueIndex(array("foo", "bar"));
$sql = $this->_platform->getCreateTableSql($table);
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals($this->getGenerateTableWithMultiColumnUniqueIndexSql(), $sql);
}
@ -57,7 +57,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->assertEquals(
$this->getGenerateIndexSql(),
$this->_platform->getCreateIndexSql($indexDef, 'mytable')
$this->_platform->getCreateIndexSQL($indexDef, 'mytable')
);
}
@ -67,7 +67,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
$indexDef = new \Doctrine\DBAL\Schema\Index('index_name', array('test', 'test2'), true);
$sql = $this->_platform->getCreateIndexSql($indexDef, 'test');
$sql = $this->_platform->getCreateIndexSQL($indexDef, 'test');
$this->assertEquals($this->getGenerateUniqueIndexSql(), $sql);
}
@ -77,7 +77,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name_id'), 'other_table', array('id'), '');
$sql = $this->_platform->getCreateForeignKeySql($fk, 'test');
$sql = $this->_platform->getCreateForeignKeySQL($fk, 'test');
$this->assertEquals($sql, $this->getGenerateForeignKeySql());
}
@ -86,15 +86,15 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
public function testGeneratesConstraintCreationSql()
{
$idx = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, false);
$sql = $this->_platform->getCreateConstraintSql($idx, 'test');
$sql = $this->_platform->getCreateConstraintSQL($idx, 'test');
$this->assertEquals($this->getGenerateConstraintUniqueIndexSql(), $sql);
$pk = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, true);
$sql = $this->_platform->getCreateConstraintSql($pk, 'test');
$sql = $this->_platform->getCreateConstraintSQL($pk, 'test');
$this->assertEquals($this->getGenerateConstraintPrimaryIndexSql(), $sql);
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk');
$sql = $this->_platform->getCreateConstraintSql($fk, 'test');
$sql = $this->_platform->getCreateConstraintSQL($fk, 'test');
$this->assertEquals($this->getGenerateConstraintForeignKeySql(), $sql);
}
@ -132,7 +132,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$tableDiff->removedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', \Doctrine\DBAL\Types\Type::getType('integer'));
$tableDiff->changedColumns['bar'] = $columnDiff;
$sql = $this->_platform->getAlterTableSql($tableDiff);
$sql = $this->_platform->getAlterTableSQL($tableDiff);
$this->assertEquals($expectedSql, $sql);
}
@ -140,6 +140,6 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
public function testGetCustomColumnDeclarationSql()
{
$field = array('columnDefinition' => 'MEDIUMINT(6) UNSIGNED');
$this->assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->_platform->getColumnDeclarationSql('foo', $field));
$this->assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->_platform->getColumnDeclarationSQL('foo', $field));
}
}

View File

@ -44,43 +44,43 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
{
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL REPEATABLE READ',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
);
}
public function testGeneratesDDLSnippets()
{
$this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSql());
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSql('foobar'));
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSql('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSql('foobar'));
$this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSQL());
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
}
public function testGeneratesTypeDeclarationForIntegers()
{
$this->assertEquals(
'INT',
$this->_platform->getIntegerTypeDeclarationSql(array())
$this->_platform->getIntegerTypeDeclarationSQL(array())
);
$this->assertEquals(
'INT AUTO_INCREMENT',
$this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true)
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
));
$this->assertEquals(
'INT AUTO_INCREMENT',
$this->_platform->getIntegerTypeDeclarationSql(
$this->_platform->getIntegerTypeDeclarationSQL(
array('autoincrement' => true, 'primary' => true)
));
}
@ -89,17 +89,17 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
{
$this->assertEquals(
'CHAR(10)',
$this->_platform->getVarcharTypeDeclarationSql(
$this->_platform->getVarcharTypeDeclarationSQL(
array('length' => 10, 'fixed' => true)
));
$this->assertEquals(
'VARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)),
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
'Variable string declaration is not correct'
);
$this->assertEquals(
'TEXT',
$this->_platform->getVarcharTypeDeclarationSql(array()),
$this->_platform->getVarcharTypeDeclarationSQL(array()),
'Long string declaration is not correct'
);
}

View File

@ -19,7 +19,7 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$table = new \Doctrine\DBAL\Schema\Table("Foo");
$table->addColumn("Bar", "integer");
$sql = $this->_platform->getCreateTableSql($table);
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) ENGINE = InnoDB', array_shift($sql));
}
@ -53,45 +53,45 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
{
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED),
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED),
''
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
);
}
public function testGeneratesDDLSnippets()
{
$this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSql());
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSql('foobar'));
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSql('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSql('foobar'));
$this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSQL());
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
}
public function testGeneratesTypeDeclarationForIntegers()
{
$this->assertEquals(
'INT',
$this->_platform->getIntegerTypeDeclarationSql(array())
$this->_platform->getIntegerTypeDeclarationSQL(array())
);
$this->assertEquals(
'INT AUTO_INCREMENT',
$this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true)
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
));
$this->assertEquals(
'INT AUTO_INCREMENT',
$this->_platform->getIntegerTypeDeclarationSql(
$this->_platform->getIntegerTypeDeclarationSQL(
array('autoincrement' => true, 'primary' => true)
));
}
@ -100,17 +100,17 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
{
$this->assertEquals(
'CHAR(10)',
$this->_platform->getVarcharTypeDeclarationSql(
$this->_platform->getVarcharTypeDeclarationSQL(
array('length' => 10, 'fixed' => true)
));
$this->assertEquals(
'VARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)),
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
'Variable string declaration is not correct'
);
$this->assertEquals(
'VARCHAR(255)',
$this->_platform->getVarcharTypeDeclarationSql(array()),
$this->_platform->getVarcharTypeDeclarationSQL(array()),
'Long string declaration is not correct'
);
}
@ -162,8 +162,8 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
*/
public function testGetDateTimeTypeDeclarationSql()
{
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSql(array('version' => false)));
$this->assertEquals("TIMESTAMP", $this->_platform->getDateTimeTypeDeclarationSql(array('version' => true)));
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSql(array()));
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => false)));
$this->assertEquals("TIMESTAMP", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true)));
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array()));
}
}

View File

@ -55,19 +55,19 @@ class OraclePlatformTest extends AbstractPlatformTestCase
{
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
);
}
@ -76,7 +76,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase
*/
public function testShowDatabasesThrowsException()
{
$this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSql());
$this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSQL());
}
/**
@ -84,32 +84,32 @@ class OraclePlatformTest extends AbstractPlatformTestCase
*/
public function testCreateDatabaseThrowsException()
{
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSql('foobar'));
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
}
public function testDropDatabaseThrowsException()
{
$this->assertEquals('DROP USER foobar CASCADE', $this->_platform->getDropDatabaseSql('foobar'));
$this->assertEquals('DROP USER foobar CASCADE', $this->_platform->getDropDatabaseSQL('foobar'));
}
public function testDropTable()
{
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSql('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
}
public function testGeneratesTypeDeclarationForIntegers()
{
$this->assertEquals(
'NUMBER(10)',
$this->_platform->getIntegerTypeDeclarationSql(array())
$this->_platform->getIntegerTypeDeclarationSQL(array())
);
$this->assertEquals(
'NUMBER(10)',
$this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true)
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
));
$this->assertEquals(
'NUMBER(10)',
$this->_platform->getIntegerTypeDeclarationSql(
$this->_platform->getIntegerTypeDeclarationSQL(
array('autoincrement' => true, 'primary' => true)
));
}
@ -118,17 +118,17 @@ class OraclePlatformTest extends AbstractPlatformTestCase
{
$this->assertEquals(
'CHAR(10)',
$this->_platform->getVarcharTypeDeclarationSql(
$this->_platform->getVarcharTypeDeclarationSQL(
array('length' => 10, 'fixed' => true)
));
$this->assertEquals(
'VARCHAR2(50)',
$this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)),
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
'Variable string declaration is not correct'
);
$this->assertEquals(
'VARCHAR2(4000)',
$this->_platform->getVarcharTypeDeclarationSql(array()),
$this->_platform->getVarcharTypeDeclarationSQL(array()),
'Long string declaration is not correct'
);
}

View File

@ -57,7 +57,7 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
);
$this->assertEquals(
"CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE",
$this->_platform->getForeignKeyDeclarationSql($foreignKey)
$this->_platform->getForeignKeyDeclarationSQL($foreignKey)
);
}
@ -74,42 +74,42 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
{
$this->assertEquals(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
$this->_platform->getSetTransactionIsolationSql(Connection::TRANSACTION_READ_UNCOMMITTED)
$this->_platform->getSetTransactionIsolationSQL(Connection::TRANSACTION_READ_UNCOMMITTED)
);
$this->assertEquals(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED',
$this->_platform->getSetTransactionIsolationSql(Connection::TRANSACTION_READ_COMMITTED)
$this->_platform->getSetTransactionIsolationSQL(Connection::TRANSACTION_READ_COMMITTED)
);
$this->assertEquals(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ',
$this->_platform->getSetTransactionIsolationSql(Connection::TRANSACTION_REPEATABLE_READ)
$this->_platform->getSetTransactionIsolationSQL(Connection::TRANSACTION_REPEATABLE_READ)
);
$this->assertEquals(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSql(Connection::TRANSACTION_SERIALIZABLE)
$this->_platform->getSetTransactionIsolationSQL(Connection::TRANSACTION_SERIALIZABLE)
);
}
public function testGeneratesDDLSnippets()
{
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSql('foobar'));
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSql('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSql('foobar'));
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
}
public function testGeneratesTypeDeclarationForIntegers()
{
$this->assertEquals(
'INT',
$this->_platform->getIntegerTypeDeclarationSql(array())
$this->_platform->getIntegerTypeDeclarationSQL(array())
);
$this->assertEquals(
'SERIAL',
$this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true)
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
));
$this->assertEquals(
'SERIAL',
$this->_platform->getIntegerTypeDeclarationSql(
$this->_platform->getIntegerTypeDeclarationSQL(
array('autoincrement' => true, 'primary' => true)
));
}
@ -118,17 +118,17 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
{
$this->assertEquals(
'CHAR(10)',
$this->_platform->getVarcharTypeDeclarationSql(
$this->_platform->getVarcharTypeDeclarationSQL(
array('length' => 10, 'fixed' => true))
);
$this->assertEquals(
'VARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)),
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
'Variable string declaration is not correct'
);
$this->assertEquals(
'TEXT',
$this->_platform->getVarcharTypeDeclarationSql(array()),
$this->_platform->getVarcharTypeDeclarationSQL(array()),
'Long string declaration is not correct'
);
}
@ -143,15 +143,15 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
$sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1);
$this->assertEquals(
'CREATE SEQUENCE myseq INCREMENT BY 20 MINVALUE 1 START 1',
$this->_platform->getCreateSequenceSql($sequence)
$this->_platform->getCreateSequenceSQL($sequence)
);
$this->assertEquals(
'DROP SEQUENCE myseq',
$this->_platform->getDropSequenceSql('myseq')
$this->_platform->getDropSequenceSQL('myseq')
);
$this->assertEquals(
"SELECT NEXTVAL('myseq')",
$this->_platform->getSequenceNextValSql('myseq')
$this->_platform->getSequenceNextValSQL('myseq')
);
}

View File

@ -36,10 +36,10 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
public function testGeneratesTransactionCommands()
{
$this->assertEquals('PRAGMA read_uncommitted = 0', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED));
$this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED));
$this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ));
$this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE));
$this->assertEquals('PRAGMA read_uncommitted = 0', $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED));
$this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED));
$this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ));
$this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE));
}
public function testPrefersIdentityColumns()
@ -51,15 +51,15 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
{
$this->assertEquals(
'INTEGER',
$this->_platform->getIntegerTypeDeclarationSql(array())
$this->_platform->getIntegerTypeDeclarationSQL(array())
);
$this->assertEquals(
'INTEGER AUTOINCREMENT',
$this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true))
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true))
);
$this->assertEquals(
'INTEGER PRIMARY KEY AUTOINCREMENT',
$this->_platform->getIntegerTypeDeclarationSql(
$this->_platform->getIntegerTypeDeclarationSQL(
array('autoincrement' => true, 'primary' => true))
);
}
@ -68,17 +68,17 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
{
$this->assertEquals(
'CHAR(10)',
$this->_platform->getVarcharTypeDeclarationSql(
$this->_platform->getVarcharTypeDeclarationSQL(
array('length' => 10, 'fixed' => true))
);
$this->assertEquals(
'VARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)),
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
'Variable string declaration is not correct'
);
$this->assertEquals(
'TEXT',
$this->_platform->getVarcharTypeDeclarationSql(array()),
$this->_platform->getVarcharTypeDeclarationSQL(array()),
'Long string declaration is not correct'
);
}

View File

@ -35,31 +35,31 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
}
/** @override */
public function getSequenceNextValSql($sequenceName)
public function getSequenceNextValSQL($sequenceName)
{
return $this->_sequenceNextValSql;
}
/** @override */
public function getBooleanTypeDeclarationSql(array $field) {}
public function getBooleanTypeDeclarationSQL(array $field) {}
/** @override */
public function getIntegerTypeDeclarationSql(array $field) {}
public function getIntegerTypeDeclarationSQL(array $field) {}
/** @override */
public function getBigIntTypeDeclarationSql(array $field) {}
public function getBigIntTypeDeclarationSQL(array $field) {}
/** @override */
public function getSmallIntTypeDeclarationSql(array $field) {}
public function getSmallIntTypeDeclarationSQL(array $field) {}
/** @override */
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef) {}
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) {}
/** @override */
public function getVarcharTypeDeclarationSql(array $field) {}
public function getVarcharTypeDeclarationSQL(array $field) {}
/** @override */
public function getClobTypeDeclarationSql(array $field) {}
public function getClobTypeDeclarationSQL(array $field) {}
/* MOCK API */

View File

@ -0,0 +1,142 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
require_once __DIR__ . '/../../../TestInit.php';
class DDC258Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Super'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Class1'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Class2'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Class3'),
));
}
/**
* @group DDC-258
*/
public function testIssue()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
$c1 = new DDC258Class1();
$c1->title = "Foo";
$c1->description = "Foo";
$c2 = new DDC258Class2();
$c2->title = "Bar";
$c2->description = "Bar";
$c2->text = "Bar";
$c3 = new DDC258Class3();
$c3->apples = "Baz";
$c3->bananas = "Baz";
$this->_em->persist($c1);
$this->_em->persist($c2);
$this->_em->persist($c3);
$this->_em->flush();
$this->_em->clear();
$e2 = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC258Super', $c2->id);
$this->assertType('Doctrine\Tests\ORM\Functional\Ticket\DDC258Class2', $e2);
$this->assertEquals('Bar', $e2->title);
$this->assertEquals('Bar', $e2->description);
$this->assertEquals('Bar', $e2->text);
$all = $this->_em->getRepository(__NAMESPACE__.'\DDC258Super')->findAll();
foreach ($all as $obj) {
if ($obj instanceof DDC258Class1) {
$this->assertEquals('Foo', $obj->title);
$this->assertEquals('Foo', $obj->description);
} else if ($obj instanceof DDC258Class2) {
$this->assertTrue($e2 === $obj);
$this->assertEquals('Bar', $obj->title);
$this->assertEquals('Bar', $obj->description);
$this->assertEquals('Bar', $obj->text);
} else if ($obj instanceof DDC258Class3) {
$this->assertEquals('Baz', $obj->apples);
$this->assertEquals('Baz', $obj->bananas);
} else {
$this->fail('Instance of DDC258Class1, DDC258Class2 or DDC258Class3 expected.');
}
}
}
}
/**
* @Entity
* @Table(name="DDC258Super")
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="type", type="string")
* @DiscriminatorMap({"class1" = "DDC258Class1", "class2" = "DDC258Class2", "class3"="DDC258Class3"})
*/
abstract class DDC258Super
{
/**
* @Id @Column(name="id", type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
}
/**
* @Entity
*/
class DDC258Class1 extends DDC258Super
{
/**
* @Column(name="title", type="string", length="150")
*/
public $title;
/**
* @Column(name="content", type="string", length="500")
*/
public $description;
}
/**
* @Entity
*/
class DDC258Class2 extends DDC258Super
{
/**
* @Column(name="title", type="string", length="150")
*/
public $title;
/**
* @Column(name="content", type="string", length="500")
*/
public $description;
/**
* @Column(name="text", type="text")
*/
public $text;
}
/**
* An extra class to demonstrate why title and description aren't in Super
*
* @Entity
*/
class DDC258Class3 extends DDC258Super
{
/**
* @Column(name="title", type="string", length="150")
*/
public $apples;
/**
* @Column(name="content", type="string", length="500")
*/
public $bananas;
}

View File

@ -2,8 +2,7 @@
namespace Doctrine\Tests\ORM\Query;
use Doctrine\ORM\Query,
Doctrine\Common\DoctrineException;
use Doctrine\ORM\Query;
require_once __DIR__ . '/../../TestInit.php';
@ -44,7 +43,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
'SELECT c0_.id AS id0 FROM cms_users c0_'
);
}
public function testSupportsSelectForOneNestedField()
{
$this->assertSqlGeneration(
@ -52,7 +51,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
'SELECT c0_.id AS id0 FROM cms_articles c1_ INNER JOIN cms_users c0_ ON c1_.user_id = c0_.id'
);
}
public function testSupportsSelectForAllNestedField()
{
$this->assertSqlGeneration(
@ -236,7 +235,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
'SELECT c0_.id AS id0, c1_.id AS id1, c2_.phonenumber AS phonenumber2, c3_.id AS id3 FROM cms_users c0_ INNER JOIN cms_articles c1_ ON c0_.id = c1_.user_id INNER JOIN cms_phonenumbers c2_ ON c0_.id = c2_.user_id INNER JOIN cms_comments c3_ ON c1_.id = c3_.article_id'
);
}
public function testSupportsTrimFunction()
{
$this->assertSqlGeneration(
@ -330,29 +329,29 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
// "Get all users who have $phone as a phonenumber." (*cough* doesnt really make sense...)
$q1 = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.phonenumbers');
$q1->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);
$phone = new \Doctrine\Tests\Models\CMS\CmsPhonenumber;
$phone->phonenumber = 101;
$q1->setParameter('param', $phone);
$this->assertEquals(
'SELECT c0_.id AS id0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_phonenumbers c1_ WHERE c0_.id = c1_.user_id AND c1_.phonenumber = ?)',
$q1->getSql()
);
// "Get all users who are members of $group."
$q2 = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.groups');
$q2->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);
$group = new \Doctrine\Tests\Models\CMS\CmsGroup;
$group->id = 101;
$q2->setParameter('param', $group);
$this->assertEquals(
'SELECT c0_.id AS id0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.user_id = c0_.id WHERE c1_.group_id = c2_.id AND c2_.id = ?)',
$q2->getSql()
);
// "Get all persons who have $person as a friend."
// Tough one: Many-many self-referencing ("friends") with class table inheritance
$q3 = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p WHERE :param MEMBER OF p.friends');
@ -423,7 +422,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ LIMIT 10 OFFSET 0', $q->getSql());
}
public function testSizeFunction()
{
$this->assertSqlGeneration(
@ -431,7 +430,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (SELECT COUNT(*) FROM cms_phonenumbers c1_ WHERE c1_.user_id = c0_.id) > 1"
);
}
public function testSizeFunctionSupportsManyToMany()
{
$this->assertSqlGeneration(
@ -451,7 +450,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (SELECT COUNT(*) FROM cms_phonenumbers c1_ WHERE c1_.user_id = c0_.id) > 0"
);
}
public function testNestedExpressions()
{
$this->assertSqlGeneration(
@ -459,7 +458,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.id > 10 AND c0_.id < 42 AND ((c0_.id * 2) > 5)"
);
}
public function testNestedExpressions2()
{
$this->assertSqlGeneration(
@ -467,7 +466,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (c0_.id > 10) AND (c0_.id < 42 AND ((c0_.id * 2) > 5)) OR c0_.id <> 42"
);
}
public function testNestedExpressions3()
{
$this->assertSqlGeneration(
@ -475,7 +474,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (c0_.id > 10) AND (c0_.id BETWEEN 1 AND 10 OR c0_.id IN (1, 2, 3, 4, 5))"
);
}
public function testOrderByCollectionAssociationSize()
{
$this->assertSqlGeneration(
@ -483,40 +482,40 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT COUNT(*) FROM cms_articles c1_ WHERE c1_.user_id = c0_.id) AS sclr4 FROM cms_users c0_ ORDER BY sclr4 ASC"
);
}
public function testBooleanLiteralInWhereOnSqlite()
{
$oldPlat = $this->_em->getConnection()->getDatabasePlatform();
$this->_em->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\SqlitePlatform);
$this->assertSqlGeneration(
"SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true",
"SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 1"
);
$this->assertSqlGeneration(
"SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = false",
"SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 0"
);
$this->_em->getConnection()->setDatabasePlatform($oldPlat);
}
public function testBooleanLiteralInWhereOnPostgres()
{
$oldPlat = $this->_em->getConnection()->getDatabasePlatform();
$this->_em->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
$this->assertSqlGeneration(
"SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true",
"SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 'true'"
);
$this->assertSqlGeneration(
"SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = false",
"SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 'false'"
);
$this->_em->getConnection()->setDatabasePlatform($oldPlat);
}
@ -546,7 +545,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON c0_.id = c1_.user_id WHERE c1_.id IS NULL"
);
}
/**
* @group DDC-339
*/