commit | author | age
|
451834
|
1 |
<?php |
S |
2 |
// +----------------------------------------------------------------------+ |
|
3 |
// | PHP versions 4 and 5 | |
|
4 |
// +----------------------------------------------------------------------+ |
|
5 |
// | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox, | |
|
6 |
// | Stig. S. Bakken, Lukas Smith | |
|
7 |
// | All rights reserved. | |
|
8 |
// +----------------------------------------------------------------------+ |
|
9 |
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | |
|
10 |
// | API as well as database abstraction for PHP applications. | |
|
11 |
// | This LICENSE is in the BSD license style. | |
|
12 |
// | | |
|
13 |
// | Redistribution and use in source and binary forms, with or without | |
|
14 |
// | modification, are permitted provided that the following conditions | |
|
15 |
// | are met: | |
|
16 |
// | | |
|
17 |
// | Redistributions of source code must retain the above copyright | |
|
18 |
// | notice, this list of conditions and the following disclaimer. | |
|
19 |
// | | |
|
20 |
// | Redistributions in binary form must reproduce the above copyright | |
|
21 |
// | notice, this list of conditions and the following disclaimer in the | |
|
22 |
// | documentation and/or other materials provided with the distribution. | |
|
23 |
// | | |
|
24 |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | |
|
25 |
// | Lukas Smith nor the names of his contributors may be used to endorse | |
|
26 |
// | or promote products derived from this software without specific prior| |
|
27 |
// | written permission. | |
|
28 |
// | | |
|
29 |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|
30 |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|
31 |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
|
32 |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
|
33 |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
|
34 |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
|
35 |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| |
|
36 |
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
|
37 |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
|
38 |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| |
|
39 |
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
|
40 |
// | POSSIBILITY OF SUCH DAMAGE. | |
|
41 |
// +----------------------------------------------------------------------+ |
|
42 |
// | Author: Lukas Smith <smith@pooteeweet.org> | |
|
43 |
// +----------------------------------------------------------------------+ |
|
44 |
// |
|
45 |
// $Id$ |
|
46 |
// |
|
47 |
|
|
48 |
/** |
|
49 |
* @package MDB2 |
|
50 |
* @category Database |
|
51 |
*/ |
|
52 |
|
|
53 |
/** |
|
54 |
* These are constants for the tableInfo-function |
|
55 |
* they are bitwised or'ed. so if there are more constants to be defined |
|
56 |
* in the future, adjust MDB2_TABLEINFO_FULL accordingly |
|
57 |
*/ |
|
58 |
|
|
59 |
define('MDB2_TABLEINFO_ORDER', 1); |
|
60 |
define('MDB2_TABLEINFO_ORDERTABLE', 2); |
|
61 |
define('MDB2_TABLEINFO_FULL', 3); |
|
62 |
|
|
63 |
/** |
|
64 |
* Base class for the schema reverse engineering module that is extended by each MDB2 driver |
|
65 |
* |
|
66 |
* @package MDB2 |
|
67 |
* @category Database |
|
68 |
* @author Lukas Smith <smith@pooteeweet.org> |
|
69 |
*/ |
|
70 |
class MDB2_Driver_Reverse_Common extends MDB2_Module_Common |
|
71 |
{ |
|
72 |
// }}} |
|
73 |
// {{{ getTableFieldDefinition() |
|
74 |
|
|
75 |
/** |
|
76 |
* get the stucture of a field into an array |
|
77 |
* |
|
78 |
* @param string $table name of table that should be used in method |
|
79 |
* @param string $fields name of field that should be used in method |
|
80 |
* @return mixed data array on success, a MDB2 error on failure |
|
81 |
* @access public |
|
82 |
*/ |
|
83 |
function getTableFieldDefinition($table, $field) |
|
84 |
{ |
|
85 |
$db =& $this->getDBInstance(); |
|
86 |
if (PEAR::isError($db)) { |
|
87 |
return $db; |
|
88 |
} |
|
89 |
|
|
90 |
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, |
|
91 |
'getTableFieldDefinition: table field definition is not supported'); |
|
92 |
} |
|
93 |
|
|
94 |
// }}} |
|
95 |
// {{{ getTableIndexDefinition() |
|
96 |
|
|
97 |
/** |
|
98 |
* get the stucture of an index into an array |
|
99 |
* |
|
100 |
* @param string $table name of table that should be used in method |
|
101 |
* @param string $index name of index that should be used in method |
|
102 |
* @return mixed data array on success, a MDB2 error on failure |
|
103 |
* @access public |
|
104 |
*/ |
|
105 |
function getTableIndexDefinition($table, $index) |
|
106 |
{ |
|
107 |
$db =& $this->getDBInstance(); |
|
108 |
if (PEAR::isError($db)) { |
|
109 |
return $db; |
|
110 |
} |
|
111 |
|
|
112 |
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, |
|
113 |
'getTableIndexDefinition: getting index definition is not supported'); |
|
114 |
} |
|
115 |
|
|
116 |
// }}} |
|
117 |
// {{{ getSequenceDefinition() |
|
118 |
|
|
119 |
/** |
|
120 |
* get the stucture of a sequence into an array |
|
121 |
* |
|
122 |
* @param string $sequence name of sequence that should be used in method |
|
123 |
* @return mixed data array on success, a MDB2 error on failure |
|
124 |
* @access public |
|
125 |
*/ |
|
126 |
function getSequenceDefinition($sequence) |
|
127 |
{ |
|
128 |
$db =& $this->getDBInstance(); |
|
129 |
if (PEAR::isError($db)) { |
|
130 |
return $db; |
|
131 |
} |
|
132 |
|
|
133 |
$start = $db->currId($sequence); |
|
134 |
if (PEAR::isError($start)) { |
|
135 |
return $start; |
|
136 |
} |
|
137 |
if ($db->supports('current_id')) { |
|
138 |
$start++; |
|
139 |
} else { |
|
140 |
$db->warnings[] = 'database does not support getting current |
|
141 |
sequence value, the sequence value was incremented'; |
|
142 |
} |
|
143 |
$definition = array(); |
|
144 |
if ($start != 1) { |
|
145 |
$definition = array('start' => $start); |
|
146 |
} |
|
147 |
return $definition; |
|
148 |
} |
|
149 |
|
|
150 |
// }}} |
|
151 |
// {{{ tableInfo() |
|
152 |
|
|
153 |
/** |
|
154 |
* Returns information about a table or a result set |
|
155 |
* |
|
156 |
* The format of the resulting array depends on which <var>$mode</var> |
|
157 |
* you select. The sample output below is based on this query: |
|
158 |
* <pre> |
|
159 |
* SELECT tblFoo.fldID, tblFoo.fldPhone, tblBar.fldId |
|
160 |
* FROM tblFoo |
|
161 |
* JOIN tblBar ON tblFoo.fldId = tblBar.fldId |
|
162 |
* </pre> |
|
163 |
* |
|
164 |
* <ul> |
|
165 |
* <li> |
|
166 |
* |
|
167 |
* <kbd>null</kbd> (default) |
|
168 |
* <pre> |
|
169 |
* [0] => Array ( |
|
170 |
* [table] => tblFoo |
|
171 |
* [name] => fldId |
|
172 |
* [type] => int |
|
173 |
* [len] => 11 |
|
174 |
* [flags] => primary_key not_null |
|
175 |
* ) |
|
176 |
* [1] => Array ( |
|
177 |
* [table] => tblFoo |
|
178 |
* [name] => fldPhone |
|
179 |
* [type] => string |
|
180 |
* [len] => 20 |
|
181 |
* [flags] => |
|
182 |
* ) |
|
183 |
* [2] => Array ( |
|
184 |
* [table] => tblBar |
|
185 |
* [name] => fldId |
|
186 |
* [type] => int |
|
187 |
* [len] => 11 |
|
188 |
* [flags] => primary_key not_null |
|
189 |
* ) |
|
190 |
* </pre> |
|
191 |
* |
|
192 |
* </li><li> |
|
193 |
* |
|
194 |
* <kbd>MDB2_TABLEINFO_ORDER</kbd> |
|
195 |
* |
|
196 |
* <p>In addition to the information found in the default output, |
|
197 |
* a notation of the number of columns is provided by the |
|
198 |
* <samp>num_fields</samp> element while the <samp>order</samp> |
|
199 |
* element provides an array with the column names as the keys and |
|
200 |
* their location index number (corresponding to the keys in the |
|
201 |
* the default output) as the values.</p> |
|
202 |
* |
|
203 |
* <p>If a result set has identical field names, the last one is |
|
204 |
* used.</p> |
|
205 |
* |
|
206 |
* <pre> |
|
207 |
* [num_fields] => 3 |
|
208 |
* [order] => Array ( |
|
209 |
* [fldId] => 2 |
|
210 |
* [fldTrans] => 1 |
|
211 |
* ) |
|
212 |
* </pre> |
|
213 |
* |
|
214 |
* </li><li> |
|
215 |
* |
|
216 |
* <kbd>MDB2_TABLEINFO_ORDERTABLE</kbd> |
|
217 |
* |
|
218 |
* <p>Similar to <kbd>MDB2_TABLEINFO_ORDER</kbd> but adds more |
|
219 |
* dimensions to the array in which the table names are keys and |
|
220 |
* the field names are sub-keys. This is helpful for queries that |
|
221 |
* join tables which have identical field names.</p> |
|
222 |
* |
|
223 |
* <pre> |
|
224 |
* [num_fields] => 3 |
|
225 |
* [ordertable] => Array ( |
|
226 |
* [tblFoo] => Array ( |
|
227 |
* [fldId] => 0 |
|
228 |
* [fldPhone] => 1 |
|
229 |
* ) |
|
230 |
* [tblBar] => Array ( |
|
231 |
* [fldId] => 2 |
|
232 |
* ) |
|
233 |
* ) |
|
234 |
* </pre> |
|
235 |
* |
|
236 |
* </li> |
|
237 |
* </ul> |
|
238 |
* |
|
239 |
* The <samp>flags</samp> element contains a space separated list |
|
240 |
* of extra information about the field. This data is inconsistent |
|
241 |
* between DBMS's due to the way each DBMS works. |
|
242 |
* + <samp>primary_key</samp> |
|
243 |
* + <samp>unique_key</samp> |
|
244 |
* + <samp>multiple_key</samp> |
|
245 |
* + <samp>not_null</samp> |
|
246 |
* |
|
247 |
* Most DBMS's only provide the <samp>table</samp> and <samp>flags</samp> |
|
248 |
* elements if <var>$result</var> is a table name. The following DBMS's |
|
249 |
* provide full information from queries: |
|
250 |
* + fbsql |
|
251 |
* + mysql |
|
252 |
* |
|
253 |
* If the 'portability' option has <samp>MDB2_PORTABILITY_FIX_CASE</samp> |
|
254 |
* turned on, the names of tables and fields will be lower or upper cased. |
|
255 |
* |
|
256 |
* @param object|string $result MDB2_result object from a query or a |
|
257 |
* string containing the name of a table. |
|
258 |
* While this also accepts a query result |
|
259 |
* resource identifier, this behavior is |
|
260 |
* deprecated. |
|
261 |
* @param int $mode either unused or one of the tableInfo modes: |
|
262 |
* <kbd>MDB2_TABLEINFO_ORDERTABLE</kbd>, |
|
263 |
* <kbd>MDB2_TABLEINFO_ORDER</kbd> or |
|
264 |
* <kbd>MDB2_TABLEINFO_FULL</kbd> (which does both). |
|
265 |
* These are bitwise, so the first two can be |
|
266 |
* combined using <kbd>|</kbd>. |
|
267 |
* |
|
268 |
* @return array an associative array with the information requested. |
|
269 |
* A MDB2_Error object on failure. |
|
270 |
* |
|
271 |
* @see MDB2_Driver_Common::setOption() |
|
272 |
*/ |
|
273 |
function tableInfo($result, $mode = null) |
|
274 |
{ |
|
275 |
$db =& $this->getDBInstance(); |
|
276 |
if (PEAR::isError($db)) { |
|
277 |
return $db; |
|
278 |
} |
|
279 |
|
|
280 |
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, |
|
281 |
'tableInfo: method not implemented'); |
|
282 |
} |
|
283 |
} |
|
284 |
?> |