/**
  * Builds the DDL SQL to remove a column
  *
  * @return     string
  */
 public function getRemoveColumnDDL(Column $column)
 {
     $pattern = "\nALTER TABLE %s DROP %s;\n";
     return sprintf($pattern, $this->quoteIdentifier($column->getTable()->getName()), $this->quoteIdentifier($column->getName()));
 }
示例#2
0
 /**
  * Get the full quoted identifier including database/table name
  * @param Column $column
  * @return string
  */
 public function getColumnFullIdentifier(Column $column)
 {
     return "{$this->getTableFullIdentifier($column->getTable())}.{$this->getColumnBaseIdentifier($column)}";
 }
 public function getColumnDDL(Column $col)
 {
     $domain = $col->getDomain();
     $ddl = array($this->quoteIdentifier($col->getName()));
     $sqlType = $domain->getSqlType();
     $table = $col->getTable();
     if ($col->isAutoIncrement() && $table && $table->getIdMethodParameters() == null) {
         $sqlType = $col->getType() === PropelTypes::BIGINT ? 'bigserial' : 'serial';
     }
     if ($this->hasSize($sqlType) && $col->isDefaultSqlType($this)) {
         $ddl[] = $sqlType . $domain->printSize();
     } else {
         $ddl[] = $sqlType;
     }
     if ($default = $this->getColumnDefaultValueDDL($col)) {
         $ddl[] = $default;
     }
     if ($notNull = $this->getNullString($col->isNotNull())) {
         $ddl[] = $notNull;
     }
     if ($autoIncrement = $col->getAutoIncrementString()) {
         $ddl[] = $autoIncrement;
     }
     return implode(' ', $ddl);
 }
 /**
  * Gets the message for a specified rule.
  *
  * @param      Column $column
  * @param      string $type
  * @param      mixed $value
  */
 protected function getRuleMessage(Column $column, $type, $value)
 {
     // create message
     $colName = $column->getName();
     $tableName = $column->getTable()->getName();
     $msg = self::$validatorMessages[strtolower($type)];
     $tmp = compact($msg['var']);
     array_unshift($tmp, $msg['msg']);
     $msg = call_user_func_array('sprintf', $tmp);
     return $msg;
 }
示例#5
0
 public function getAddColumnDDLBits(Column $column)
 {
     $pattern = "ADD %s %s";
     $tableColumns = $column->getTable()->getColumns();
     //default to add to top if the before-column cannot be found
     $insertPositionDDL = "FIRST";
     foreach ($tableColumns as $i => $tableColumn) {
         //we found the column, use the column before it, if its not the first
         if ($tableColumn->getName() == $column->getName()) {
             //we have a column that is not the first column
             if ($i > 0) {
                 $insertPositionDDL = "AFTER " . $this->quoteIdentifier($tableColumns[$i - 1]->getName());
             }
             break;
         }
     }
     return sprintf($pattern, $this->getColumnDDL($column), $insertPositionDDL);
 }
示例#6
0
 /**
  * Builds the DDL SQL to remove a column
  *
  * @return string
  */
 public function getAddColumnDDL(Column $column)
 {
     $pattern = "\r\nALTER TABLE %s ADD %s;\r\n";
     return sprintf($pattern, $this->quoteIdentifier($column->getTable()->getName()), $this->getColumnDDL($column));
 }