ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
MDB2_Driver_Reverse_oci8 Class Reference
+ Inheritance diagram for MDB2_Driver_Reverse_oci8:
+ Collaboration diagram for MDB2_Driver_Reverse_oci8:

Public Member Functions

 getTableFieldDefinition ($table, $field_name)
 Get the structure of a field into an array. More...
 
 getTableIndexDefinition ($table, $index_name)
 Get the structure of an index into an array. More...
 
 getTableConstraintDefinition ($table, $constraint_name)
 Get the structure of a constraint into an array. More...
 
 getSequenceDefinition ($sequence)
 Get the structure of a sequence into an array. More...
 
 getTriggerDefinition ($trigger)
 Get the structure of a trigger into an array. More...
 
 tableInfo ($result, $mode=null)
 Returns information about a table or a result set. More...
 
 getTableFieldDefinition ($table, $field)
 Get the structure of a field into an array. More...
 
 getTableIndexDefinition ($table, $index)
 Get the structure of an index into an array. More...
 
 getTableConstraintDefinition ($table, $index)
 Get the structure of an constraints into an array. More...
 
 getSequenceDefinition ($sequence)
 Get the structure of a sequence into an array. More...
 
 getTriggerDefinition ($trigger)
 Get the structure of a trigger into an array. More...
 
 tableInfo ($result, $mode=null)
 Returns information about a table or a result set. More...
 
- Public Member Functions inherited from MDB2_Module_Common
 __construct ($db_index)
 Constructor. More...
 
 MDB2_Module_Common ($db_index)
 PHP 4 Constructor. More...
 
getDBInstance ()
 Get the instance of MDB2 associated with the module instance. More...
 

Additional Inherited Members

- Data Fields inherited from MDB2_Module_Common
 $db_index
 

Detailed Description

Definition at line 57 of file oci8.php.

Member Function Documentation

◆ getSequenceDefinition()

MDB2_Driver_Reverse_oci8::getSequenceDefinition (   $sequence)

Get the structure of a sequence into an array.

Parameters
string$sequencename of sequence that should be used in method
Returns
mixed data array on success, a MDB2 error on failure @access public

Reimplemented from MDB2_Driver_Reverse_Common.

Definition at line 366 of file oci8.php.

367 {
368 $db =& $this->getDBInstance();
369 if (PEAR::isError($db)) {
370 return $db;
371 }
372
373 $sequence_name = $db->getSequenceName($sequence);
374 $query = 'SELECT last_number FROM user_sequences';
375 $query.= ' WHERE sequence_name='.$db->quote($sequence_name, 'text');
376 $query.= ' OR sequence_name='.$db->quote(strtoupper($sequence_name), 'text');
377 $start = $db->queryOne($query, 'integer');
378 if (PEAR::isError($start)) {
379 return $start;
380 }
381 $definition = array();
382 if ($start != 1) {
383 $definition = array('start' => $start);
384 }
385 return $definition;
386 }
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4206
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279

References $query, MDB2_Module_Common\getDBInstance(), and PEAR\isError().

+ Here is the call graph for this function:

◆ getTableConstraintDefinition()

MDB2_Driver_Reverse_oci8::getTableConstraintDefinition (   $table,
  $constraint_name 
)

Get the structure of a constraint into an array.

Parameters
string$tablename of table that should be used in method
string$constraint_namename of constraint that should be used in method
Returns
mixed data array on success, a MDB2 error on failure @access public

Reimplemented from MDB2_Driver_Reverse_Common.

Definition at line 267 of file oci8.php.

