|
@@ 4611-4636 (lines=26) @@
|
| 4608 |
|
* @param string $tablespace (optional) The tablespace for the schema, '' indicates default. |
| 4609 |
|
* @return int|\PHPPgAdmin\Database\A 0 success |
| 4610 |
|
*/ |
| 4611 |
|
public function addPrimaryKey($table, $fields, $name = '', $tablespace = '') |
| 4612 |
|
{ |
| 4613 |
|
if (!is_array($fields) || sizeof($fields) == 0) { |
| 4614 |
|
return -1; |
| 4615 |
|
} |
| 4616 |
|
|
| 4617 |
|
$f_schema = $this->_schema; |
| 4618 |
|
$this->fieldClean($f_schema); |
| 4619 |
|
$this->fieldClean($table); |
| 4620 |
|
$this->fieldArrayClean($fields); |
| 4621 |
|
$this->fieldClean($name); |
| 4622 |
|
$this->fieldClean($tablespace); |
| 4623 |
|
|
| 4624 |
|
$sql = "ALTER TABLE \"{$f_schema}\".\"{$table}\" ADD "; |
| 4625 |
|
if ($name != '') { |
| 4626 |
|
$sql .= "CONSTRAINT \"{$name}\" "; |
| 4627 |
|
} |
| 4628 |
|
|
| 4629 |
|
$sql .= 'PRIMARY KEY ("' . join('","', $fields) . '")'; |
| 4630 |
|
|
| 4631 |
|
if ($tablespace != '' && $this->hasTablespaces()) { |
| 4632 |
|
$sql .= " USING INDEX TABLESPACE \"{$tablespace}\""; |
| 4633 |
|
} |
| 4634 |
|
|
| 4635 |
|
return $this->execute($sql); |
| 4636 |
|
} |
| 4637 |
|
|
| 4638 |
|
/** |
| 4639 |
|
* Adds a unique constraint to a table |
|
@@ 4647-4672 (lines=26) @@
|
| 4644 |
|
* @param string $tablespace (optional) The tablespace for the schema, '' indicates default. |
| 4645 |
|
* @return int|\PHPPgAdmin\Database\A 0 success |
| 4646 |
|
*/ |
| 4647 |
|
public function addUniqueKey($table, $fields, $name = '', $tablespace = '') |
| 4648 |
|
{ |
| 4649 |
|
if (!is_array($fields) || sizeof($fields) == 0) { |
| 4650 |
|
return -1; |
| 4651 |
|
} |
| 4652 |
|
|
| 4653 |
|
$f_schema = $this->_schema; |
| 4654 |
|
$this->fieldClean($f_schema); |
| 4655 |
|
$this->fieldClean($table); |
| 4656 |
|
$this->fieldArrayClean($fields); |
| 4657 |
|
$this->fieldClean($name); |
| 4658 |
|
$this->fieldClean($tablespace); |
| 4659 |
|
|
| 4660 |
|
$sql = "ALTER TABLE \"{$f_schema}\".\"{$table}\" ADD "; |
| 4661 |
|
if ($name != '') { |
| 4662 |
|
$sql .= "CONSTRAINT \"{$name}\" "; |
| 4663 |
|
} |
| 4664 |
|
|
| 4665 |
|
$sql .= 'UNIQUE ("' . join('","', $fields) . '")'; |
| 4666 |
|
|
| 4667 |
|
if ($tablespace != '' && $this->hasTablespaces()) { |
| 4668 |
|
$sql .= " USING INDEX TABLESPACE \"{$tablespace}\""; |
| 4669 |
|
} |
| 4670 |
|
|
| 4671 |
|
return $this->execute($sql); |
| 4672 |
|
} |
| 4673 |
|
|
| 4674 |
|
// Function functions |
| 4675 |
|
|