ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilDBPdoManagerPostgres Class Reference

Class ilDBPdoManager. More...

+ Inheritance diagram for ilDBPdoManagerPostgres:
+ Collaboration diagram for ilDBPdoManagerPostgres:

Public Member Functions

 getQueryUtils ()
 
 getTableCreationQuery ($name, $fields, $options=array())
 
 createTable ($name, $fields, $options=array())
 
 listTables ($database=null)
 
 createDatabase ($name)
 
 dropDatabase ($name)
 
 listTableFields ($table)
 
 listTableIndexes ($table)
 
 listTableConstraints ($table)
 
 createSequence ($seq_name, $start=1, $options=array())
 
 dropSequence ($seq_name)
 
 dropIndex ($table, $name)
 
 listSequences ($database=null)
 
 dropConstraint ($table, $name, $primary=false)
 
- Public Member Functions inherited from ilDBPdoManager
 __construct (\PDO $pdo, ilDBPdo $db_instance)
 ilDBPdoManager constructor. More...
 
 getQueryUtils ()
 
 getDBInstance ()
 
 listTables ($database=null)
 
 listSequences ($database=null)
 
 createConstraint ($table, $name, $definition)
 
 createSequence ($seq_name, $start=1, $options=array())
 
 alterTable ($name, $changes, $check)
 
 createTable ($name, $fields, $options=array())
 
 getIndexName ($idx)
 
 getSequenceName ($sqn)
 
 listTableFields ($table)
 
 listTableConstraints ($table)
 
 listTableIndexes ($table)
 
 createIndex ($table, $name, $definition)
 
 dropIndex ($table, $name)
 
 dropSequence ($table_name)
 
 getTableCreationQuery ($name, $fields, $options=array())
 
 dropConstraint ($table, $name, $primary=false)
 
 dropTable ($name)
 
Parameters
$nameTable-name
Returns
mixed
More...
 

Protected Member Functions

 fixIndexName ($idx)
 
- Protected Member Functions inherited from ilDBPdoManager
 fixSequenceName ($sqn, $check=false)
 
 fixIndexName ($idx)
 

Additional Inherited Members

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

Detailed Description

Member Function Documentation

◆ createDatabase()

ilDBPdoManagerPostgres::createDatabase (   $name)
Parameters
$name
Returns
mixed

Definition at line 79 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance, and $name.

80  {
81  $db = $this->db_instance;
82  $name = $db->quoteIdentifier($name, true);
83 
84  return $db->manipulate("CREATE DATABASE $name");
85  }

◆ createSequence()

ilDBPdoManagerPostgres::createSequence (   $seq_name,
  $start = 1,
  $options = array() 
)
Parameters
$seq_name
int$start
array$options
Returns
mixed

Implements ilDBManager.

Definition at line 278 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance, and $start.

279  {
280  $db = $this->db_instance;
281 
282  $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
283 
284  return $db->manipulate("CREATE SEQUENCE $sequence_name INCREMENT 1" . ($start < 1 ? " MINVALUE $start" : '') . " START $start");
285  }
$start
Definition: bench.php:8

◆ createTable()

ilDBPdoManagerPostgres::createTable (   $name,
  $fields,
  $options = array() 
)
Parameters
$name
$fields
array$options
Returns
int

Definition at line 45 of file class.ilDBPdoManagerPostgres.php.

References $name, PHPMailer\PHPMailer\$options, and getQueryUtils().

46  {
47  return $this->pdo->exec($this->getQueryUtils()->createTable($name, $fields, $options));
48  }
createTable($name, $fields, $options=array())
+ Here is the call graph for this function:

◆ dropConstraint()

ilDBPdoManagerPostgres::dropConstraint (   $table,
  $name,
  $primary = false 
)
Parameters
$table
$name
bool$primary
Returns
int

Implements ilDBManager.

Definition at line 365 of file class.ilDBPdoManagerPostgres.php.

References $name, $table, ilDBPdoManager\getDBInstance(), and ilDBPdoManager\getIndexName().

366  {
367  $table_quoted = $this->getDBInstance()->quoteIdentifier($table, true);
368  $name = $this->getDBInstance()->quoteIdentifier($table . '_' . $this->getDBInstance()->getIndexName($name), true);
369 
370  return $this->pdo->exec("ALTER TABLE $table_quoted DROP CONSTRAINT $name");
371  }
if(empty($password)) $table
Definition: pwgen.php:24
+ Here is the call graph for this function:

