Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Db / Adapter / Platform / Sqlite.php
blobf4dc76970906accafae313d1986b062da8d2cfb9
1 <?php
2 /**
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
8 */
10 namespace Zend\Db\Adapter\Platform;
12 use Zend\Db\Adapter\Driver\DriverInterface;
13 use Zend\Db\Adapter\Driver\Pdo;
14 use Zend\Db\Adapter\Exception;
16 class Sqlite implements PlatformInterface
19 /** @var \PDO */
20 protected $resource = null;
22 public function __construct($driver = null)
24 if ($driver) {
25 $this->setDriver($driver);
29 /**
30 * @param \Zend\Db\Adapter\Driver\Pdo\Pdo||\PDO $driver
31 * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
32 * @return $this
34 public function setDriver($driver)
36 if (($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'sqlite')
37 || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Sqlite')
38 ) {
39 $this->resource = $driver;
40 return $this;
43 throw new Exception\InvalidArgumentException('$driver must be a Sqlite PDO Zend\Db\Adapter\Driver, Sqlite PDO instance');
46 /**
47 * Get name
49 * @return string
51 public function getName()
53 return 'SQLite';
56 /**
57 * Get quote identifier symbol
59 * @return string
61 public function getQuoteIdentifierSymbol()
63 return '"';
66 /**
67 * Quote identifier
69 * @param string $identifier
70 * @return string
72 public function quoteIdentifier($identifier)
74 return '"' . str_replace('"', '\\' . '"', $identifier) . '"';
77 /**
78 * Quote identifier chain
80 * @param string|string[] $identifierChain
81 * @return string
83 public function quoteIdentifierChain($identifierChain)
85 $identifierChain = str_replace('"', '\\"', $identifierChain);
86 if (is_array($identifierChain)) {
87 $identifierChain = implode('"."', $identifierChain);
89 return '"' . $identifierChain . '"';
92 /**
93 * Get quote value symbol
95 * @return string
97 public function getQuoteValueSymbol()
99 return '\'';
103 * Quote value
105 * @param string $value
106 * @return string
108 public function quoteValue($value)
110 if ($this->resource instanceof DriverInterface) {
111 $this->resource = $this->resource->getConnection()->getResource();
113 if ($this->resource instanceof \PDO) {
114 return $this->resource->quote($value);
116 trigger_error(
117 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support '
118 . 'can introduce security vulnerabilities in a production environment.'
120 return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\'';
124 * Quote Trusted Value
126 * The ability to quote values without notices
128 * @param $value
129 * @return mixed
131 public function quoteTrustedValue($value)
133 if ($this->resource instanceof DriverInterface) {
134 $this->resource = $this->resource->getConnection()->getResource();
136 if ($this->resource instanceof \PDO) {
137 return $this->resource->quote($value);
139 return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\'';
143 * Quote value list
145 * @param string|string[] $valueList
146 * @return string
148 public function quoteValueList($valueList)
150 if (!is_array($valueList)) {
151 return $this->quoteValue($valueList);
153 $value = reset($valueList);
154 do {
155 $valueList[key($valueList)] = $this->quoteValue($value);
156 } while ($value = next($valueList));
157 return implode(', ', $valueList);
161 * Get identifier separator
163 * @return string
165 public function getIdentifierSeparator()
167 return '.';
171 * Quote identifier in fragment
173 * @param string $identifier
174 * @param array $safeWords
175 * @return string
177 public function quoteIdentifierInFragment($identifier, array $safeWords = array())
179 $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
180 if ($safeWords) {
181 $safeWords = array_flip($safeWords);
182 $safeWords = array_change_key_case($safeWords, CASE_LOWER);
184 foreach ($parts as $i => $part) {
185 if ($safeWords && isset($safeWords[strtolower($part)])) {
186 continue;
188 switch ($part) {
189 case ' ':
190 case '.':
191 case '*':
192 case 'AS':
193 case 'As':
194 case 'aS':
195 case 'as':
196 break;
197 default:
198 $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"';
201 return implode('', $parts);