public function getPrimaryKeyDDL(Table $table)
 {
     if ($table->hasPrimaryKey()) {
         $pattern = 'CONSTRAINT %s PRIMARY KEY (%s)';
         return sprintf($pattern, $this->quoteIdentifier($this->getPrimaryKeyName($table)), $this->getColumnListDDL($table->getPrimaryKey()));
     }
 }
 protected function validateTableColumns(Table $table)
 {
     if (!$table->hasPrimaryKey() && !$table->isSkipSql()) {
         $this->errors[] = sprintf('Table "%s" does not have a primary key defined. Propel requires all tables to have a primary key.', $table->getName());
     }
     $phpNames = array();
     foreach ($table->getColumns() as $column) {
         if (in_array($column->getPhpName(), $phpNames)) {
             $this->errors[] = sprintf('Column "%s" declares a phpName already used in table "%s"', $column->getName(), $table->getName());
         }
         $phpNames[] = $column->getPhpName();
     }
 }
Example #3
0
 public function getAddTableDDL(Table $table)
 {
     $tableDescription = $table->hasDescription() ? $this->getCommentLineDDL($table->getDescription()) : '';
     $lines = array();
     foreach ($table->getColumns() as $column) {
         $lines[] = $this->getColumnDDL($column);
     }
     if ($table->hasPrimaryKey() && count($table->getPrimaryKey()) > 1) {
         $lines[] = $this->getPrimaryKeyDDL($table);
     }
     foreach ($table->getUnices() as $unique) {
         $lines[] = $this->getUniqueDDL($unique);
     }
     $sep = ",\n\t";
     $pattern = "\n%sCREATE TABLE %s\n(\n\t%s\n);\n";
     return sprintf($pattern, $tableDescription, $this->quoteIdentifier($table->getName()), implode($sep, $lines));
 }
 public function getAddTableDDL(Table $table)
 {
     $lines = array();
     foreach ($table->getColumns() as $column) {
         $lines[] = $this->getColumnDDL($column);
     }
     if ($table->hasPrimaryKey()) {
         $lines[] = $this->getPrimaryKeyDDL($table);
     }
     foreach ($table->getUnices() as $unique) {
         $lines[] = $this->getUniqueDDL($unique);
     }
     foreach ($table->getIndices() as $index) {
         $lines[] = $this->getIndexDDL($index);
     }
     foreach ($table->getForeignKeys() as $foreignKey) {
         if ($foreignKey->isSkipSql()) {
             continue;
         }
         $lines[] = str_replace("\n\t", "\n\t\t", $this->getForeignKeyDDL($foreignKey));
     }
     $vendorSpecific = $table->getVendorInfoForType('mysql');
     if ($vendorSpecific->hasParameter('Type')) {
         $mysqlTableType = $vendorSpecific->getParameter('Type');
     } elseif ($vendorSpecific->hasParameter('Engine')) {
         $mysqlTableType = $vendorSpecific->getParameter('Engine');
     } else {
         $mysqlTableType = $this->getDefaultTableEngine();
     }
     $tableOptions = $this->getTableOptions($table);
     if ($table->getDescription()) {
         $tableOptions[] = 'COMMENT=' . $this->quote($table->getDescription());
     }
     $tableOptions = $tableOptions ? ' ' . implode(' ', $tableOptions) : '';
     $sep = ",\n\t";
     $pattern = "\nCREATE TABLE %s\n(\n\t%s\n) %s=%s%s;\n";
     return sprintf($pattern, $this->quoteIdentifier($table->getName()), implode($sep, $lines), $this->getTableEngineKeyword(), $mysqlTableType, $tableOptions);
 }
Example #5
0
 /**
  * Returns the SQL for the primary key of a Table object
  * @return     string
  */
 public function getPrimaryKeyDDL(Table $table)
 {
     if ($table->hasPrimaryKey()) {
         return 'PRIMARY KEY (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
     }
 }