◆ dropDatabase()

ilDBPdoManagerPostgres::dropDatabase (   $name)
Parameters
$name
Returns
mixed

Definition at line 92 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance, $name, $query, $result, ilDBPdoManager\alterTable(), ilDBPdoManager\getIndexName(), listTableConstraints(), listTableIndexes(), and ilDBConstants\MODULE_REVERSE.

93  {
94  $db = $this->db_instance;
95 
96  $name = $db->quoteIdentifier($name, true);
97 
98  return $db->manipulate("DROP DATABASE $name");
99  }
+ Here is the call graph for this function:

◆ dropIndex()

ilDBPdoManagerPostgres::dropIndex (   $table,
  $name 
)
Parameters
$table
$name
Returns
mixed

Implements ilDBManager.

Definition at line 307 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance, $name, $table, ilDBPdoManager\getDBInstance(), and ilDBPdoManager\getIndexName().

308  {
309  $db = $this->db_instance;
310 
311  $name = $this->getIndexName($name);
312  $name = $db->quoteIdentifier($this->getDBInstance()->constraintName($table, $name), true);
313 
314  return $db->manipulate("DROP INDEX $name");
315  }
if(empty($password)) $table
Definition: pwgen.php:24
+ Here is the call graph for this function:

◆ dropSequence()

ilDBPdoManagerPostgres::dropSequence (   $seq_name)
Parameters
$seq_name
Returns
mixed

Implements ilDBManager.

Definition at line 292 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance.

293  {
294  $db = $this->db_instance;
295 
296  $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
297 
298  return $db->manipulate("DROP SEQUENCE $sequence_name");
299  }

◆ fixIndexName()

ilDBPdoManagerPostgres::fixIndexName (   $idx)
protected
Parameters
$idx
Returns
mixed

Definition at line 322 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoFieldDefinition\INDEX_FORMAT.

Referenced by listTableConstraints(), and listTableIndexes().

323  {
324  $idx_pattern = '/^' . preg_replace('/%s/', '([a-z0-9_]+)', ilDBPdoFieldDefinition::INDEX_FORMAT) . '$/i';
325  $idx_name = preg_replace($idx_pattern, '\\1', $idx);
326  if ($idx_name && !strcasecmp($idx, $this->db_instance->getIndexName($idx_name))) {
327  return $idx_name;
328  }
329 
330  return $idx;
331  }
+ Here is the caller graph for this function:

◆ getQueryUtils()

ilDBPdoManagerPostgres::getQueryUtils ( )
Returns

Definition at line 16 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$query_utils.

Referenced by createTable(), and getTableCreationQuery().

17  {
18  if (!$this->query_utils) {
19  $this->query_utils = new ilPostgresQueryUtils($this->db_instance);
20  }
21 
22  return $this->query_utils;
23  }
Class ilPostgresQueryUtils.
+ Here is the caller graph for this function:

◆ getTableCreationQuery()

ilDBPdoManagerPostgres::getTableCreationQuery (   $name,
  $fields,
  $options = array() 
)
Parameters
$name
$fields
array$options
Returns
string
Exceptions

Definition at line 33 of file class.ilDBPdoManagerPostgres.php.

References $name, PHPMailer\PHPMailer\$options, and getQueryUtils().

34  {
35  return $this->getQueryUtils()->createTable($name, $fields, $options);
36  }
+ Here is the call graph for this function:

◆ listSequences()

ilDBPdoManagerPostgres::listSequences (   $database = null)
Parameters
null$database
Returns
array

Implements ilDBManager.

Definition at line 338 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance, $query, $result, and ilDBPdoManager\fixSequenceName().

339  {
340  $db = $this->db_instance;
341 
342  $query = "SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN";
343  $query .= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
344  $table_names = $db->queryCol($query);
345 
346  $result = array();
347  foreach ($table_names as $table_name) {
348  $result[] = $this->fixSequenceName($table_name);
349  }
350  if ($db->options['portability']) {
351  $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
352  }
353  sort($result); // FSX patch
354 
355  return $result;
356  }
$result
fixSequenceName($sqn, $check=false)
$query
+ Here is the call graph for this function:

◆ listTableConstraints()

