예제 #1
0
 /**
  * Generate the SQL fragments for defining table constraints.
  *
  * @param TableSchema $table The table instance the column is in.
  * @param string $name The name of the column.
  * @return string SQL fragment.
  */
 public function constraintSql(TableSchema $table, $name)
 {
     $data = $table->constraint($name);
     if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY) {
         $columns = array_map([$this->_driver, 'quoteIdentifier'], $data['columns']);
         return sprintf('PRIMARY KEY (%s)', implode(', ', $columns));
     }
     $out = '';
     if ($data['type'] === TableSchema::CONSTRAINT_UNIQUE) {
         $out = 'UNIQUE KEY ';
     }
     if ($data['type'] === TableSchema::CONSTRAINT_FOREIGN) {
         $out = 'CONSTRAINT ';
     }
     $out .= $this->_driver->quoteIdentifier($name);
     return $this->_keySql($out, $data);
 }
예제 #2
0
 /**
  * Generate the SQL fragments for defining table constraints.
  *
  * @param TableSchema $table The table instance the column is in.
  * @param string $name The name of the column.
  * @return string SQL fragment.
  */
 public function constraintSql(TableSchema $table, $name)
 {
     $data = $table->constraint($name);
     $out = 'CONSTRAINT ' . $this->_driver->quoteIdentifier($name);
     if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY) {
         $out = 'PRIMARY KEY';
     }
     if ($data['type'] === TableSchema::CONSTRAINT_UNIQUE) {
         $out .= ' UNIQUE';
     }
     return $this->_keySql($out, $data);
 }
예제 #3
0
 /**
  * Generate the SQL fragments for defining table constraints.
  *
  * @param TableSchema $table The table instance the column is in.
  * @param string $name The name of the column.
  * @return string SQL fragment.
  */
 public function constraintSql(TableSchema $table, $name)
 {
     $data = $table->constraint($name);
     if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY && count($data['columns']) === 1 && $table->column($data['columns'][0])['type'] === 'integer') {
         return '';
     }
     $clause = '';
     if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY) {
         $type = 'PRIMARY KEY';
     }
     if ($data['type'] === TableSchema::CONSTRAINT_UNIQUE) {
         $type = 'UNIQUE';
     }
     if ($data['type'] === TableSchema::CONSTRAINT_FOREIGN) {
         $type = 'FOREIGN KEY';
         $clause = sprintf(' REFERENCES %s (%s) ON UPDATE %s ON DELETE %s', $this->_driver->quoteIdentifier($data['references'][0]), $this->_convertConstraintColumns($data['references'][1]), $this->_foreignOnClause($data['update']), $this->_foreignOnClause($data['delete']));
     }
     $columns = array_map([$this->_driver, 'quoteIdentifier'], $data['columns']);
     return sprintf('CONSTRAINT %s %s (%s)%s', $this->_driver->quoteIdentifier($name), $type, implode(', ', $columns), $clause);
 }