ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 
- 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)
 

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 public

Implements ilDBReverse.

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

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

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  }
Class ilDatabaseException.
$query
$row
if(empty($password)) $table
Definition: pwgen.php:24
if(! $in) $columns
Definition: Utf8Test.php:45

◆ 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 public

: add support for plsql functions and functions with args

Implements ilDBReverse.

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

References ilDBPdoReverse\$db_instance, $query, and ilDBConstants\FETCHMODE_ASSOC.

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, ilDBConstants::FETCHMODE_ASSOC);
294  }
$query

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