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...
 
 listTables ($database=null)
 
 listSequences ($database=null)
 
 createConstraint ($table, $name, $definition)
 
 listTableFields ($table)
 
 listTableConstraints ($table)
 
 createSequence ($seq_name, $start=1, $options=array())
 
 listTableIndexes ($table)
 
 alterTable ($name, $changes, $check)
 
 createIndex ($table, $name, $definition)
 
 dropIndex ($table, $name)
 
 dropSequence ($seq_name)
 
 dropConstraint ($table, $name, $primary=false)
 
 dropTable ($name)
 
 getIndexName ($idx)
 
 getSequenceName ($sqn)
 

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.

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

References ilDBPdoManager\$db_instance.

◆ createSequence()

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

Reimplemented from ilDBPdoManager.

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

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 }

References ilDBPdoManager\$db_instance, and $start.

◆ createTable()

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

Reimplemented from ilDBPdoManager.

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

42 {
43 return $this->pdo->exec($this->getQueryUtils()->createTable($name, $fields, $options));
44 }
createTable($name, $fields, $options=array())
if(!is_array($argv)) $options

References $options, createTable(), and getQueryUtils().

Referenced by createTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dropConstraint()

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

Reimplemented from ilDBPdoManager.

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

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 }

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

+ 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.

86 {
88
89 $name = $db->quoteIdentifier($name, true);
90
91 return $db->manipulate("DROP DATABASE $name");
92 }

References ilDBPdoManager\$db_instance.

◆ dropIndex()

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

Reimplemented from ilDBPdoManager.

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

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 }

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

+ Here is the call graph for this function:

◆ dropSequence()

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

Reimplemented from ilDBPdoManager.

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

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 }

References ilDBPdoManager\$db_instance.

◆ fixIndexName()

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

Reimplemented from ilDBPdoManager.

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

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 }

References ilDBPdoFieldDefinition\INDEX_FORMAT.

Referenced by listTableConstraints(), and listTableIndexes().

+ Here is the caller graph for this function:

◆ getQueryUtils()

ilDBPdoManagerPostgres::getQueryUtils ( )
Returns
\ilPostgresQueryUtils

Reimplemented from ilDBPdoManager.

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

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.

References ilDBPdoManager\$query_utils.

Referenced by createTable(), and getTableCreationQuery().

+ Here is the caller graph for this function:

◆ getTableCreationQuery()

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

ilDatabaseException

Reimplemented from ilDBPdoManager.

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

31 {
32 return $this->getQueryUtils()->createTable($name, $fields, $options);
33 }

References $options, and getQueryUtils().

+ Here is the call graph for this function:

◆ listSequences()

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

Reimplemented from ilDBPdoManager.

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

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)

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

+ Here is the call graph for this function:

◆ listTableConstraints()

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

Reimplemented from ilDBPdoManager.

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

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 }

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

+ Here is the call graph for this function:

◆ listTableFields()

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

Reimplemented from ilDBPdoManager.

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

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 }

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

◆ listTableIndexes()

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

Reimplemented from ilDBPdoManager.

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

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 }

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

+ Here is the call graph for this function:

◆ listTables()

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

Reimplemented from ilDBPdoManager.

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

51 {
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 }

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


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