Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Delegate quoteIdentifier operation to quoteIdentifierChain #233

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/Adapter/Platform/AbstractPlatform.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see http://github.com/zendframework/zend-db for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://github.com/zendframework/zend-db/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Db\Adapter\Platform;
Expand Down Expand Up @@ -66,21 +64,29 @@ public function quoteIdentifierInFragment($identifier, array $safeWords = [])
*/
public function quoteIdentifier($identifier)
{
if (! $this->quoteIdentifiers) {
return $identifier;
}

return $this->quoteIdentifier[0]
. str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $identifier)
. $this->quoteIdentifier[1];
return $this->quoteIdentifierChain([$identifier]);
}

/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '"' . implode('"."', (array) str_replace('"', '\\"', $identifierChain)) . '"';
if (is_string($identifierChain)) {
$identifierChain = [$identifierChain];
}

if (! $this->quoteIdentifiers) {
return implode($this->getIdentifierSeparator(), $identifierChain);
}

/** @var array $identifierChain */
foreach ($identifierChain as $key => $identifier) {
$identifierChain[$key] = str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $identifier);
}
$chainGlue = $this->quoteIdentifier[1] . $this->getIdentifierSeparator() . $this->quoteIdentifier[0];

return $this->quoteIdentifier[0] . implode($chainGlue, $identifierChain) . $this->quoteIdentifier[1];
}

/**
Expand All @@ -105,8 +111,11 @@ public function getQuoteValueSymbol()
public function quoteValue($value)
{
trigger_error(
'Attempting to quote a value in ' . get_class($this) .
' without extension/driver support can introduce security vulnerabilities in a production environment'
sprintf(
'Attempting to quote a value in %s without extension/driver support ' .
'can introduce security vulnerabilities in a production environment',
get_class($this)
)
);
return '\'' . addcslashes((string) $value, "\x00\n\r\\'\"\x1a") . '\'';
}
Expand Down
16 changes: 3 additions & 13 deletions src/Adapter/Platform/Mysql.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see http://github.com/zendframework/zend-db for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://github.com/zendframework/zend-db/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Db\Adapter\Platform;
Expand Down Expand Up @@ -69,14 +67,6 @@ public function getName()
return 'MySQL';
}

/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '`' . implode('`.`', (array) str_replace('`', '``', $identifierChain)) . '`';
}

/**
* {@inheritDoc}
*/
Expand Down
22 changes: 4 additions & 18 deletions src/Adapter/Platform/Oracle.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see http://github.com/zendframework/zend-db for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://github.com/zendframework/zend-db/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Db\Adapter\Platform;

use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Driver\Oci8\Oci8;
use Zend\Db\Adapter\Driver\Pdo\Pdo;
use \Zend\Db\Adapter\Exception\InvalidArgumentException;
use Zend\Db\Adapter\Exception\InvalidArgumentException;

class Oracle extends AbstractPlatform
{
Expand Down Expand Up @@ -78,18 +76,6 @@ public function getName()
return 'Oracle';
}

/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
if ($this->quoteIdentifiers === false) {
return implode('.', (array) $identifierChain);
}

return '"' . implode('"."', (array) str_replace('"', '\\"', $identifierChain)) . '"';
}

/**
* {@inheritDoc}
*/
Expand Down
16 changes: 3 additions & 13 deletions src/Adapter/Platform/Postgresql.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see http://github.com/zendframework/zend-db for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://github.com/zendframework/zend-db/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Db\Adapter\Platform;
Expand Down Expand Up @@ -65,14 +63,6 @@ public function getName()
return 'PostgreSQL';
}

/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '"' . implode('"."', (array) str_replace('"', '""', $identifierChain)) . '"';
}

/**
* {@inheritDoc}
*/
Expand Down
16 changes: 3 additions & 13 deletions src/Adapter/Platform/SqlServer.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see http://github.com/zendframework/zend-db for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://github.com/zendframework/zend-db/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Db\Adapter\Platform;
Expand Down Expand Up @@ -74,14 +72,6 @@ public function getQuoteIdentifierSymbol()
return $this->quoteIdentifier;
}

/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '[' . implode('].[', (array) $identifierChain) . ']';
}

/**
* {@inheritDoc}
*/
Expand Down
12 changes: 5 additions & 7 deletions src/Sql/AbstractSql.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see http://github.com/zendframework/zend-db for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://github.com/zendframework/zend-db/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Db\Sql;

use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Platform\PlatformInterface;
use Zend\Db\Sql\Platform\PlatformDecoratorInterface;
use Zend\Db\Adapter\Platform\Sql92 as DefaultAdapterPlatform;
use Zend\Db\Sql\Platform\PlatformDecoratorInterface;

abstract class AbstractSql implements SqlInterface
{
Expand Down Expand Up @@ -435,7 +433,7 @@ protected function resolveTable(
}

if ($schema && $table) {
$table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table;
$table = $platform->quoteIdentifierChain($schema) . $platform->getIdentifierSeparator() . $table;
}
return $table;
}
Expand Down