1 |
<?php
|
2 |
/*
|
3 |
* $Id: Oracle.php 2702 2007-10-03 21:43:22Z 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_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: 2702 $
|
28 |
* @link www.phpdoctrine.com
|
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 |
* lists all availible database functions
|
60 |
*
|
61 |
* @return array
|
62 |
*/
|
63 |
public function listFunctions()
|
64 |
{
|
65 |
$query = "SELECT name FROM sys.user_source WHERE line = 1 AND type = 'FUNCTION'";
|
66 |
|
67 |
return $this->conn->fetchColumn($query);
|
68 |
}
|
69 |
/**
|
70 |
* lists all database triggers
|
71 |
*
|
72 |
* @param string|null $database
|
73 |
* @return array
|
74 |
*/
|
75 |
public function listTriggers($database = null)
|
76 |
{
|
77 |
|
78 |
}
|
79 |
/**
|
80 |
* lists all database sequences
|
81 |
*
|
82 |
* @param string|null $database
|
83 |
* @return array
|
84 |
*/
|
85 |
public function listSequences($database = null)
|
86 |
{
|
87 |
$query = "SELECT sequence_name FROM sys.user_sequences";
|
88 |
|
89 |
$tableNames = $this->conn->fetchColumn($query);
|
90 |
|
91 |
return array_map(array($this->conn->formatter, 'fixSequenceName'), $tableNames);
|
92 |
}
|
93 |
/**
|
94 |
* lists table constraints
|
95 |
*
|
96 |
* @param string $table database table name
|
97 |
* @return array
|
98 |
*/
|
99 |
public function listTableConstraints($table)
|
100 |
{
|
101 |
$table = $this->conn->quote($table, 'text');
|
102 |
|
103 |
$query = 'SELECT index_name name FROM user_constraints'
|
104 |
. ' WHERE table_name = ' . $table . ' OR table_name = ' . strtoupper($table);
|
105 |
|
106 |
$constraints = $this->conn->fetchColumn($query);
|
107 |
|
108 |
return array_map(array($this->conn->formatter, 'fixIndexName'), $constraints);
|
109 |
}
|
110 |
/**
|
111 |
* lists table constraints
|
112 |
*
|
113 |
* @param string $table database table name
|
114 |
* @return array
|
115 |
*/
|
116 |
public function listTableColumns($table)
|
117 |
{
|
118 |
$table = strtoupper($table);
|
119 |
$sql = "SELECT column_name, data_type, data_length, nullable, data_default, data_scale, data_precision FROM all_tab_columns"
|
120 |
. " WHERE table_name = '" . $table . "' ORDER BY column_name";
|
121 |
|
122 |
$result = $this->conn->fetchAssoc($sql);
|
123 |
|
124 |
foreach($result as $val) {
|
125 |
$val = array_change_key_case($val, CASE_LOWER);
|
126 |
$decl = $this->conn->dataDict->getPortableDeclaration($val);
|
127 |
|
128 |
|
129 |
$descr[$val['column_name']] = array(
|
130 |
'name' => $val['column_name'],
|
131 |
'notnull' => (bool) ($val['nullable'] === 'N'),
|
132 |
'ntype' => $val['data_type'],
|
133 |
'type' => $decl['type'][0],
|
134 |
'alltypes' => $decl['type'],
|
135 |
'fixed' => $decl['fixed'],
|
136 |
'unsigned' => $decl['unsigned'],
|
137 |
'default' => $val['data_default'],
|
138 |
'length' => $val['data_length'],
|
139 |
'precision' => $val['data_precision'],
|
140 |
'scale' => $val['scale'],
|
141 |
);
|
142 |
}
|
143 |
return $result;
|
144 |
}
|
145 |
/**
|
146 |
* lists table constraints
|
147 |
*
|
148 |
* @param string $table database table name
|
149 |
* @return array
|
150 |
*/
|
151 |
public function listTableIndexes($table)
|
152 |
{
|
153 |
$table = $this->conn->quote($table, 'text');
|
154 |
$query = 'SELECT index_name name FROM user_indexes'
|
155 |
. ' WHERE table_name = ' . $table . ' OR table_name = ' . strtoupper($table)
|
156 |
. ' AND generated = ' . $this->conn->quote('N', 'text');
|
157 |
|
158 |
$indexes = $this->conn->fetchColumn($query);
|
159 |
|
160 |
return array_map(array($this->conn->formatter, 'fixIndexName'), $indexes);
|
161 |
}
|
162 |
/**
|
163 |
* lists tables
|
164 |
*
|
165 |
* @param string|null $database
|
166 |
* @return array
|
167 |
*/
|
168 |
public function listTables($database = null)
|
169 |
{
|
170 |
$query = 'SELECT table_name FROM sys.user_tables';
|
171 |
return $this->conn->fetchColumn($query);
|
172 |
}
|
173 |
/**
|
174 |
* lists table triggers
|
175 |
*
|
176 |
* @param string $table database table name
|
177 |
* @return array
|
178 |
*/
|
179 |
public function listTableTriggers($table)
|
180 |
{
|
181 |
|
182 |
}
|
183 |
/**
|
184 |
* lists table views
|
185 |
*
|
186 |
* @param string $table database table name
|
187 |
* @return array
|
188 |
*/
|
189 |
public function listTableViews($table)
|
190 |
{
|
191 |
|
192 |
}
|
193 |
/**
|
194 |
* lists database users
|
195 |
*
|
196 |
* @return array
|
197 |
*/
|
198 |
public function listUsers()
|
199 |
{
|
200 |
/**
|
201 |
if ($this->conn->options['emulate_database'] && $this->conn->options['database_name_prefix']) {
|
202 |
$query = 'SELECT SUBSTR(username, ';
|
203 |
$query.= (strlen($this->conn->options['database_name_prefix'])+1);
|
204 |
$query.= ") FROM sys.dba_users WHERE username NOT LIKE '";
|
205 |
$query.= $this->conn->options['database_name_prefix']."%'";
|
206 |
} else {
|
207 |
*/
|
208 |
|
209 |
$query = 'SELECT username FROM sys.dba_users';
|
210 |
//}
|
211 |
|
212 |
return $this->conn->fetchColumn($query);
|
213 |
}
|
214 |
/**
|
215 |
* lists database views
|
216 |
*
|
217 |
* @param string|null $database
|
218 |
* @return array
|
219 |
*/
|
220 |
public function listViews($database = null)
|
221 |
{
|
222 |
$query = 'SELECT view_name FROM sys.user_views';
|
223 |
return $this->conn->fetchColumn($query);
|
224 |
}
|
225 |
} |