ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilDBPdoReversePostgres Class Reference

Class ilDBPdoReverse. More...

+ Inheritance diagram for ilDBPdoReversePostgres:
+ Collaboration diagram for ilDBPdoReversePostgres:

Public Member Functions

 getTableConstraintDefinition ($table, $constraint_name)
 Get the structure of a constraint 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 ilDBPdoReverse
 __construct (\PDO $pdo, ilDBPdo $db_instance)
 ilDBPdoReverse constructor. More...
 
 getQueryUtils ()
 
 getTableFieldDefinition ($table_name, $field_name)
 
 getTableIndexDefinition ($table, $index_name)
 
 getTableConstraintDefinition ($table, $constraint_name)
 
 getTriggerDefinition ($trigger)
 
 tableInfo ($result, $mode=null)
 
 getTableFieldDefinition ($table_name, $field_name)
 
 getTableIndexDefinition ($table, $constraint_name)
 
 getTableConstraintDefinition ($table, $index_name)
 
 getTriggerDefinition ($trigger)
 
 tableInfo ($result, $mode=null)
 

Additional Inherited Members

- Protected Attributes inherited from ilDBPdoReverse
 $pdo
 
 $db_instance
 
 $query_utils
 

Detailed Description

Member Function Documentation

◆ getTableConstraintDefinition()

ilDBPdoReversePostgres::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 ilDBPdoReverse.

Definition at line 186 of file class.ilDBPdoReversePostgres.php.

186 {
187 $db = $this->db_instance;
188
189 $query = 'SELECT relname, indisunique, indisprimary, indkey FROM pg_index, pg_class';
190 $query .= ' WHERE pg_class.oid = pg_index.indexrelid';
191 $query .= " AND (indisunique = 't' OR indisprimary = 't')";
192 $query .= ' AND pg_class.relname = %s';
193 $constraint_name_mdb2 = $db->getIndexName($constraint_name);
194 try {
195 $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, ilDBConstants::FETCHMODE_ASSOC);
196 } catch (Exception $e) {
197 }
198
199 if ($e instanceof PDOException || empty($row)) {
200 // fallback to the given $index_name, without transformation
201 $row = $db->queryRow(sprintf($query, $db->quote($constraint_name, 'text')), null, ilDBConstants::FETCHMODE_ASSOC);
202 }
203
204 if (empty($row)) {
205 throw new ilDatabaseException($constraint_name . ' is not an existing table constraint');
206 }
207
208 $row = array_change_key_case($row, CASE_LOWER);
209 $columns = $db->loadModule(ilDBConstants::MODULE_MANAGER)->listTableFields($table);
210
211 $definition = array();
212 if ($row['indisprimary'] == 't') {
213 $definition['primary'] = true;
214 } elseif ($row['indisunique'] == 't') {
215 $definition['unique'] = true;
216 }
217
218 $index_column_numbers = explode(' ', $row['indkey']);
219
220 $colpos = 1;
221 foreach ($index_column_numbers as $number) {
222 $definition['fields'][$columns[($number - 1)]] = array(
223 'position' => $colpos ++,
224 'sorting' => 'ascending',
225 );
226 }
227
228 return $definition;
229 }
sprintf('%.4f', $callTime)
if(! $in) $columns
Definition: Utf8Test.php:45
Class ilDatabaseException.

References $columns, ilDBPdoReverse\$db_instance, $query, $row, ilDBConstants\FETCHMODE_ASSOC, ilDBConstants\MODULE_MANAGER, and sprintf.

◆ getTriggerDefinition()

ilDBPdoReversePostgres::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

@TODO : add support for plsql functions and functions with args

Reimplemented from ilDBPdoReverse.

Definition at line 248 of file class.ilDBPdoReversePostgres.php.

248 {
249 $db = $this->db_instance;
250
251 $query = "SELECT trg.tgname AS trigger_name,
252 tbl.relname AS table_name,
253 CASE
254 WHEN p.proname IS NOT NULL THEN 'EXECUTE PROCEDURE ' || p.proname || '();'
255 ELSE ''
256 END AS trigger_body,
257 CASE trg.tgtype & cast(2 as int2)
258 WHEN 0 THEN 'AFTER'
259 ELSE 'BEFORE'
260 END AS trigger_type,
261 CASE trg.tgtype & cast(28 as int2)
262 WHEN 16 THEN 'UPDATE'
263 WHEN 8 THEN 'DELETE'
264 WHEN 4 THEN 'INSERT'
265 WHEN 20 THEN 'INSERT, UPDATE'
266 WHEN 28 THEN 'INSERT, UPDATE, DELETE'
267 WHEN 24 THEN 'UPDATE, DELETE'
268 WHEN 12 THEN 'INSERT, DELETE'
269 END AS trigger_event,
270 trg.tgenabled AS trigger_enabled,
271 obj_description(trg.oid, 'pg_trigger') AS trigger_comment
272 FROM pg_trigger trg,
273 pg_class tbl,
274 pg_proc p
275 WHERE trg.tgrelid = tbl.oid
276 AND trg.tgfoid = p.oid
277 AND trg.tgname = " . $db->quote($trigger, 'text');
278 $types = array(
279 'trigger_name' => 'text',
280 'table_name' => 'text',
281 'trigger_body' => 'text',
282 'trigger_type' => 'text',
283 'trigger_event' => 'text',
284 'trigger_comment' => 'text',
285 'trigger_enabled' => 'boolean',
286 );
287
288 return $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
289 }
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
Definition: MDB2.php:134

References ilDBPdoReverse\$db_instance, $query, and MDB2_FETCHMODE_ASSOC.

◆ tableInfo()

ilDBPdoReversePostgres::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.

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 ilDBPdoReverse.

Definition at line 312 of file class.ilDBPdoReversePostgres.php.

312 {
313 if (is_string($result)) {
314 return parent::tableInfo($result, $mode);
315 }
316
317 $db = $this->db_instance;
318
319 $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
320 if (!is_resource($resource)) {
321 return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'Could not generate result resource', __FUNCTION__);
322 }
323
324 if ($db->options['portability']) {
325 if ($db->options['field_case'] == CASE_LOWER) {
326 $case_func = 'strtolower';
327 } else {
328 $case_func = 'strtoupper';
329 }
330 } else {
331 $case_func = 'strval';
332 }
333
334 $count = @pg_num_fields($resource);
335 $res = array();
336
337 if ($mode) {
338 $res['num_fields'] = $count;
339 }
340
341 $db->loadModule('Datatype', null, true);
342 for ($i = 0; $i < $count; $i ++) {
343 $res[$i] = array(
344 'table' => function_exists('pg_field_table') ? @pg_field_table($resource, $i) : '',
345 'name' => $case_func(@pg_field_name($resource, $i)),
346 'type' => @pg_field_type($resource, $i),
347 'length' => @pg_field_size($resource, $i),
348 'flags' => '',
349 );
350 $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
351 if (PEAR::isError($mdb2type_info)) {
352 return $mdb2type_info;
353 }
354 $res[$i]['mdb2type'] = $mdb2type_info[0][0];
355 if ($mode & MDB2_TABLEINFO_ORDER) {
356 $res['order'][$res[$i]['name']] = $i;
357 }
358 if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
359 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
360 }
361 }
362
363 return $res;
364 }
$result
const MDB2_ERROR_NEED_MORE_DATA
Definition: MDB2.php:92
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:660
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280

References ilDBPdoReverse\$db_instance, $res, $result, PEAR\isError(), MDB2\isResultCommon(), MDB2_ERROR_NEED_MORE_DATA, 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: