コード例 #1
0
 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()));
     }
 }
コード例 #2
0
ファイル: SqlitePlatform.php プロジェクト: robin850/Propel2
 /**
  * Returns the SQL for the primary key of a Table object.
  *
  * @return string
  */
 public function getPrimaryKeyDDL(Table $table)
 {
     if ($table->hasPrimaryKey() && 1 < count($table->getPrimaryKey())) {
         if ($table->hasAutoIncrementPrimaryKey()) {
             return 'UNIQUE (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
         }
         return 'PRIMARY KEY (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
     }
 }
コード例 #3
0
ファイル: SchemaValidator.php プロジェクト: disider/Propel2
 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 = [];
     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();
     }
 }
コード例 #4
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    ";
     $pattern = "\n%sCREATE TABLE %s\n(\n    %s\n);\n";
     return sprintf($pattern, $tableDescription, $this->quoteIdentifier($table->getName()), implode($sep, $lines));
 }
コード例 #5
0
 /**
  * Builds the DDL SQL to drop the primary key of a table.
  *
  * @param  Table  $table
  * @return string
  */
 public function getDropPrimaryKeyDDL(Table $table)
 {
     if (!$table->hasPrimaryKey()) {
         return '';
     }
     $pattern = "\nALTER TABLE %s DROP PRIMARY KEY;\n";
     return sprintf($pattern, $this->quoteIdentifier($table->getName()));
 }
コード例 #6
0
ファイル: MysqlPlatform.php プロジェクト: norfil/Propel2
 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    ", "\n        ", $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    ";
     $pattern = "\nCREATE TABLE %s\n(\n    %s\n) %s=%s%s;\n";
     return sprintf($pattern, $this->quoteIdentifier($table->getName()), implode($sep, $lines), $this->getTableEngineKeyword(), $mysqlTableType, $tableOptions);
 }
コード例 #7
0
 public function testGetAutoIncrementPrimaryKey()
 {
     $column1 = $this->getColumnMock('id', array('primary' => true, 'auto_increment' => true));
     $column2 = $this->getColumnMock('title');
     $column3 = $this->getColumnMock('isbn');
     $table = new Table();
     $table->setIdMethod('native');
     $table->addColumn($column1);
     $table->addColumn($column2);
     $table->addColumn($column3);
     $this->assertCount(1, $table->getPrimaryKey());
     $this->assertTrue($table->hasPrimaryKey());
     $this->assertTrue($table->hasAutoIncrementPrimaryKey());
     $this->assertSame($column1, $table->getAutoIncrementPrimaryKey());
 }
コード例 #8
0
 /**
  * Returns the DDL SQL to add the primary key of a table.
  *
  * @param  Table  $table From Table
  * @return string
  */
 public function getAddPrimaryKeyDDL(Table $table)
 {
     if (!$table->hasPrimaryKey()) {
         return '';
     }
     $pattern = "\nALTER TABLE %s ADD %s;\n";
     return sprintf($pattern, $this->quoteIdentifier($table->getName()), $this->getPrimaryKeyDDL($table));
 }
コード例 #9
0
ファイル: DefaultPlatform.php プロジェクト: rouffj/Propel2
 /**
  * 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()) . ')';
     }
 }