# Coverage for Doctrine_Import_Oracle

Back to coverage report

1 | <?php
2 | /*
3 | * $Id: Oracle.php 3159 2007-11-15 05:16:31Z 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 | * @version $Revision: 3159 $
28 | * @link www.phpdoctrine.org
29 | * @since 1.0
30 | */
31 | class Doctrine_Import_Oracle extends Doctrine_Import
32 | {
33 | /**
34 | * lists all databases
35 | *
36 | * @return array
37 | */
38 | public function listDatabases()
39 | {
40 | if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE)) {
41 | throw new Doctrine_Import_Exception('database listing is only supported if the "emulate_database" option is enabled');
42 | }
43 | /**
44 | if ($this->conn->options['database_name_prefix']) {
45 | $query = 'SELECT SUBSTR(username, ';
46 | $query.= (strlen($this->conn->getAttribute(['database_name_prefix'])+1);
47 | $query.= ") FROM sys.dba_users WHERE username LIKE '";
48 | $query.= $this->conn->options['database_name_prefix']."%'";
49 | } else {
50 | */
51 | $query = 'SELECT username FROM sys.dba_users';
52 |
53 | $result2 = $this->conn->standaloneQuery($query);
54 | $result = $result2->fetchColumn();
55 |
56 | return $result;
57 | }
58 |
59 | /**
60 | * lists all availible database functions
61 | *
62 | * @return array
63 | */
64 | public function listFunctions()
65 | {
66 | $query = "SELECT name FROM sys.user_source WHERE line = 1 AND type = 'FUNCTION'";
67 |
68 | return $this->conn->fetchColumn($query);
69 | }
70 |
71 | /**
72 | * lists all database triggers
73 | *
74 | * @param string|null $database
75 | * @return array
76 | */
77 | public function listTriggers($database = null)
78 | {
79 |
80 | }
81 |
82 | /**
83 | * lists all database sequences
84 | *
85 | * @param string|null $database
86 | * @return array
87 | */
88 | public function listSequences($database = null)
89 | {
90 | $query = "SELECT sequence_name FROM sys.user_sequences";
91 |
92 | $tableNames = $this->conn->fetchColumn($query);
93 |
94 | return array_map(array($this->conn->formatter, 'fixSequenceName'), $tableNames);
95 | }
96 |
97 | /**
98 | * lists table constraints
99 | *
100 | * @param string $table database table name
101 | * @return array
102 | */
103 | public function listTableConstraints($table)
104 | {
105 | $table = $this->conn->quote($table, 'text');
106 |
107 | $query = 'SELECT index_name name FROM user_constraints'
108 | . ' WHERE table_name = ' . $table . ' OR table_name = ' . strtoupper($table);
109 |
110 | $constraints = $this->conn->fetchColumn($query);
111 |
112 | return array_map(array($this->conn->formatter, 'fixIndexName'), $constraints);
113 | }
114 |
115 | /**
116 | * lists table constraints
117 | *
118 | * @param string $table database table name
119 | * @return array
120 | */
121 | public function listTableColumns($table)
122 | {
123 | $table = strtoupper($table);
124 | $sql = "SELECT column_name, data_type, data_length, nullable, data_default, data_scale, data_precision FROM all_tab_columns"
125 | . " WHERE table_name = '" . $table . "' ORDER BY column_name";
126 |
127 | $result = $this->conn->fetchAssoc($sql);
128 |
129 | $descr = array();
130 |
131 | foreach($result as $val) {
132 | $val = array_change_key_case($val, CASE_LOWER);
133 | $decl = $this->conn->dataDict->getPortableDeclaration($val);
134 |
135 |
136 | $descr[$val['column_name']] = array(
137 | 'name' => $val['column_name'],
138 | 'notnull' => (bool) ($val['nullable'] === 'N'),
139 | 'ntype' => $val['data_type'],
140 | 'type' => $decl['type'][0],
141 | 'alltypes' => $decl['type'],
142 | 'fixed' => $decl['fixed'],
143 | 'unsigned' => $decl['unsigned'],
144 | 'default' => $val['data_default'],
145 | 'length' => $val['data_length'],
146 | 'precision' => $val['data_precision'],
147 | 'scale' => $val['scale'],
148 | );
149 | }
150 |
151 | return $descr;
152 | }
153 |
154 | /**
155 | * lists table constraints
156 | *
157 | * @param string $table database table name
158 | * @return array
159 | */
160 | public function listTableIndexes($table)
161 | {
162 | $table = $this->conn->quote($table, 'text');
163 | $query = 'SELECT index_name name FROM user_indexes'
164 | . ' WHERE table_name = ' . $table . ' OR table_name = ' . strtoupper($table)
165 | . ' AND generated = ' . $this->conn->quote('N', 'text');
166 |
167 | $indexes = $this->conn->fetchColumn($query);
168 |
169 | return array_map(array($this->conn->formatter, 'fixIndexName'), $indexes);
170 | }
171 |
172 | /**
173 | * lists tables
174 | *
175 | * @param string|null $database
176 | * @return array
177 | */
178 | public function listTables($database = null)
179 | {
180 | $query = 'SELECT table_name FROM sys.user_tables';
181 | return $this->conn->fetchColumn($query);
182 | }
183 |
184 | /**
185 | * lists table triggers
186 | *
187 | * @param string $table database table name
188 | * @return array
189 | */
190 | public function listTableTriggers($table)
191 | {
192 |
193 | }
194 |
195 | /**
196 | * lists table views
197 | *
198 | * @param string $table database table name
199 | * @return array
200 | */
201 | public function listTableViews($table)
202 | {
203 |
204 | }
205 |
206 | /**
207 | * lists database users
208 | *
209 | * @return array
210 | */
211 | public function listUsers()
212 | {
213 | /**
214 | if ($this->conn->options['emulate_database'] && $this->conn->options['database_name_prefix']) {
215 | $query = 'SELECT SUBSTR(username, ';
216 | $query.= (strlen($this->conn->options['database_name_prefix'])+1);
217 | $query.= ") FROM sys.dba_users WHERE username NOT LIKE '";
218 | $query.= $this->conn->options['database_name_prefix']."%'";
219 | } else {
220 | */
221 |
222 | $query = 'SELECT username FROM sys.dba_users';
223 | //}
224 |
225 | return $this->conn->fetchColumn($query);
226 | }
227 |
228 | /**
229 | * lists database views
230 | *
231 | * @param string|null $database
232 | * @return array
233 | */
234 | public function listViews($database = null)
235 | {
236 | $query = 'SELECT view_name FROM sys.user_views';
237 | return $this->conn->fetchColumn($query);
238 | }
239 | }