ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 189 of file class.ilDBPdoReversePostgres.php.

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

References $columns, ilDBPdoReverse\$db_instance, $query, $row, $table, 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 252 of file class.ilDBPdoReversePostgres.php.

253 {
254 $db = $this->db_instance;
255
256 $query = "SELECT trg.tgname AS trigger_name,
257 tbl.relname AS table_name,
258 CASE
259 WHEN p.proname IS NOT NULL THEN 'EXECUTE PROCEDURE ' || p.proname || '();'
260 ELSE ''
261 END AS trigger_body,
262 CASE trg.tgtype & cast(2 as int2)
263 WHEN 0 THEN 'AFTER'
264 ELSE 'BEFORE'
265 END AS trigger_type,
266 CASE trg.tgtype & cast(28 as int2)
267 WHEN 16 THEN 'UPDATE'
268 WHEN 8 THEN 'DELETE'
269 WHEN 4 THEN 'INSERT'
270 WHEN 20 THEN 'INSERT, UPDATE'
271 WHEN 28 THEN 'INSERT, UPDATE, DELETE'
272 WHEN 24 THEN 'UPDATE, DELETE'
273 WHEN 12 THEN 'INSERT, DELETE'
274 END AS trigger_event,
275 trg.tgenabled AS trigger_enabled,
276 obj_description(trg.oid, 'pg_trigger') AS trigger_comment
277 FROM pg_trigger trg,
278 pg_class tbl,
279 pg_proc p
280 WHERE trg.tgrelid = tbl.oid
281 AND trg.tgfoid = p.oid
282 AND trg.tgname = " . $db->quote($trigger, 'text');
283 $types = array(
284 'trigger_name' => 'text',
285 'table_name' => 'text',
286 'trigger_body' => 'text',
287 'trigger_type' => 'text',
288 'trigger_event' => 'text',
289 'trigger_comment' => 'text',
290 'trigger_enabled' => 'boolean',
291 );
292
293 return $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
294 }
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 317 of file class.ilDBPdoReversePostgres.php.

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

References ilDBPdoReverse\$db_instance, $i, $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: