# Coverage for Doctrine_Import_Firebird

Back to coverage report

1 | <?php
2 | /*
3 | * $Id: Firebird.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.org>.
20 | */
21 | Doctrine::autoload('Doctrine_Import');
22 | /**
23 | * @package Doctrine
24 | * @subpackage Import
25 | * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
26 | * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
27 | * @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
28 | * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
29 | * @version $Revision: 2963 $
30 | * @link www.phpdoctrine.org
31 | * @since 1.0
32 | */
33 | class Doctrine_Import_Firebird extends Doctrine_Import
34 | {
35 | /**
36 | * list all tables in the current database
37 | *
38 | * @return array data array
39 | */
40 | public function listTables($database = null)
41 | {
42 | $query = 'SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR IS NULL';
43 |
44 | return $this->conn->fetchColumn($query);
45 | }
46 |
47 | /**
48 | * list all fields in a tables in the current database
49 | *
50 | * @param string $table name of table that should be used in method
51 | * @return mixed data array on success, a MDB2 error on failure
52 | * @access public
53 | */
54 | public function listTableFields($table)
55 | {
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 | return $this->conn->fetchColumn($query);
60 | }
61 |
62 | /**
63 | * list all users
64 | *
65 | * @return array data array containing all database users
66 | */
67 | public function listUsers()
68 | {
69 | return $this->conn->fetchColumn('SELECT DISTINCT RDB$USER FROM RDB$USER_PRIVILEGES');
70 | }
71 |
72 | /**
73 | * list the views in the database
74 | *
75 | * @return array data array containing all database views
76 | */
77 | public function listViews($database = null)
78 | {
79 | return $this->conn->fetchColumn('SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS');
80 | }
81 |
82 | /**
83 | * list the views in the database that reference a given table
84 | *
85 | * @param string $table table for which all references views should be found
86 | * @return array data array containing all views for given table
87 | */
88 | public function listTableViews($table)
89 | {
90 | $query = 'SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS';
91 | $table = $this->conn->quote(strtoupper($table), 'text');
92 | $query .= ' WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
93 |
94 | return $this->conn->fetchColumn($query);
95 | }
96 |
97 | /**
98 | * list all functions in the current database
99 | *
100 | * @return array data array containing all availible functions
101 | */
102 | public function listFunctions()
103 | {
104 | $query = 'SELECT RDB$FUNCTION_NAME FROM RDB$FUNCTIONS WHERE RDB$SYSTEM_FLAG IS NULL';
105 |
106 | return $this->conn->fetchColumn($query);
107 | }
108 |
109 | /**
110 | * This function will be called to get all triggers of the
111 | * current database ($this->conn->getDatabase())
112 | *
113 | * @param string $table The name of the table from the
114 | * previous database to query against.
115 | * @return array data array containing all triggers for given table
116 | */
117 | public function listTableTriggers($table)
118 | {
119 | $query = 'SELECT RDB$TRIGGER_NAME FROM RDB$TRIGGERS WHERE RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0';
120 |
121 | if ( ! is_null($table)) {
122 | $table = $this->conn->quote(strtoupper($table), 'text');
123 | $query .= ' WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
124 | }
125 |
126 | return $this->conn->fetchColumn($query);
127 | }
128 | }