From 35bf0fa9dd47a43630ebb41e0e597a7c82fa2905 Mon Sep 17 00:00:00 2001 From: Glen Sawyer Date: Wed, 11 Nov 2015 15:42:02 -0700 Subject: [PATCH] Implemented addConstraintSql and dropConstraintSql --- src/Schema/OracleSchema.php | 42 +++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Schema/OracleSchema.php b/src/Schema/OracleSchema.php index 458d342..0f2deae 100644 --- a/src/Schema/OracleSchema.php +++ b/src/Schema/OracleSchema.php @@ -385,12 +385,46 @@ public function truncateTableSql(Table $table) return [sprintf("TRUNCATE TABLE %s", $tableName)]; } - public function addConstraintSql(Table $table) { - throw new Oci8Exception("addConstraintSql has not been implemented"); + public function addConstraintSql(Table $table) + { + $sqlPattern = 'ALTER TABLE %s ADD %s;'; + $sql = []; + + foreach ($table->constraints() as $name) { + $constraint = $table->constraint($name); + if ($constraint['type'] === Table::CONSTRAINT_FOREIGN) { + if ($this->_driver->autoQuoting()) { + $tableName = $this->_driver->quoteIdentifier($table->name()); + } else { + $tableName = $table->name(); + } + $sql[] = sprintf($sqlPattern, $tableName, $this->constraintSql($table, $name)); + } + } + + return $sql; } - public function dropConstraintSql(Table $table) { - throw new Oci8Exception("dropConstraintSql has not been implemented"); + public function dropConstraintSql(Table $table) + { + $sqlPattern = 'ALTER TABLE %s DROP CONSTRAINT %s;'; + $sql = []; + + foreach ($table->constraints() as $name) { + $constraint = $table->constraint($name); + if ($constraint['type'] === Table::CONSTRAINT_FOREIGN) { + if ($this->_driver->autoQuoting()) { + $tableName = $this->_driver->quoteIdentifier($table->name()); + $constraintName = $this->_driver->quoteIdentifier($name); + } else { + $tableName = $table->name(); + $constraintName = $name; + } + $sql[] = sprintf($sqlPattern, $tableName, $constraintName); + } + } + + return $sql; } }