3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Db\Adapter\Platform
;
12 class Oracle
implements PlatformInterface
18 protected $quoteIdentifiers = true;
21 * @param array $options
23 public function __construct($options = array())
25 if (isset($options['quote_identifiers'])
26 && ($options['quote_identifiers'] == false
27 ||
$options['quote_identifiers'] === 'false')
29 $this->quoteIdentifiers
= false;
38 public function getName()
44 * Get quote identifier symbol
48 public function getQuoteIdentifierSymbol()
56 * @param string $identifier
59 public function quoteIdentifier($identifier)
61 if ($this->quoteIdentifiers
=== false) {
64 return '"' . str_replace('"', '\\' . '"', $identifier) . '"';
68 * Quote identifier chain
70 * @param string|string[] $identifierChain
73 public function quoteIdentifierChain($identifierChain)
75 if ($this->quoteIdentifiers
=== false) {
76 return (is_array($identifierChain)) ?
implode('.', $identifierChain) : $identifierChain;
78 $identifierChain = str_replace('"', '\\"', $identifierChain);
79 if (is_array($identifierChain)) {
80 $identifierChain = implode('"."', $identifierChain);
82 return '"' . $identifierChain . '"';
86 * Get quote value symbol
90 public function getQuoteValueSymbol()
98 * @param string $value
101 public function quoteValue($value)
104 'Attempting to quote a value in ' . __CLASS__
. ' without extension/driver support '
105 . 'can introduce security vulnerabilities in a production environment.'
107 return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\'';
111 * Quote Trusted Value
113 * The ability to quote values without notices
118 public function quoteTrustedValue($value)
120 return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\'';
126 * @param string|string[] $valueList
129 public function quoteValueList($valueList)
131 if (!is_array($valueList)) {
132 return $this->quoteValue($valueList);
135 $value = reset($valueList);
137 $valueList[key($valueList)] = $this->quoteValue($value);
138 } while ($value = next($valueList));
139 return implode(', ', $valueList);
143 * Get identifier separator
147 public function getIdentifierSeparator()
153 * Quote identifier in fragment
155 * @param string $identifier
156 * @param array $safeWords
159 public function quoteIdentifierInFragment($identifier, array $safeWords = array())
161 if ($this->quoteIdentifiers
=== false) {
164 $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
166 $safeWords = array_flip($safeWords);
167 $safeWords = array_change_key_case($safeWords, CASE_LOWER
);
169 foreach ($parts as $i => $part) {
170 if ($safeWords && isset($safeWords[strtolower($part)])) {
183 $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"';
186 return implode('', $parts);