3 require_once(
'./Services/Database/classes/PDO/Manager/class.ilDBPdoManagerPostgres.php');
4 require_once(
'class.ilDBPdo.php');
5 require_once(
'./Services/Database/classes/PDO/FieldDefinition/class.ilDBPdoPostgresFieldDefinition.php');
6 require_once(
'./Services/Database/classes/PDO/Reverse/class.ilDBPdoReversePostgres.php');
19 protected $port = self::POSTGRE_STD_PORT;
32 $this->
setPort(self::POSTGRE_STD_PORT);
34 $this->dsn =
'pgsql:host=' . $this->
getHost() .
';port=' . $this->
getPort() .
';dbname=' . $this->
getDbname() .
';user=' 44 public function connect($return_false_for_error =
false) {
50 $this->error_code = $e->getCode();
51 if ($return_false_for_error) {
57 return ($this->pdo->errorCode() == PDO::ERR_NONE);
63 PDO::ATTR_EMULATE_PREPARES =>
true,
105 $a_constraint = str_replace($a_table .
'_',
'', $a_constraint);
107 return $a_table .
'_' . $a_constraint;
116 return parent::getIndexName($index_name_base);
127 public function replace($a_table, $a_pk_columns, $a_other_columns) {
128 $a_columns = array_merge($a_pk_columns, $a_other_columns);
130 $field_values =
array();
131 $placeholders =
array();
136 $val_field =
array();
139 foreach ($a_columns as $k => $col) {
140 if ($col[0] ==
'clob' or $col[0] ==
'blob') {
141 $val_field[] = $this->
quote($col[1],
'text') .
" " . $k;
143 $val_field[] = $this->
quote($col[1], $col[0]) .
" " . $k;
146 $placeholders[] =
"%s";
147 $placeholders2[] =
":$k";
150 $field_values[$k] = $col[1];
151 if ($col[0] ==
"blob" || $col[0] ==
"clob") {
161 foreach ($a_pk_columns as $k => $col) {
162 $abpk[] =
"a." . $k .
" = b." . $k;
163 $delwhere[] = $k .
" = " . $this->
quote($col[1], $col[0]);
165 foreach ($a_other_columns as $k => $col) {
166 $aboc[] =
"a." . $k .
" = b." . $k;
170 $this->
manipulate(
"DELETE FROM " . $a_table .
" WHERE " . implode($delwhere,
" AND "));
171 $this->
insert($a_table, $a_columns);
188 foreach ($a_tables as $table) {
189 if (!isset($table[
'sequence']) && $table[
'sequence']) {
190 $lock =
'LOCK TABLE ' . $table[
'name'];
192 switch ($table[
'type']) {
194 $lock .=
' IN SHARE MODE ';
198 $lock .=
' IN EXCLUSIVE MODE ';
208 foreach ($locks as $lock) {
244 $sequence_name = $table_name .
'_seq';
245 $query =
"SELECT NEXTVAL('$sequence_name')";
249 return $data->nextval;
258 public function dropTable($table_name, $error_if_not_existing =
false) {
260 $this->pdo->exec(
"DROP TABLE $table_name");
261 }
catch (PDOException $PDOException) {
262 if ($error_if_not_existing) {
279 return '"'.$identifier.
'"';
290 if (is_array($tables)) {
291 if (in_array($table_name, $tables)) {
305 if ($this->limit !== null && $this->offset !== null) {
308 $this->offset = null;
324 return in_array($column_name, $this->manager->listTableFields($table_name));
346 $this->manager->alterTable($a_name,
array(
"name" => $a_new_name ),
false);
361 if (in_array($table_name, $this->manager->listSequences())) {
365 parent::createSequence($table_name,
$start);
380 public function createTable($table_name, $fields, $drop_table =
false, $ignore_erros =
false) {
385 return parent::createTable($table_name, $fields, $drop_table, $ignore_erros);
398 require_once(
'./Services/Database/classes/class.ilDBAnalyzer.php');
400 if ($ilDBAnalyzer->getPrimaryKeyInformation($table_name)) {
404 return parent::addPrimaryKey($table_name, $primary_keys);
411 public function addIndex($table_name, $fields, $index_name =
'', $fulltext =
false) {
412 $indices = $this->manager->listTableIndexes($table_name);
413 if (in_array($this->
constraintName($table_name, $index_name), $indices)) {
417 return parent::addIndex($table_name, $fields, $index_name, $fulltext);
426 return parent::addUniqueConstraint($table, $fields, $name);
437 return $this->manager->dropConstraint($table_name,
"pk",
true);
createTable($table_name, $fields, $drop_table=false, $ignore_erros=false)
dropTable($table_name, $error_if_not_existing=false)
renameTable($a_name, $a_new_name)
Class ilDBPdoPostgresFieldDefinition.
quote($value, $type=null)
getPrimaryKeyIdentifier()
Primary key identifier.
setStorageEngine($storage_engine)
Class ilDatabaseException.
replace($a_table, $a_pk_columns, $a_other_columns)
constraintName($a_table, $a_constraint)
quoteIdentifier($identifier, $check_option=false)
tableColumnExists($table_name, $column_name)
dropPrimaryKey($table_name)
addPrimaryKey($table_name, $primary_keys)
addIndex($table_name, $fields, $index_name='', $fulltext=false)
Create styles array
The data for the language used.
createSequence($table_name, $start=1)
getIndexName($index_name_base)
getAdditionalAttributes()
insert($table_name, $values)
addUniqueConstraint($table, $fields, $name="con")
This class gives all kind of DB information using the MDB2 manager and reverse module.
connect($return_false_for_error=false)