本文整理匯總了PHP中Doctrine\DBAL\DBALException::noColumnsSpecifiedForTable方法的典型用法代碼示例。如果您正苦於以下問題:PHP DBALException::noColumnsSpecifiedForTable方法的具體用法?PHP DBALException::noColumnsSpecifiedForTable怎麽用?PHP DBALException::noColumnsSpecifiedForTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\DBAL\DBALException
的用法示例。
在下文中一共展示了DBALException::noColumnsSpecifiedForTable方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getCreateTableSQL
/**
* Gets the SQL statement(s) to create a table with the specified name, columns and constraints
* on this platform.
*
* @param string $table The name of the table.
* @param int $createFlags
* @return array The sequence of SQL statements.
*/
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
{
if (!is_int($createFlags)) {
throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.");
}
if (count($table->getColumns()) == 0) {
throw DBALException::noColumnsSpecifiedForTable($table->getName());
}
$tableName = $table->getName();
$options = $table->getOptions();
$options['uniqueConstraints'] = array();
$options['indexes'] = array();
$options['primary'] = array();
if (($createFlags & self::CREATE_INDEXES) > 0) {
foreach ($table->getIndexes() as $index) {
/* @var $index Index */
if ($index->isPrimary()) {
$options['primary'] = $index->getColumns();
} else {
$options['indexes'][$index->getName()] = $index;
}
}
}
$columns = array();
foreach ($table->getColumns() as $column) {
/* @var \Doctrine\DBAL\Schema\Column $column */
$columnData = array();
$columnData['name'] = $column->getName();
$columnData['type'] = $column->getType();
$columnData['length'] = $column->getLength();
$columnData['notnull'] = $column->getNotNull();
$columnData['unique'] = $column->hasPlatformOption("unique") ? $column->getPlatformOption('unique') : false;
$columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption('version') : false;
if (strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
$columnData['length'] = 255;
}
$columnData['precision'] = $column->getPrecision();
$columnData['scale'] = $column->getScale();
$columnData['default'] = $column->getDefault();
$columnData['columnDefinition'] = $column->getColumnDefinition();
if (in_array($column->getName(), $options['primary'])) {
$columnData['primary'] = true;
if ($table->isIdGeneratorIdentity()) {
$columnData['autoincrement'] = true;
}
}
$columns[$columnData['name']] = $columnData;
}
if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) {
$options['foreignKeys'] = array();
foreach ($table->getForeignKeys() as $fkConstraint) {
$options['foreignKeys'][] = $fkConstraint;
}
}
return $this->_getCreateTableSQL($tableName, $columns, $options);
}
示例2: getCreateTableSQL
/**
* Gets the SQL statement(s) to create a table with the specified name, columns and constraints
* on this platform.
*
* @param string $table The name of the table.
* @param int $createFlags
* @return array The sequence of SQL statements.
*/
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
{
if (!is_int($createFlags)) {
throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.");
}
if (count($table->getColumns()) == 0) {
throw DBALException::noColumnsSpecifiedForTable($table->getName());
}
$tableName = $table->getQuotedName($this);
$options = $table->getOptions();
$options['uniqueConstraints'] = array();
$options['indexes'] = array();
$options['primary'] = array();
if (($createFlags & self::CREATE_INDEXES) > 0) {
foreach ($table->getIndexes() as $index) {
/* @var $index Index */
if ($index->isPrimary()) {
$options['primary'] = $index->getColumns();
} else {
$options['indexes'][$index->getName()] = $index;
}
}
}
$columnSql = array();
$columns = array();
foreach ($table->getColumns() as $column) {
/* @var \Doctrine\DBAL\Schema\Column $column */
if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) {
$eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs);
$columnSql = array_merge($columnSql, $eventArgs->getSql());
if ($eventArgs->isDefaultPrevented()) {
continue;
}
}
$columnData = array();
$columnData['name'] = $column->getQuotedName($this);
$columnData['type'] = $column->getType();
$columnData['length'] = $column->getLength();
$columnData['notnull'] = $column->getNotNull();
$columnData['fixed'] = $column->getFixed();
$columnData['unique'] = false;
// TODO: what do we do about this?
$columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption('version') : false;
if (strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
$columnData['length'] = 255;
}
$columnData['unsigned'] = $column->getUnsigned();
$columnData['precision'] = $column->getPrecision();
$columnData['scale'] = $column->getScale();
$columnData['default'] = $column->getDefault();
$columnData['columnDefinition'] = $column->getColumnDefinition();
$columnData['autoincrement'] = $column->getAutoincrement();
$columnData['comment'] = $this->getColumnComment($column);
if (in_array($column->getName(), $options['primary'])) {
$columnData['primary'] = true;
}
$columns[$columnData['name']] = $columnData;
}
if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) {
$options['foreignKeys'] = array();
foreach ($table->getForeignKeys() as $fkConstraint) {
$options['foreignKeys'][] = $fkConstraint;
}
}
if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) {
$eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs);
if ($eventArgs->isDefaultPrevented()) {
return array_merge($eventArgs->getSql(), $columnSql);
}
}
$sql = $this->_getCreateTableSQL($tableName, $columns, $options);
if ($this->supportsCommentOnStatement()) {
foreach ($table->getColumns() as $column) {
if ($this->getColumnComment($column)) {
$sql[] = $this->getCommentOnColumnSQL($tableName, $column->getName(), $this->getColumnComment($column));
}
}
}
return array_merge($sql, $columnSql);
}
示例3: getCreateTableSQL
/**
* {@inheritDoc}
* Gets the SQL statement(s) to create a table with the specified name, columns and constraints
* on this platform.
*
* @param Table $table The name of the table.
* @param integer $createFlags
*
* @return array The sequence of SQL statements.
*/
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
{
if (!is_int($createFlags)) {
$msg = "Second argument of CratePlatform::getCreateTableSQL() has to be integer.";
throw new \InvalidArgumentException($msg);
}
if (count($table->getColumns()) === 0) {
throw DBALException::noColumnsSpecifiedForTable($table->getName());
}
$tableName = $table->getQuotedName($this);
$options = $table->getOptions();
$options['uniqueConstraints'] = array();
$options['indexes'] = array();
$options['primary'] = array();
if (($createFlags & self::CREATE_INDEXES) > 0) {
foreach ($table->getIndexes() as $index) {
/* @var $index Index */
if ($index->isPrimary()) {
$platform = $this;
$options['primary'] = array_map(function ($columnName) use($table, $platform) {
return $table->getColumn($columnName)->getQuotedName($platform);
}, $index->getColumns());
$options['primary_index'] = $index;
} else {
$options['indexes'][$index->getName()] = $index;
}
}
}
$columnSql = array();
$columns = array();
foreach ($table->getColumns() as $column) {
if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) {
$eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs);
$columnSql = array_merge($columnSql, $eventArgs->getSql());
if ($eventArgs->isDefaultPrevented()) {
continue;
}
}
$columns[$column->getQuotedName($this)] = $this->prepareColumnData($column, $options['primary']);
}
if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) {
$eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs);
if ($eventArgs->isDefaultPrevented()) {
return array_merge($eventArgs->getSql(), $columnSql);
}
}
$sql = $this->_getCreateTableSQL($tableName, $columns, $options);
if ($this->supportsCommentOnStatement()) {
foreach ($table->getColumns() as $column) {
if ($this->getColumnComment($column)) {
$sql[] = $this->getCommentOnColumnSQL($tableName, $column->getName(), $this->getColumnComment($column));
}
}
}
return array_merge($sql, $columnSql);
}