268 {
269 $db =& $this->getDBInstance();
270 if (PEAR::isError($db)) {
271 return $db;
272 }
273
274 $query = 'SELECT alc.constraint_name,
275 alc.constraint_type,
276 alc.search_condition,
277 alc.r_constraint_name,
278 alc.search_condition,
279 cols.column_name,
280 cols.position
281 FROM all_constraints alc,
282 all_cons_columns cols
283 WHERE (alc.constraint_name=%s OR alc.constraint_name=%s)
284 AND alc.constraint_name = cols.constraint_name
285 AND alc.owner = '.$db->quote(strtoupper($db->dsn['username']), 'text');
286 if (!empty($table)) {
287 $query.= ' AND (alc.table_name='.$db->quote($table, 'text').' OR alc.table_name='.$db->quote(strtoupper($table), 'text').')';
288 }
289 if (strtolower($constraint_name) != 'primary') {
290 $constraint_name_mdb2 = $db->getIndexName($constraint_name);
291 $sql = sprintf($query,
292 $db->quote($constraint_name_mdb2, 'text'),
293 $db->quote(strtoupper($constraint_name_mdb2), 'text')
294 );
295 $result = $db->queryRow($sql);
296 if (!PEAR::isError($result) && !is_null($result)) {
297 // apply 'idxname_format' only if the query succeeded, otherwise
298 // fallback to the given $index_name, without transformation
299 $constraint_name = $constraint_name_mdb2;
300 }
301 }
302 $sql = sprintf($query,
303 $db->quote($constraint_name, 'text'),
304 $db->quote(strtoupper($constraint_name), 'text')
305 );
306 $result = $db->query($sql);
307 if (PEAR::isError($result)) {
308 return $result;
309 }
310 $definition = array();
311 while (is_array($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
312 $row = array_change_key_case($row, CASE_LOWER);
313 $column_name = $row['column_name'];
314 if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
315 if ($db->options['field_case'] == CASE_LOWER) {
316 $column_name = strtolower($column_name);
317 } else {
318 $column_name = strtoupper($column_name);
319 }
320 }
321 $definition['fields'][$column_name] = array(
322 'position' => (int)$row['position']
323 );
324 $lastrow = $row;
325 // otherwise $row is no longer usable on exit from loop
326 }
327 $result->free();
328 if (empty($definition)) {
329 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
330 $constraint_name . ' is not an existing table constraint', __FUNCTION__);
331 }
332 if ($lastrow['constraint_type'] === 'P') {
333 $definition['primary'] = true;
334 } elseif ($lastrow['constraint_type'] === 'U') {
335 $definition['unique'] = true;
336 } elseif ($lastrow['constraint_type'] === 'R') {
337 $definition['foreign'] = $lastrow['r_constraint_name'];
338 } elseif ($lastrow['constraint_type'] === 'C') {
339 $definition['check'] = true;
340 // pattern match constraint for check constraint values into enum-style output:
341 $enumregex = '/'.$lastrow['column_name'].' in \‍((.+?)\‍)/i';
342 if (preg_match($enumregex, $lastrow['search_condition'], $rangestr)) {
343 $definition['fields'][$column_name] = array();
344 $allowed = explode(',', $rangestr[1]);
345 foreach ($allowed as $val) {
346 $val = trim($val);
347 $val = preg_replace('/^\'/', '', $val);
348 $val = preg_replace('/\'$/', '', $val);
349 array_push($definition['fields'][$column_name], $val);
350 }
351 }
352 }
353 return $definition;
354 }
$result
const MDB2_PORTABILITY_FIX_CASE
Portability: convert names of tables and fields to case defined in the "field_case" option when using...
Definition: MDB2.php:158
const MDB2_ERROR_NOT_FOUND
Definition: MDB2.php:71
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
Definition: MDB2.php:129

References $query, $result, $row, MDB2_Module_Common\getDBInstance(), PEAR\isError(), MDB2_ERROR_NOT_FOUND, MDB2_FETCHMODE_ASSOC, and MDB2_PORTABILITY_FIX_CASE.

+ Here is the call graph for this function:

◆ getTableFieldDefinition()

MDB2_Driver_Reverse_oci8::getTableFieldDefinition (   $table,
  $field_name 
)

Get the structure of a field into an array.

Parameters
string$tablename of table that should be used in method
string$field_namename of field that should be used in method
Returns
mixed data array on success, a MDB2 error on failure @access public

Reimplemented from MDB2_Driver_Reverse_Common.

Definition at line 69 of file oci8.php.

