ILIAS  release_7 Revision v7.30-3-g800a261c036
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)
 
 getTableFieldDefinition ($table_name, $field_name)
 
 getTableIndexDefinition ($table, $constraint_name)
 
 getTableConstraintDefinition ($table, $index_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 @access public

Reimplemented from ilDBPdoReverse.

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

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

References $columns, ilDBPdoReverse\$db_instance, Vendor\Package\$e, $query, ilDBConstants\FETCHMODE_ASSOC, and ilDBConstants\MODULE_MANAGER.

◆ 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 251 of file class.ilDBPdoReversePostgres.php.

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

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


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