1 |
<?php
|
2 |
/*
|
3 |
* $Id: Sqlite.php 2963 2007-10-21 06:23:59Z Jonathan.Wage $
|
4 |
*
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
16 |
*
|
17 |
* This software consists of voluntary contributions made by many individuals
|
18 |
* and is licensed under the LGPL. For more information, see
|
19 |
* <http://www.phpdoctrine.com>.
|
20 |
*/
|
21 |
Doctrine::autoload("Doctrine_Connection_Common");
|
22 |
/**
|
23 |
* Doctrine_Connection_Sqlite
|
24 |
*
|
25 |
* @package Doctrine
|
26 |
* @subpackage Connection
|
27 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
28 |
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
29 |
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
30 |
* @version $Revision: 2963 $
|
31 |
* @link www.phpdoctrine.com
|
32 |
* @since 1.0
|
33 |
*/
|
34 |
class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common
|
35 |
{
|
36 |
/**
|
37 |
* @var string $driverName the name of this connection driver
|
38 |
*/
|
39 |
protected $driverName = 'Sqlite';
|
40 |
|
41 |
/**
|
42 |
* the constructor
|
43 |
*
|
44 |
* @param Doctrine_Manager $manager
|
45 |
* @param PDO $pdo database handle
|
46 |
*/
|
47 |
public function __construct(Doctrine_Manager $manager, $adapter)
|
48 |
{
|
49 |
|
50 |
$this->supported = array(
|
51 |
'sequences' => 'emulated',
|
52 |
'indexes' => true,
|
53 |
'affected_rows' => true,
|
54 |
'summary_functions' => true,
|
55 |
'order_by_text' => true,
|
56 |
'current_id' => 'emulated',
|
57 |
'limit_queries' => true,
|
58 |
'LOBs' => true,
|
59 |
'replace' => true,
|
60 |
'transactions' => true,
|
61 |
'savepoints' => false,
|
62 |
'sub_selects' => true,
|
63 |
'auto_increment' => true,
|
64 |
'primary_key' => true,
|
65 |
'result_introspection' => false, // not implemented
|
66 |
'prepared_statements' => 'emulated',
|
67 |
'identifier_quoting' => true,
|
68 |
'pattern_escaping' => false,
|
69 |
);
|
70 |
/**
|
71 |
$this->options['base_transaction_name'] = '___php_Doctrine_sqlite_auto_commit_off';
|
72 |
$this->options['fixed_float'] = 0;
|
73 |
$this->options['database_path'] = '';
|
74 |
$this->options['database_extension'] = '';
|
75 |
$this->options['server_version'] = '';
|
76 |
*/
|
77 |
parent::__construct($manager, $adapter);
|
78 |
|
79 |
if ($this->isConnected) {
|
80 |
$this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
|
81 |
$this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl'));
|
82 |
$this->dbh->sqliteCreateFunction('md5', 'md5', 1);
|
83 |
$this->dbh->sqliteCreateFunction('now', 'time', 0);
|
84 |
}
|
85 |
}
|
86 |
|
87 |
/**
|
88 |
* initializes database functions missing in sqlite
|
89 |
*
|
90 |
* @see Doctrine_Expression
|
91 |
* @return void
|
92 |
*/
|
93 |
public function connect()
|
94 |
{
|
95 |
if ($this->isConnected) {
|
96 |
return false;
|
97 |
}
|
98 |
|
99 |
parent::connect();
|
100 |
|
101 |
$this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
|
102 |
$this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl'));
|
103 |
$this->dbh->sqliteCreateFunction('md5', 'md5', 1);
|
104 |
$this->dbh->sqliteCreateFunction('now', 'time', 0);
|
105 |
}
|
106 |
|
107 |
/**
|
108 |
* getDatabaseFile
|
109 |
*
|
110 |
* @param string $name the name of the database
|
111 |
* @return string
|
112 |
*/
|
113 |
public function getDatabaseFile($name)
|
114 |
{
|
115 |
return $name . '.db';
|
116 |
}
|
117 |
} |