70 {
71 $db =& $this->getDBInstance();
72 if (PEAR::isError($db)) {
73 return $db;
74 }
75
76 $result = $db->loadModule('Datatype', null, true);
78 return $result;
79 }
80
81 $query = 'SELECT column_name name, data_type "type", nullable, data_default "default"';
82 $query.= ', COALESCE(data_precision, data_length) "length", data_scale "scale"';
83 $query.= ' FROM user_tab_columns';
84 $query.= ' WHERE (table_name='.$db->quote($table, 'text').' OR table_name='.$db->quote(strtoupper($table), 'text').')';
85 $query.= ' AND (column_name='.$db->quote($field_name, 'text').' OR column_name='.$db->quote(strtoupper($field_name), 'text').')';
86 $query.= ' ORDER BY column_id';
87 $column = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC);
88 if (PEAR::isError($column)) {
89 return $column;
90 }
91
92 if (empty($column)) {
93 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
94 'it was not specified an existing table column', __FUNCTION__);
95 }
96
97 $column = array_change_key_case($column, CASE_LOWER);
98 if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
99 if ($db->options['field_case'] == CASE_LOWER) {
100 $column['name'] = strtolower($column['name']);
101 } else {
102 $column['name'] = strtoupper($column['name']);
103 }
104 }
105 $mapped_datatype = $db->datatype->mapNativeDatatype($column);
106 if (PEAR::IsError($mapped_datatype)) {
107 return $mapped_datatype;
108 }
109 list($types, $length, $unsigned, $fixed) = $mapped_datatype;
110 $notnull = false;
111 if (!empty($column['nullable']) && $column['nullable'] == 'N') {
112 $notnull = true;
113 }
114 $default = false;
115 if (array_key_exists('default', $column)) {
116 $default = $column['default'];
117 if ($default === 'NULL') {
118 $default = null;
119 }
120 if (is_null($default) && $notnull) {
121 $default = '';
122 }
123 }
124
125 $definition[0] = array('notnull' => $notnull, 'nativetype' => $column['type']);
126 if (!is_null($length)) {
127 $definition[0]['length'] = $length;
128 }
129 if (!is_null($unsigned)) {
130 $definition[0]['unsigned'] = $unsigned;
131 }
132 if (!is_null($fixed)) {
133 $definition[0]['fixed'] = $fixed;
134 }
135 if ($default !== false) {
136 $definition[0]['default'] = $default;
137 }
138 foreach ($types as $key => $type) {
139 $definition[$key] = $definition[0];
140 if ($type == 'clob' || $type == 'blob') {
141 unset($definition[$key]['default']);
142 }
143 $definition[$key]['type'] = $type;
144 $definition[$key]['mdb2type'] = $type;
145 }
146 if ($type == 'integer') {
147 $query = "SELECT DISTINCT name
148 FROM all_source
149 WHERE type='TRIGGER'
150 AND UPPER(text) like '%ON ". strtoupper($db->escape($table, 'text')) ."%'";
151 $result = $db->query($query);
152 if (!PEAR::isError($result)) {
153 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
154 $row = array_change_key_case($row, CASE_LOWER);
155 $trquery = 'SELECT text
156 FROM all_source
157 WHERE name=' . $db->quote($row['name'],'text')
158 . ' ORDER BY line';
159 $triggersth = $db->query($trquery);
160 $triggerstr = '';
161 while ($triggerline = $triggersth->fetchRow(MDB2_FETCHMODE_ASSOC)) {
162 $triggerline = array_change_key_case($triggerline,CASE_LOWER);
163 $triggerstr .= $triggerline['text']. ' ';
164 }
165 $matches = array();
166 if (preg_match('/.*\W(.+)\.nextval into :NEW\.'.$field_name.' FROM dual/i', $triggerstr, $matches)) {
167 // we reckon it's an autoincrementing trigger on field_name
168 // there will be other pcre patterns needed here for other ways of mimicking auto_increment in ora.
169 $definition[0]['autoincrement'] = $matches[1];
170 }
171 }
172 }
173 }
174 return $definition;
175 }

