ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 77 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance, and $name.

78  {
79  $db = $this->db_instance;
80  $name = $db->quoteIdentifier($name, true);
81 
82  return $db->manipulate("CREATE DATABASE $name");
83  }
if($format !==null) $name
Definition: metadata.php:230

◆ createSequence()

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

Implements ilDBManager.

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

References ilDBPdoManager\$db_instance.

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

◆ createTable()

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

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

References $name, and getQueryUtils().

44  {
45  return $this->pdo->exec($this->getQueryUtils()->createTable($name, $fields, $options));
46  }
createTable($name, $fields, $options=array())
if($format !==null) $name
Definition: metadata.php:230
+ 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 363 of file class.ilDBPdoManagerPostgres.php.

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

364  {
365  $table_quoted = $this->getDBInstance()->quoteIdentifier($table, true);
366  $name = $this->getDBInstance()->quoteIdentifier($table . '_' . $this->getDBInstance()->getIndexName($name), true);
367 
368  return $this->pdo->exec("ALTER TABLE $table_quoted DROP CONSTRAINT $name");
369  }
if($format !==null) $name
Definition: metadata.php:230
+ Here is the call graph for this function:

◆ dropDatabase()

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

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

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

91  {
92  $db = $this->db_instance;
93 
94  $name = $db->quoteIdentifier($name, true);
95 
96  return $db->manipulate("DROP DATABASE $name");
97  }
if($format !==null) $name
Definition: metadata.php:230
+ Here is the call graph for this function:

◆ dropIndex()

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

Implements ilDBManager.

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

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

306  {
307  $db = $this->db_instance;
308 
309  $name = $this->getIndexName($name);
310  $name = $db->quoteIdentifier($this->getDBInstance()->constraintName($table, $name), true);
311 
312  return $db->manipulate("DROP INDEX $name");
313  }
if($format !==null) $name
Definition: metadata.php:230
+ Here is the call graph for this function:

◆ dropSequence()

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

Implements ilDBManager.

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

References ilDBPdoManager\$db_instance.

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

◆ fixIndexName()

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

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

References ilDBPdoFieldDefinition\INDEX_FORMAT.

Referenced by listTableConstraints(), and listTableIndexes().

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

◆ getQueryUtils()

ilDBPdoManagerPostgres::getQueryUtils ( )
Returns

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

References ilDBPdoManager\$query_utils.

Referenced by createTable(), and getTableCreationQuery().

15  {
16  if (!$this->query_utils) {
17  $this->query_utils = new ilPostgresQueryUtils($this->db_instance);
18  }
19 
20  return $this->query_utils;
21  }
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 31 of file class.ilDBPdoManagerPostgres.php.

References $name, and getQueryUtils().

32  {
33  return $this->getQueryUtils()->createTable($name, $fields, $options);
34  }
if($format !==null) $name
Definition: metadata.php:230
+ Here is the call graph for this function:

◆ listSequences()

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

Implements ilDBManager.

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

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

337  {
338  $db = $this->db_instance;
339 
340  $query = "SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN";
341  $query .= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
342  $table_names = $db->queryCol($query);
343 
344  $result = array();
345  foreach ($table_names as $table_name) {
346  $result[] = $this->fixSequenceName($table_name);
347  }
348  if ($db->options['portability']) {
349  $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
350  }
351  sort($result); // FSX patch
352 
353  return $result;
354  }
$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 242 of file class.ilDBPdoManagerPostgres.php.

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

Referenced by dropDatabase().

243  {
244  $db = $this->db_instance;
245 
246  $table = $db->quote($table, 'text');
247  $subquery = "SELECT indexrelid FROM pg_index, pg_class";
248  $subquery .= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND (indisunique = 't' OR indisprimary = 't')";
249  $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
250  $constraints = $db->queryCol($query);
251 
252  $result = array();
253  foreach ($constraints as $constraint) {
254  $constraint = $this->fixIndexName($constraint);
255  if (!empty($constraint)) {
256  $result[$constraint] = true;
257  }
258  }
259 
260  if ($db->options['portability']
261  && $db->options['field_case'] == CASE_LOWER
262  ) {
263  $result = array_change_key_case($result, $db->options['field_case']);
264  }
265 
266  return array_keys($result);
267  }
$result
$query
+ 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 195 of file class.ilDBPdoManagerPostgres.php.

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

196  {
197  $db = $this->db_instance;
198 
199  $table = $db->quoteIdentifier($table, true);
200  $res = $this->pdo->query("select * from $table");
201  for ($i = 0; $i < $res->columnCount(); $i++) {
202  $data[] = $res->getColumnMeta($i)["name"];
203  }
204  return $data;
205  }
$data
Definition: storeScorm.php:23
foreach($_POST as $key=> $value) $res
$i
Definition: metadata.php:24

◆ listTableIndexes()

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

Implements ilDBManager.

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

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

Referenced by dropDatabase().

213  {
214  $db = $this->db_instance;
215 
216  $table = $db->quote($table, 'text');
217  $subquery = "SELECT indexrelid FROM pg_index, pg_class";
218  $subquery .= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND indisunique != 't' AND indisprimary != 't'";
219  $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
220  $indexes = $db->queryCol($query, 'text');
221 
222  $result = array();
223  foreach ($indexes as $index) {
224  $index = $this->fixIndexName($index);
225  if (!empty($index)) {
226  $result[$index] = true;
227  }
228  }
229 
230  if ($db->options['portability']) {
231  $result = array_change_key_case($result, $db->options['field_case']);
232  }
233 
234  return array_keys($result);
235  }
$result
$index
Definition: metadata.php:128
$query
+ 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 53 of file class.ilDBPdoManagerPostgres.php.

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

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

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