ilDBPdoManagerPostgres::listTableConstraints (   $table)
Parameters
$table
Returns
array

Implements ilDBManager.

Definition at line 244 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance, $query, $result, $table, and fixIndexName().

Referenced by dropDatabase().

245  {
246  $db = $this->db_instance;
247 
248  $table = $db->quote($table, 'text');
249  $subquery = "SELECT indexrelid FROM pg_index, pg_class";
250  $subquery .= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND (indisunique = 't' OR indisprimary = 't')";
251  $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
252  $constraints = $db->queryCol($query);
253 
254  $result = array();
255  foreach ($constraints as $constraint) {
256  $constraint = $this->fixIndexName($constraint);
257  if (!empty($constraint)) {
258  $result[$constraint] = true;
259  }
260  }
261 
262  if ($db->options['portability']
263  && $db->options['field_case'] == CASE_LOWER
264  ) {
265  $result = array_change_key_case($result, $db->options['field_case']);
266  }
267 
268  return array_keys($result);
269  }
$result
$query
if(empty($password)) $table
Definition: pwgen.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listTableFields()

ilDBPdoManagerPostgres::listTableFields (   $table)
Parameters
$table
Returns
array

Implements ilDBManager.

Definition at line 197 of file class.ilDBPdoManagerPostgres.php.

References $data, ilDBPdoManager\$db_instance, $i, $res, and $table.

198  {
199  $db = $this->db_instance;
200 
201  $table = $db->quoteIdentifier($table, true);
202  $res = $this->pdo->query("select * from $table");
203  for ($i = 0; $i < $res->columnCount(); $i++) {
204  $data[] = $res->getColumnMeta($i)["name"];
205  }
206  return $data;
207  }
foreach($_POST as $key=> $value) $res
$i
Definition: disco.tpl.php:19
if(empty($password)) $table
Definition: pwgen.php:24
$data
Definition: bench.php:6

◆ listTableIndexes()

ilDBPdoManagerPostgres::listTableIndexes (   $table)
Parameters
$table
Returns
array

Implements ilDBManager.

Definition at line 214 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance, $index, $query, $result, $table, and fixIndexName().

Referenced by dropDatabase().

215  {
216  $db = $this->db_instance;
217 
218  $table = $db->quote($table, 'text');
219  $subquery = "SELECT indexrelid FROM pg_index, pg_class";
220  $subquery .= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND indisunique != 't' AND indisprimary != 't'";
221  $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
222  $indexes = $db->queryCol($query, 'text');
223 
224  $result = array();
225  foreach ($indexes as $index) {
226  $index = $this->fixIndexName($index);
227  if (!empty($index)) {
228  $result[$index] = true;
229  }
230  }
231 
232  if ($db->options['portability']) {
233  $result = array_change_key_case($result, $db->options['field_case']);
234  }
235 
236  return array_keys($result);
237  }
$result
$index
Definition: metadata.php:60
$query
if(empty($password)) $table
Definition: pwgen.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listTables()

ilDBPdoManagerPostgres::listTables (   $database = null)
Parameters
null$database
Returns
array

Implements ilDBManager.

Definition at line 55 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance, $query, $result, and ilDBConstants\FETCHMODE_ASSOC.

56  {
57  $db = $this->db_instance;
58 
59  // gratuitously stolen from PEAR DB _getSpecialQuery in pgsql.php
60  $query = 'SELECT c.relname AS "Name"' . ' FROM pg_class c, pg_user u' . ' WHERE c.relowner = u.usesysid' . " AND c.relkind = 'r'"
61  . ' AND NOT EXISTS' . ' (SELECT 1 FROM pg_views' . ' WHERE viewname = c.relname)' . " AND c.relname !~ '^(pg_|sql_)'" . ' UNION'
62  . ' SELECT c.relname AS "Name"' . ' FROM pg_class c' . " WHERE c.relkind = 'r'" . ' AND NOT EXISTS' . ' (SELECT 1 FROM pg_views'
63  . ' WHERE viewname = c.relname)' . ' AND NOT EXISTS' . ' (SELECT 1 FROM pg_user' . ' WHERE usesysid = c.relowner)'
64  . " AND c.relname !~ '^pg_'";
66 
67  if ($db->options['portability']) {
68  $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
69  }
70  sort($result); // FSX Patch
71  return $result;
72  }
$result
$query

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