References $query, $result, $row, MDB2_Module_Common\getDBInstance(), PEAR\isError(), MDB2_ERROR_NOT_FOUND, MDB2_FETCHMODE_ASSOC, and MDB2_PORTABILITY_FIX_CASE.

+ Here is the call graph for this function:

◆ getTableIndexDefinition()

MDB2_Driver_Reverse_oci8::getTableIndexDefinition (   $table,
  $index_name 
)

Get the structure of an index into an array.

Parameters
string$tablename of table that should be used in method
string$index_namename of index that should be used in method
Returns
mixed data array on success, a MDB2 error on failure @access public

Reimplemented from MDB2_Driver_Reverse_Common.

Definition at line 189 of file oci8.php.

190 {
191 $db =& $this->getDBInstance();
192 if (PEAR::isError($db)) {
193 return $db;
194 }
195
196 $query = "SELECT column_name,
197 column_position,
198 descend
199 FROM user_ind_columns
200 WHERE (table_name=".$db->quote($table, 'text').' OR table_name='.$db->quote(strtoupper($table), 'text').')
201 AND (index_name=%s OR index_name=%s)
202 AND index_name NOT IN (
203 SELECT constraint_name
204 FROM dba_constraints
205 WHERE (table_name = '.$db->quote($table, 'text').' OR table_name='.$db->quote(strtoupper($table), 'text').")
206 AND constraint_type in ('P','U')
207 )
208 ORDER BY column_position";
209 $index_name_mdb2 = $db->getIndexName($index_name);
210 $sql = sprintf($query,
211 $db->quote($index_name_mdb2, 'text'),
212 $db->quote(strtoupper($index_name_mdb2), 'text')
213 );
214 $result = $db->queryRow($sql);
215 if (!PEAR::isError($result) && !is_null($result)) {
216 // apply 'idxname_format' only if the query succeeded, otherwise
217 // fallback to the given $index_name, without transformation
218 $index_name = $index_name_mdb2;
219 }
220 $sql = sprintf($query,
221 $db->quote($index_name, 'text'),
222 $db->quote(strtoupper($index_name), 'text')
223 );
224 $result = $db->query($sql);
225 if (PEAR::isError($result)) {
226 return $result;
227 }
228
229 $definition = array();
230 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
231 $row = array_change_key_case($row, CASE_LOWER);
232 $column_name = $row['column_name'];
233 if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
234 if ($db->options['field_case'] == CASE_LOWER) {
235 $column_name = strtolower($column_name);
236 } else {
237 $column_name = strtoupper($column_name);
238 }
239 }
240 $definition['fields'][$column_name] = array(
241 'position' => (int)$row['column_position'],
242 );
243 if (!empty($row['descend'])) {
244 $definition['fields'][$column_name]['sorting'] =
245 ($row['descend'] == 'ASC' ? 'ascending' : 'descending');
246 }
247 }
248 $result->free();
249 if (empty($definition['fields'])) {
250 return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
251 'it was not specified an existing table index', __FUNCTION__);
252 }
253 return $definition;
254 }

References $query, $result, $row, MDB2_Module_Common\getDBInstance(), PEAR\isError(), MDB2_ERROR_NOT_FOUND, MDB2_FETCHMODE_ASSOC, and MDB2_PORTABILITY_FIX_CASE.

+ Here is the call graph for this function:

◆ getTriggerDefinition()

MDB2_Driver_Reverse_oci8::getTriggerDefinition (   $trigger)

Get the structure of a trigger into an array.

EXPERIMENTAL

WARNING: this function is experimental and may change the returned value at any time until labelled as non-experimental

Parameters
string$triggername of trigger that should be used in method
Returns
mixed data array on success, a MDB2 error on failure @access public

Reimplemented from MDB2_Driver_Reverse_Common.

Definition at line 403 of file oci8.php.

