本文整理汇总了PHP中Propel\Generator\Model\Column::isPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Column::isPrimaryKey方法的具体用法?PHP Column::isPrimaryKey怎么用?PHP Column::isPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Generator\Model\Column
的用法示例。
在下文中一共展示了Column::isPrimaryKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addColumns
/**
* Adds Columns to the specified table.
*
* @param Table $table The Table model class to add columns to.
*/
protected function addColumns(Table $table)
{
$tableName = $table->getName();
// var_dump("PRAGMA table_info('$tableName') //");
$stmt = $this->dbh->query("PRAGMA table_info('{$tableName}')");
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$name = $row['name'];
$fulltype = $row['type'];
$size = null;
$scale = null;
if (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
$type = $matches[1];
$size = $matches[2];
$scale = $matches[3];
} elseif (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
$type = $matches[1];
$size = $matches[2];
} else {
$type = $fulltype;
}
$notNull = $row['notnull'];
$default = $row['dflt_value'];
$propelType = $this->getMappedPropelType(strtolower($type));
if (!$propelType) {
$propelType = Column::DEFAULT_TYPE;
$this->warn('Column [' . $table->getName() . '.' . $name . '] has a column type (' . $type . ') that Propel does not support.');
}
$column = new Column($name);
$column->setTable($table);
$column->setDomainForType($propelType);
// We may want to provide an option to include this:
// $column->getDomain()->replaceSqlType($type);
$column->getDomain()->replaceSize($size);
$column->getDomain()->replaceScale($scale);
if (null !== $default) {
if ("'" !== substr($default, 0, 1) && strpos($default, '(')) {
$defaultType = ColumnDefaultValue::TYPE_EXPR;
if ('datetime(CURRENT_TIMESTAMP, \'localtime\')' === $default) {
$default = 'CURRENT_TIMESTAMP';
}
} else {
$defaultType = ColumnDefaultValue::TYPE_VALUE;
$default = str_replace("'", '', $default);
}
$column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, $defaultType));
}
$column->setNotNull($notNull);
if (0 < $row['pk'] + 0) {
$column->setPrimaryKey(true);
}
if ($column->isPrimaryKey()) {
// check if autoIncrement
$autoIncrementStmt = $this->dbh->prepare('
SELECT tbl_name
FROM sqlite_master
WHERE
tbl_name = ?
AND
sql LIKE "%AUTOINCREMENT%"
');
$autoIncrementStmt->execute([$table->getName()]);
$autoincrementRow = $autoIncrementStmt->fetch(\PDO::FETCH_ASSOC);
if ($autoincrementRow && $autoincrementRow['tbl_name'] == $table->getName()) {
$column->setAutoIncrement(true);
}
}
$table->addColumn($column);
}
}
示例2: appendColumnNode
/**
* Appends the generated <column> XML node to its parent node.
*
* @param Column $column The Column model instance
* @param \DOMNode $parentNode The parent DOMNode object
*/
private function appendColumnNode(Column $column, \DOMNode $parentNode)
{
$columnNode = $parentNode->appendChild($this->document->createElement('column'));
$columnNode->setAttribute('name', $column->getName());
if ($phpName = $column->getPhpName()) {
$columnNode->setAttribute('phpName', $phpName);
}
$columnNode->setAttribute('type', $column->getType());
$domain = $column->getDomain();
if ($size = $domain->getSize()) {
$columnNode->setAttribute('size', $size);
}
if (null !== ($scale = $domain->getScale())) {
$columnNode->setAttribute('scale', $scale);
}
$platform = $column->getPlatform();
if ($platform && !$column->isDefaultSqlType($platform)) {
$columnNode->setAttribute('sqlType', $domain->getSqlType());
}
if ($description = $column->getDescription()) {
$columnNode->setAttribute('description', $description);
}
if ($column->isPrimaryKey()) {
$columnNode->setAttribute('primaryKey', 'true');
}
if ($column->isAutoIncrement()) {
$columnNode->setAttribute('autoIncrement', 'true');
}
if ($column->isNotNull()) {
$columnNode->setAttribute('required', 'true');
}
$defaultValue = $domain->getDefaultValue();
if ($defaultValue) {
$type = $defaultValue->isExpression() ? 'defaultExpr' : 'defaultValue';
$columnNode->setAttribute($type, $defaultValue->getValue());
}
if ($column->isInheritance()) {
$columnNode->setAttribute('inheritance', $column->getInheritanceType());
foreach ($column->getInheritanceList() as $inheritance) {
$this->appendInheritanceNode($inheritance, $columnNode);
}
}
if ($column->isNodeKey()) {
$columnNode->setAttribute('nodeKey', 'true');
if ($nodeKeySeparator = $column->getNodeKeySep()) {
$columnNode->setAttribute('nodeKeySep', $nodeKeySeparator);
}
}
foreach ($column->getVendorInformation() as $vendorInformation) {
$this->appendVendorInformationNode($vendorInformation, $columnNode);
}
}
示例3: addAddedPkColumn
/**
* Add an added Pk column
*
* @param string $columnName
* @param Column $addedPkColumn
*/
public function addAddedPkColumn($columnName, Column $addedPkColumn)
{
if (!$addedPkColumn->isPrimaryKey()) {
throw new DiffException(sprintf('Column %s is not a valid primary key column.', $columnName));
}
$this->addedPkColumns[$columnName] = $addedPkColumn;
}
示例4: testSetupObjectWithDomain
public function testSetupObjectWithDomain()
{
$database = $this->getDatabaseMock('bookstore');
$database->expects($this->once())->method('getDomain')->with($this->equalTo('BOOLEAN'))->will($this->returnValue($this->getDomainMock('INTEGER')));
$table = $this->getTableMock('books', array('database' => $database));
$column = new Column();
$column->setTable($table);
$column->setDomain($this->getDomainMock('BOOLEAN'));
$column->loadMapping(array('domain' => 'BOOLEAN', 'name' => 'is_published', 'phpName' => 'IsPublished', 'phpType' => 'boolean', 'tableMapName' => 'IS_PUBLISHED', 'prefix' => 'col_', 'accessorVisibility' => 'public', 'mutatorVisibility' => 'public', 'primaryString' => 'false', 'primaryKey' => 'false', 'nodeKey' => 'false', 'nestedSetLeftKey' => 'false', 'nestedSetRightKey' => 'false', 'treeScopeKey' => 'false', 'required' => 'false', 'autoIncrement' => 'false', 'lazyLoad' => 'true', 'sqlType' => 'TINYINT', 'size' => 1, 'defaultValue' => 'true', 'valueSet' => 'FOO, BAR, BAZ'));
$this->assertSame('is_published', $column->getName());
$this->assertSame('IsPublished', $column->getPhpName());
$this->assertSame('boolean', $column->getPhpType());
$this->assertSame('IS_PUBLISHED', $column->getTableMapName());
$this->assertSame('public', $column->getAccessorVisibility());
$this->assertSame('public', $column->getMutatorVisibility());
$this->assertFalse($column->isPrimaryString());
$this->assertFalse($column->isPrimaryKey());
$this->assertFalse($column->isNodeKey());
$this->assertFalse($column->isNestedSetLeftKey());
$this->assertFalse($column->isNestedSetRightKey());
$this->assertFalse($column->isTreeScopeKey());
$this->assertTrue($column->isLazyLoad());
$this->assertCount(3, $column->getValueSet());
}