3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\DBAL\Driver\PDOSqlite;
23 * The PDO Sqlite driver.
27 class Driver implements \Doctrine\DBAL\Driver
32 protected $_userDefinedFunctions = array(
33 'sqrt' => array('callback' => array('Doctrine\DBAL\Platforms\SqlitePlatform', 'udfSqrt'), 'numArgs' => 1),
34 'mod' => array('callback' => array('Doctrine\DBAL\Platforms\SqlitePlatform', 'udfMod'), 'numArgs' => 2),
35 'locate' => array('callback' => array('Doctrine\DBAL\Platforms\SqlitePlatform', 'udfLocate'), 'numArgs' => -1),
39 * Tries to establish a database connection to SQLite.
41 * @param array $params
42 * @param string $username
43 * @param string $password
44 * @param array $driverOptions
45 * @return \Doctrine\DBAL\Driver\PDOConnection
47 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
49 if (isset($driverOptions['userDefinedFunctions'])) {
50 $this->_userDefinedFunctions = array_merge(
51 $this->_userDefinedFunctions, $driverOptions['userDefinedFunctions']);
52 unset($driverOptions['userDefinedFunctions']);
55 $pdo = new \Doctrine\DBAL\Driver\PDOConnection(
56 $this->_constructPdoDsn($params),
62 foreach ($this->_userDefinedFunctions as $fn => $data) {
63 $pdo->sqliteCreateFunction($fn, $data['callback'], $data['numArgs']);
70 * Constructs the Sqlite PDO DSN.
72 * @return string The DSN.
75 protected function _constructPdoDsn(array $params)
78 if (isset($params['path'])) {
79 $dsn .= $params['path'];
80 } else if (isset($params['memory'])) {
88 * Gets the database platform that is relevant for this driver.
90 public function getDatabasePlatform()
92 return new \Doctrine\DBAL\Platforms\SqlitePlatform();
96 * Gets the schema manager that is relevant for this driver.
98 * @param \Doctrine\DBAL\Connection $conn
99 * @return \Doctrine\DBAL\Schema\SqliteSchemaManager
101 public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
103 return new \Doctrine\DBAL\Schema\SqliteSchemaManager($conn);
106 public function getName()
111 public function getDatabase(\Doctrine\DBAL\Connection $conn)
113 $params = $conn->getParams();
114 return isset($params['path']) ? $params['path'] : null;