Firebird.php 4.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php
/*
 *  $Id$
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * <http://www.phpdoctrine.com>.
 */
Doctrine::autoload('Doctrine_Import');
/**
23 24
  * @package     Doctrine
  * @subpackage  Import
25 26 27 28 29 30 31 32
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
 * @author      Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
 * @author      Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
 * @version     $Revision$
 * @link        www.phpdoctrine.com
 * @since       1.0
 */
lsmith's avatar
lsmith committed
33 34
class Doctrine_Import_Firebird extends Doctrine_Import
{
35 36 37 38 39
    /**
     * list all tables in the current database
     *
     * @return array        data array
     */
zYne's avatar
zYne committed
40
    public function listTables($database = null)
lsmith's avatar
lsmith committed
41
    {
42 43 44 45
        $query = 'SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR IS NULL';

        return $this->conn->fetchColumn($query);
    }
46

47 48 49 50 51 52 53
    /**
     * list all fields in a tables in the current database
     *
     * @param string $table name of table that should be used in method
     * @return mixed data array on success, a MDB2 error on failure
     * @access public
     */
lsmith's avatar
lsmith committed
54 55
    public function listTableFields($table)
    {
lsmith's avatar
lsmith committed
56
        $table = $this->conn->quote(strtoupper($table), 'text');
57
        $query = 'SELECT RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
58 59 60

        return $this->conn->fetchColumn($query);
    }
61

62 63 64 65 66
    /**
     * list all users
     *
     * @return array            data array containing all database users
     */
lsmith's avatar
lsmith committed
67 68
    public function listUsers()
    {
69 70
        return $this->conn->fetchColumn('SELECT DISTINCT RDB$USER FROM RDB$USER_PRIVILEGES');
    }
71

72 73 74 75 76
    /**
     * list the views in the database
     *
     * @return array            data array containing all database views
     */
zYne's avatar
zYne committed
77
    public function listViews($database = null)
lsmith's avatar
lsmith committed
78
    {
lsmith's avatar
lsmith committed
79
        return $this->conn->fetchColumn('SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS');
80
    }
81

82 83 84 85 86 87
    /**
     * list the views in the database that reference a given table
     *
     * @param string $table     table for which all references views should be found
     * @return array            data array containing all views for given table
     */
lsmith's avatar
lsmith committed
88 89
    public function listTableViews($table)
    {
90
        $query  = 'SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS';
lsmith's avatar
lsmith committed
91
        $table  = $this->conn->quote(strtoupper($table), 'text');
92
        $query .= ' WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
93 94 95

        return $this->conn->fetchColumn($query);
    }
96

97 98 99 100 101
    /**
     * list all functions in the current database
     *
     * @return array              data array containing all availible functions
     */
lsmith's avatar
lsmith committed
102 103
    public function listFunctions()
    {
104 105 106 107
        $query = 'SELECT RDB$FUNCTION_NAME FROM RDB$FUNCTIONS WHERE RDB$SYSTEM_FLAG IS NULL';

        return $this->conn->fetchColumn($query);
    }
108

109 110
    /**
     * This function will be called to get all triggers of the
lsmith's avatar
lsmith committed
111
     * current database ($this->conn->getDatabase())
112 113 114 115 116
     *
     * @param  string $table      The name of the table from the
     *                            previous database to query against.
     * @return array              data array containing all triggers for given table
     */
zYne's avatar
zYne committed
117
    public function listTableTriggers($table)
lsmith's avatar
lsmith committed
118
    {
119
        $query = 'SELECT RDB$TRIGGER_NAME FROM RDB$TRIGGERS WHERE RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0';
120

lsmith's avatar
lsmith committed
121
        if ( ! is_null($table)) {
lsmith's avatar
lsmith committed
122
            $table = $this->conn->quote(strtoupper($table), 'text');
123
            $query .= ' WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
124 125 126 127
        }

        return $this->conn->fetchColumn($query);
    }
128
}