本文整理汇总了PHP中Propel\Generator\Model\Table::hasPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::hasPrimaryKey方法的具体用法?PHP Table::hasPrimaryKey怎么用?PHP Table::hasPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Generator\Model\Table
的用法示例。
在下文中一共展示了Table::hasPrimaryKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPrimaryKeyDDL
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: getPrimaryKeyDDL
/**
* 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: validateTableColumns
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: getAddTableDDL
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: getDropPrimaryKeyDDL
/**
* 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: getAddTableDDL
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: testGetAutoIncrementPrimaryKey
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: getAddPrimaryKeyDDL
/**
* 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: getPrimaryKeyDDL
/**
* 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()) . ')';
}
}