Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: Sqlite.php 7490 2010-03-29 19:53:27Z jwage $
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.doctrine-project.org>.
20
 */
21
 
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: 7490 $
31
 * @link        www.doctrine-project.org
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
        $this->supported = array('sequences'            => 'emulated',
50
                          'indexes'              => true,
51
                          'affected_rows'        => true,
52
                          'summary_functions'    => true,
53
                          'order_by_text'        => true,
54
                          'current_id'           => 'emulated',
55
                          'limit_queries'        => true,
56
                          'LOBs'                 => true,
57
                          'replace'              => true,
58
                          'transactions'         => true,
59
                          'savepoints'           => false,
60
                          'sub_selects'          => true,
61
                          'auto_increment'       => true,
62
                          'primary_key'          => true,
63
                          'result_introspection' => false, // not implemented
64
                          'prepared_statements'  => 'emulated',
65
                          'identifier_quoting'   => true,
66
                          'pattern_escaping'     => false,
67
                          );
68
         parent::__construct($manager, $adapter);
69
 
70
        if ($this->isConnected) {
71
            $this->dbh->sqliteCreateFunction('mod',    array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
72
            $this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl'));
73
            $this->dbh->sqliteCreateFunction('md5', 'md5', 1);
74
            $this->dbh->sqliteCreateFunction('now', array('Doctrine_Expression_Sqlite', 'nowImpl'), 0);
75
        }
76
    }
77
 
78
    /**
79
     * initializes database functions missing in sqlite
80
     *
81
     * @see Doctrine_Expression
82
     * @return void
83
     */
84
    public function connect()
85
    {
86
        if ($this->isConnected) {
87
            return false;
88
        }
89
 
90
        parent::connect();
91
 
92
        $this->dbh->sqliteCreateFunction('mod',    array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
93
        $this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl'));
94
        $this->dbh->sqliteCreateFunction('md5', 'md5', 1);
95
        $this->dbh->sqliteCreateFunction('now', array('Doctrine_Expression_Sqlite', 'nowImpl'), 0);
96
    }
97
 
98
    /**
99
     * createDatabase
100
     *
101
     * @return void
102
     */
103
    public function createDatabase()
104
    {
105
        if ( ! $dsn = $this->getOption('dsn')) {
106
            throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality');
107
        }
108
 
109
        $info = $this->getManager()->parseDsn($dsn);
110
 
111
        $this->export->createDatabase($info['database']);
112
    }
113
 
114
    /**
115
     * dropDatabase
116
     *
117
     * @return void
118
     */
119
    public function dropDatabase()
120
    {
121
        if ( ! $dsn = $this->getOption('dsn')) {
122
            throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality');
123
        }
124
 
125
        $info = $this->getManager()->parseDsn($dsn);
126
 
127
        $this->export->dropDatabase($info['database']);
128
    }
129
}