@@ 4716-4741 (lines=26) @@ | ||
4713 | * |
|
4714 | * @return int|\PHPPgAdmin\Database\A 0 success |
|
4715 | */ |
|
4716 | public function addPrimaryKey($table, $fields, $name = '', $tablespace = '') |
|
4717 | { |
|
4718 | if (!is_array($fields) || count($fields) == 0) { |
|
4719 | return -1; |
|
4720 | } |
|
4721 | ||
4722 | $f_schema = $this->_schema; |
|
4723 | $this->fieldClean($f_schema); |
|
4724 | $this->fieldClean($table); |
|
4725 | $this->fieldArrayClean($fields); |
|
4726 | $this->fieldClean($name); |
|
4727 | $this->fieldClean($tablespace); |
|
4728 | ||
4729 | $sql = "ALTER TABLE \"{$f_schema}\".\"{$table}\" ADD "; |
|
4730 | if ($name != '') { |
|
4731 | $sql .= "CONSTRAINT \"{$name}\" "; |
|
4732 | } |
|
4733 | ||
4734 | $sql .= 'PRIMARY KEY ("'.implode('","', $fields).'")'; |
|
4735 | ||
4736 | if ($tablespace != '' && $this->hasTablespaces()) { |
|
4737 | $sql .= " USING INDEX TABLESPACE \"{$tablespace}\""; |
|
4738 | } |
|
4739 | ||
4740 | return $this->execute($sql); |
|
4741 | } |
|
4742 | ||
4743 | /** |
|
4744 | * Adds a unique constraint to a table. |
|
@@ 4753-4778 (lines=26) @@ | ||
4750 | * |
|
4751 | * @return int|\PHPPgAdmin\Database\A 0 success |
|
4752 | */ |
|
4753 | public function addUniqueKey($table, $fields, $name = '', $tablespace = '') |
|
4754 | { |
|
4755 | if (!is_array($fields) || count($fields) == 0) { |
|
4756 | return -1; |
|
4757 | } |
|
4758 | ||
4759 | $f_schema = $this->_schema; |
|
4760 | $this->fieldClean($f_schema); |
|
4761 | $this->fieldClean($table); |
|
4762 | $this->fieldArrayClean($fields); |
|
4763 | $this->fieldClean($name); |
|
4764 | $this->fieldClean($tablespace); |
|
4765 | ||
4766 | $sql = "ALTER TABLE \"{$f_schema}\".\"{$table}\" ADD "; |
|
4767 | if ($name != '') { |
|
4768 | $sql .= "CONSTRAINT \"{$name}\" "; |
|
4769 | } |
|
4770 | ||
4771 | $sql .= 'UNIQUE ("'.implode('","', $fields).'")'; |
|
4772 | ||
4773 | if ($tablespace != '' && $this->hasTablespaces()) { |
|
4774 | $sql .= " USING INDEX TABLESPACE \"{$tablespace}\""; |
|
4775 | } |
|
4776 | ||
4777 | return $this->execute($sql); |
|
4778 | } |
|
4779 | ||
4780 | // Function functions |
|
4781 |