404 {
405 $db =& $this->getDBInstance();
406 if (PEAR::isError($db)) {
407 return $db;
408 }
409
410 $query = 'SELECT trigger_name,
411 table_name,
412 trigger_body,
413 trigger_type,
414 triggering_event trigger_event,
415 description trigger_comment,
416 1 trigger_enabled,
417 when_clause
418 FROM user_triggers
419 WHERE trigger_name = \''. strtoupper($trigger).'\'';
420 $types = array(
421 'trigger_name' => 'text',
422 'table_name' => 'text',
423 'trigger_body' => 'text',
424 'trigger_type' => 'text',
425 'trigger_event' => 'text',
426 'trigger_comment' => 'text',
427 'trigger_enabled' => 'boolean',
428 'when_clause' => 'text',
429 );
430 $result = $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
431 if (PEAR::isError($result)) {
432 return $result;
433 }
434 if (!empty($result['trigger_type'])) {
435 //$result['trigger_type'] = array_shift(explode(' ', $result['trigger_type']));
436 $result['trigger_type'] = preg_replace('/(\S+).*/', '\\1', $result['trigger_type']);
437 }
438 return $result;
439 }

References $query, $result, MDB2_Module_Common\getDBInstance(), PEAR\isError(), and MDB2_FETCHMODE_ASSOC.

+ Here is the call graph for this function:

◆ tableInfo()

MDB2_Driver_Reverse_oci8::tableInfo (   $result,
  $mode = null 
)

Returns information about a table or a result set.

NOTE: only supports 'table' and 'flags' if $result is a table name.

NOTE: flags won't contain index information.

Parameters
object | string$resultMDB2_result object from a query or a string containing the name of a table. While this also accepts a query result resource identifier, this behavior is deprecated.
int$modea valid tableInfo mode
Returns
array an associative array with the information requested. A MDB2_Error object on failure.
See also
MDB2_Driver_Common::tableInfo()

Reimplemented from MDB2_Driver_Reverse_Common.

Definition at line 464 of file oci8.php.

465 {
466 if (is_string($result)) {
467 return parent::tableInfo($result, $mode);
468 }
469
470 $db =& $this->getDBInstance();
471 if (PEAR::isError($db)) {
472 return $db;
473 }
474
475 $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
476 if (!is_resource($resource)) {
477 return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
478 'Could not generate result resource', __FUNCTION__);
479 }
480
481 if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
482 if ($db->options['field_case'] == CASE_LOWER) {
483 $case_func = 'strtolower';
484 } else {
485 $case_func = 'strtoupper';
486 }
487 } else {
488 $case_func = 'strval';
489 }
490
491 $count = @OCINumCols($resource);
492 $res = array();
493
494 if ($mode) {
495 $res['num_fields'] = $count;
496 }
497
498 $db->loadModule('Datatype', null, true);
499 for ($i = 0; $i < $count; $i++) {
500 $column = array(
501 'table' => '',
502 'name' => $case_func(@OCIColumnName($resource, $i+1)),
503 'type' => @OCIColumnType($resource, $i+1),
504 'length' => @OCIColumnSize($resource, $i+1),
505 'flags' => '',
506 );
507 $res[$i] = $column;
508 $res[$i]['mdb2type'] = $db->datatype->mapNativeDatatype($res[$i]);
509 if ($mode & MDB2_TABLEINFO_ORDER) {
510 $res['order'][$res[$i]['name']] = $i;
511 }
512 if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
513 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
514 }
515 }
516 return $res;
517 }
const MDB2_ERROR_NEED_MORE_DATA
Definition: MDB2.php:87
const MDB2_TABLEINFO_ORDERTABLE
Definition: Common.php:60
const MDB2_TABLEINFO_ORDER
These are constants for the tableInfo-function they are bitwised or'ed.
Definition: Common.php:59
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
Definition: MDB2.php:655

References $res, $result, MDB2_Module_Common\getDBInstance(), PEAR\isError(), MDB2\isResultCommon(), MDB2_ERROR_NEED_MORE_DATA, MDB2_PORTABILITY_FIX_CASE, MDB2_TABLEINFO_ORDER, and MDB2_TABLEINFO_ORDERTABLE.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: