ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 74 of file class.ilDBPdoManagerPostgres.php.

References ilDBPdoManager\$db_instance.

74  {
75  $db = $this->db_instance;
76  $name = $db->quoteIdentifier($name, true);
77 
78  return $db->manipulate("CREATE DATABASE $name");
79  }

◆ createSequence()

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

Implements ilDBManager.

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

References ilDBPdoManager\$db_instance, and $start.

268  {
269  $db = $this->db_instance;
270 
271  $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
272 
273  return $db->manipulate("CREATE SEQUENCE $sequence_name INCREMENT 1" . ($start < 1 ? " MINVALUE $start" : '') . " START $start");
274  }

◆ createTable()

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

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

References $options, and getQueryUtils().

42  {
43  return $this->pdo->exec($this->getQueryUtils()->createTable($name, $fields, $options));
44  }
createTable($name, $fields, $options=array())
if(!is_array($argv)) $options
+ 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 350 of file class.ilDBPdoManagerPostgres.php.

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

350  {
351  $table_quoted = $this->getDBInstance()->quoteIdentifier($table, true);
352  $name = $this->getDBInstance()->quoteIdentifier($table . '_' . $this->getDBInstance()->getIndexName($name), true);
353 
354  return $this->pdo->exec("ALTER TABLE $table_quoted DROP CONSTRAINT $name");
355  }
+ Here is the call graph for this function:

◆ dropDatabase()

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

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

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

86  {
87  $db = $this->db_instance;
88 
89  $name = $db->quoteIdentifier($name, true);
90 
91  return $db->manipulate("DROP DATABASE $name");
92  }
+ Here is the call graph for this function:

◆ dropIndex()

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

Implements ilDBManager.

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

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

295  {
296  $db = $this->db_instance;
297 
298  $name = $this->getIndexName($name);
299  $name = $db->quoteIdentifier($this->getDBInstance()->constraintName($table, $name), true);
300 
301  return $db->manipulate("DROP INDEX $name");
302  }
+ Here is the call graph for this function:

◆ dropSequence()

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

Implements ilDBManager.

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

References ilDBPdoManager\$db_instance.

281  {
282  $db = $this->db_instance;
283 
284  $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
285 
286  return $db->manipulate("DROP SEQUENCE $sequence_name");
287  }

◆ fixIndexName()

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

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

References ilDBPdoFieldDefinition\INDEX_FORMAT.

Referenced by listTableConstraints(), and listTableIndexes().

309  {
310  $idx_pattern = '/^' . preg_replace('/%s/', '([a-z0-9_]+)', ilDBPdoFieldDefinition::INDEX_FORMAT) . '$/i';
311  $idx_name = preg_replace($idx_pattern, '\\1', $idx);
312  if ($idx_name && !strcasecmp($idx, $this->db_instance->getIndexName($idx_name))) {
313  return $idx_name;
314  }
315 
316  return $idx;
317  }
+ Here is the caller graph for this function:

◆ getQueryUtils()

ilDBPdoManagerPostgres::getQueryUtils ( )
Returns

Definition at line 15 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 $options, and getQueryUtils().

31  {
32  return $this->getQueryUtils()->createTable($name, $fields, $options);
33  }
if(!is_array($argv)) $options
+ Here is the call graph for this function:

◆ listSequences()

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

Implements ilDBManager.

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

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

324  {
325  $db = $this->db_instance;
326 
327  $query = "SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN";
328  $query .= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
329  $table_names = $db->queryCol($query);
330 
331  $result = array();
332  foreach ($table_names as $table_name) {
333  $result[] = $this->fixSequenceName($table_name);
334  }
335  if ($db->options['portability']) {
336  $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
337  }
338  sort($result); // FSX patch
339 
340  return $result;
341  }
$result
fixSequenceName($sqn, $check=false)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ listTableConstraints()

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

Implements ilDBManager.

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

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

Referenced by dropDatabase().

235  {
236  $db = $this->db_instance;
237 
238  $table = $db->quote($table, 'text');
239  $subquery = "SELECT indexrelid FROM pg_index, pg_class";
240  $subquery .= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND (indisunique = 't' OR indisprimary = 't')";
241  $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
242  $constraints = $db->queryCol($query);
243 
244  $result = array();
245  foreach ($constraints as $constraint) {
246  $constraint = $this->fixIndexName($constraint);
247  if (!empty($constraint)) {
248  $result[$constraint] = true;
249  }
250  }
251 
252  if ($db->options['portability']
253  && $db->options['field_case'] == CASE_LOWER
254  ) {
255  $result = array_change_key_case($result, $db->options['field_case']);
256  }
257 
258  return array_keys($result);
259  }
$result
Create styles array
The data for the language used.
+ 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 190 of file class.ilDBPdoManagerPostgres.php.

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

190  {
191  $db = $this->db_instance;
192 
193  $table = $db->quoteIdentifier($table, true);
194  $res = $this->pdo->query("select * from $table");
195  for ($i = 0; $i < $res->columnCount(); $i++) {
196  $data[] = $res->getColumnMeta($i)["name"];
197  }
198  return $data;
199  }

◆ listTableIndexes()

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

Implements ilDBManager.

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

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

Referenced by dropDatabase().

206  {
207  $db = $this->db_instance;
208 
209  $table = $db->quote($table, 'text');
210  $subquery = "SELECT indexrelid FROM pg_index, pg_class";
211  $subquery .= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND indisunique != 't' AND indisprimary != 't'";
212  $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
213  $indexes = $db->queryCol($query, 'text');
214 
215  $result = array();
216  foreach ($indexes as $index) {
217  $index = $this->fixIndexName($index);
218  if (!empty($index)) {
219  $result[$index] = true;
220  }
221  }
222 
223  if ($db->options['portability']) {
224  $result = array_change_key_case($result, $db->options['field_case']);
225  }
226 
227  return array_keys($result);
228  }
$result
Create styles array
The data for the language used.
+ 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 51 of file class.ilDBPdoManagerPostgres.php.

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

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

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