本文整理汇总了PHP中Cake\Database\Schema\Table::addColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::addColumn方法的具体用法?PHP Table::addColumn怎么用?PHP Table::addColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Database\Schema\Table
的用法示例。
在下文中一共展示了Table::addColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertColumnDescription
public function convertColumnDescription(Table $table, $row)
{
switch ($row['DATA_TYPE']) {
case 'DATE':
$field = ['type' => 'datetime', 'length' => null];
break;
case 'TIMESTAMP(6)':
$field = ['type' => 'string', 'length' => $row['DATA_LENGTH']];
break;
case 'NUMBER':
if ($row['DATA_PRECISION'] == 1) {
$field = ['type' => 'boolean', 'length' => null];
} else {
if ($row['DATA_SCALE'] > 0) {
$field = ['type' => 'decimal', 'length' => $row['DATA_PRECISION'], 'precision' => $row['DATA_SCALE']];
} else {
$field = ['type' => 'integer', 'length' => $row['DATA_PRECISION']];
}
}
break;
case 'VARCHAR2':
$field = ['type' => 'string', 'length' => $row['DATA_LENGTH']];
break;
default:
}
$field += ['null' => $row['NULLABLE'] === 'Y' ? true : false, 'default' => $row['DATA_DEFAULT']];
$table->addColumn(strtolower($row['COLUMN_NAME']), $field);
}
示例2: _schemaFromFields
/**
* Build the fixtures table schema from the fields property.
*
* @return void
*/
protected function _schemaFromFields()
{
$this->_schema = new Table($this->table);
foreach ($this->fields as $field => $data) {
if ($field === '_constraints' || $field === '_indexes' || $field === '_options') {
continue;
}
// Trigger errors on deprecated usage.
if (is_array($data) && isset($data['key'])) {
$msg = 'Usage of the `key` options in columns is not supported. Try using the upgrade shell to migrate your fixtures.';
$msg .= ' You can download the upgrade shell from https://github.com/cakephp/upgrade.';
trigger_error($msg, E_USER_NOTICE);
}
$this->_schema->addColumn($field, $data);
}
if (!empty($this->fields['_constraints'])) {
foreach ($this->fields['_constraints'] as $name => $data) {
$this->_schema->addConstraint($name, $data);
}
}
if (!empty($this->fields['_indexes'])) {
// Trigger errors on deprecated usage.
if (empty($data['type'])) {
$msg = 'Indexes must define a type. Try using the upgrade shell to migrate your fixtures.';
$msg .= ' You can download the upgrade shell from https://github.com/cakephp/upgrade.';
trigger_error($msg, E_USER_NOTICE);
}
foreach ($this->fields['_indexes'] as $name => $data) {
$this->_schema->addIndex($name, $data);
}
}
if (!empty($this->fields['_options'])) {
$this->_schema->options($this->fields['_options']);
}
}
示例3: _schemaFromFields
/**
* Build the fixtures table schema from the fields property.
*
* @return void
*/
protected function _schemaFromFields()
{
$connection = ConnectionManager::get($this->connection());
$this->_schema = new Table($this->table);
foreach ($this->fields as $field => $data) {
if ($field === '_constraints' || $field === '_indexes' || $field === '_options') {
continue;
}
$this->_schema->addColumn($field, $data);
}
if (!empty($this->fields['_constraints'])) {
foreach ($this->fields['_constraints'] as $name => $data) {
if (!$connection->supportsDynamicConstraints() || $data['type'] !== Table::CONSTRAINT_FOREIGN) {
$this->_schema->addConstraint($name, $data);
} else {
$this->_constraints[$name] = $data;
}
}
}
if (!empty($this->fields['_indexes'])) {
foreach ($this->fields['_indexes'] as $name => $data) {
$this->_schema->addIndex($name, $data);
}
}
if (!empty($this->fields['_options'])) {
$this->_schema->options($this->fields['_options']);
}
}
示例4: _schemaFromFields
/**
* Build the fixtures table schema from the fields property.
*
* @return void
*/
protected function _schemaFromFields()
{
$this->_schema = new Table($this->table);
foreach ($this->fields as $field => $data) {
if ($field === '_constraints' || $field === '_indexes' || $field === '_options') {
continue;
}
$this->_schema->addColumn($field, $data);
}
if (!empty($this->fields['_constraints'])) {
foreach ($this->fields['_constraints'] as $name => $data) {
$this->_schema->addConstraint($name, $data);
}
}
if (!empty($this->fields['_indexes'])) {
foreach ($this->fields['_indexes'] as $name => $data) {
$this->_schema->addIndex($name, $data);
}
}
if (!empty($this->fields['_options'])) {
$this->_schema->options($this->fields['_options']);
}
}
示例5: convertColumnDescription
/**
* {@inheritDoc}
*/
public function convertColumnDescription(Table $table, $row)
{
$field = $this->_convertColumn($row['type']);
if ($field['type'] === 'boolean') {
if ($row['default'] === 'true') {
$row['default'] = 1;
}
if ($row['default'] === 'false') {
$row['default'] = 0;
}
}
if (!empty($row['has_serial'])) {
$field['autoIncrement'] = true;
}
$field += ['default' => $this->_defaultValue($row['default']), 'null' => $row['null'] === 'YES' ? true : false, 'comment' => $row['comment']];
$field['length'] = $row['char_length'] ?: $field['length'];
$table->addColumn($row['name'], $field);
}
示例6: testTruncateSql
/**
* Test truncateSql()
*
* @return void
*/
public function testTruncateSql()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMockBuilder('Cake\\Database\\Connection')->disableOriginalConstructor()->getMock();
$connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
$table = new Table('schema_articles');
$table->addColumn('id', 'integer')->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$result = $table->truncateSql($connection);
$this->assertCount(1, $result);
$this->assertEquals('TRUNCATE "schema_articles" RESTART IDENTITY CASCADE', $result[0]);
}
示例7: convertColumnDescription
/**
* {@inheritDoc}
*/
public function convertColumnDescription(Table $table, $row)
{
$field = $this->_convertColumn($row['type']);
$field += ['null' => !$row['notnull'], 'default' => $this->_defaultValue($row['dflt_value'])];
$primary = $table->constraint('primary');
if ($row['pk'] && empty($primary)) {
$field['null'] = false;
$field['autoIncrement'] = true;
}
// SQLite does not support autoincrement on composite keys.
if ($row['pk'] && !empty($primary)) {
$existingColumn = $primary['columns'][0];
$table->addColumn($existingColumn, ['autoIncrement' => null] + $table->column($existingColumn));
}
$table->addColumn($row['name'], $field);
if ($row['pk']) {
$constraint = (array) $table->constraint('primary') + ['type' => Table::CONSTRAINT_PRIMARY, 'columns' => []];
$constraint['columns'] = array_merge($constraint['columns'], [$row['name']]);
$table->addConstraint('primary', $constraint);
}
}
示例8: testColumnSqlPrimaryKey
/**
* Test generating a column that is a primary key.
*
* @return void
*/
public function testColumnSqlPrimaryKey()
{
$driver = $this->_getMockedDriver();
$schema = new MysqlSchema($driver);
$table = new Table('articles');
$table->addColumn('id', ['type' => 'integer', 'null' => false])->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$result = $schema->columnSql($table, 'id');
$this->assertEquals($result, '`id` INTEGER NOT NULL AUTO_INCREMENT');
$table = new Table('articles');
$table->addColumn('id', ['type' => 'biginteger', 'null' => false])->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$result = $schema->columnSql($table, 'id');
$this->assertEquals($result, '`id` BIGINT NOT NULL AUTO_INCREMENT');
}
示例9: convertColumnDescription
/**
* {@inheritDoc}
*/
public function convertColumnDescription(Table $table, $row)
{
$row = array_change_key_case($row);
switch ($row['type']) {
case 'DATE':
$field = ['type' => 'datetime', 'length' => null];
break;
case 'TIMESTAMP':
case 'TIMESTAMP(6)':
case 'TIMESTAMP(9)':
$field = ['type' => 'timestamp', 'length' => null];
break;
case 'NUMBER':
case 'INTEGER':
case 'PLS_INTEGER':
case 'BINARY_INTEGER':
if ($row['data_precision'] == 1) {
$field = ['type' => 'boolean', 'length' => null];
} elseif ($row['data_scale'] > 0) {
$field = ['type' => 'decimal', 'length' => $row['data_precision'], 'precision' => $row['data_scale']];
} else {
$field = ['type' => 'integer', 'length' => $row['data_precision']];
}
break;
case 'FLOAT':
case 'BINARY_FLOAT':
case 'BINARY_DOUBLE':
$field = ['type' => 'float', 'length' => $row['data_precision']];
break;
case 'NCHAR':
case 'NVARCHAR2':
case 'CHAR':
case 'VARCHAR2':
case 'LONG':
case 'ROWID':
case 'UROWID':
$length = $row['char_length'];
if ($length == 36) {
$field = ['type' => 'uuid', 'length' => null];
} else {
$field = ['type' => 'string', 'length' => $length];
}
break;
case 'NCLOB':
case 'CLOB':
$field = ['type' => 'text', 'length' => $row['char_length']];
break;
case 'RAW':
case 'LONG RAW':
case 'BLOB':
$field = ['type' => 'binary', 'length' => $row['char_length']];
break;
default:
}
$field += ['null' => $row['null'] === 'Y' ? true : false, 'default' => $row['default'], 'comment' => $row['comment']];
$table->addColumn($this->_transformValueCase($row['name']), $field);
}
示例10: testColumnSqlPrimaryKeyBigInt
/**
* Test generating a bigint column that is a primary key.
*
* @return void
*/
public function testColumnSqlPrimaryKeyBigInt()
{
$driver = $this->_getMockedDriver();
$schema = new SqliteSchema($driver);
$table = new Table('articles');
$table->addColumn('id', ['type' => 'biginteger', 'null' => false])->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$result = $schema->columnSql($table, 'id');
$this->assertEquals($result, '"id" BIGINT NOT NULL');
$result = $schema->constraintSql($table, 'primary');
$this->assertEquals('CONSTRAINT "primary" PRIMARY KEY ("id")', $result, 'Bigint primary keys are not special.');
}
示例11: testTruncateSql
/**
* Test truncateSql()
*
* @return void
*/
public function testTruncateSql()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMock('Cake\\Database\\Connection', [], [], '', false);
$connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
$table = new Table('schema_articles');
$table->addColumn('id', 'integer')->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$result = $table->truncateSql($connection);
$this->assertCount(2, $result);
$this->assertEquals('DELETE FROM [schema_articles]', $result[0]);
$this->assertEquals('DBCC CHECKIDENT([schema_articles], RESEED, 0)', $result[1]);
}
示例12: prepareColumn
/**
* Prepare column
*
* @param DOMElement $table
* @param DOMXPath $xpath
* @param Table $schemaTable
*/
protected function prepareColumn(DOMElement $table, DOMXPath $xpath, Table $schemaTable)
{
$columns = $xpath->query(sprintf('/database/table[@name="%s"]/column', $table->getAttribute('name')));
/** @var \DOMElement $column */
foreach ($columns as $column) {
$schemaTable->addColumn($column->getAttribute('name'), ['type' => $column->getAttribute('type') !== '' ? $column->getAttribute('type') : null, 'length' => $column->getAttribute('length') !== '' ? $column->getAttribute('length') : null, 'precision' => $column->getAttribute('precision') !== '' ? $column->getAttribute('precision') : null, 'default' => $column->getAttribute('default') !== '' ? $column->getAttribute('default') : null, 'null' => $column->getAttribute('null') !== '' ? filter_var($column->getAttribute('null'), FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]) : null, 'fixed' => $column->getAttribute('fixed') !== '' ? $column->getAttribute('fixed') : null, 'unsigned' => $column->getAttribute('unsigned') !== '' ? $column->getAttribute('unsigned') : null, 'comment' => $column->getAttribute('comment') !== '' ? $column->getAttribute('comment') : null]);
}
}
示例13: testAddConstraintForeignKeyBadData
/**
* Add a foreign key constraint with bad data
*
* @dataProvider badForeignKeyProvider
* @expectedException \Cake\Database\Exception
* @return void
*/
public function testAddConstraintForeignKeyBadData($data)
{
$table = new Table('articles');
$table->addColumn('author_id', 'integer')->addConstraint('author_id_idx', $data);
}
示例14: convertColumnDescription
/**
* {@inheritDoc}
*/
public function convertColumnDescription(Table $table, $row)
{
$field = $this->_convertColumn($row['Type']);
$field += ['null' => $row['Null'] === 'YES' ? true : false, 'default' => $row['Default'], 'collate' => $row['Collation'], 'comment' => $row['Comment']];
if (isset($row['Extra']) && $row['Extra'] === 'auto_increment') {
$field['autoIncrement'] = true;
}
$table->addColumn($row['Field'], $field);
}
示例15: Table
<?php
/**
* Queued Tasks schema file
*
* @author David Yell <neon1024@gmail.com>
* @author MGriesbach@gmail.com
*/
use Cake\Database\Schema\Table;
$t = new Table('queued_tasks');
$t->addColumn('id', ['type' => 'integer', 'length' => 10, 'null' => false, 'default' => null]);
$t->addColumn('job_type', ['type' => 'string', 'null' => false, 'length' => 45]);
$t->addColumn('data', ['type' => 'text', 'null' => true, 'default' => null]);
$t->addColumn('job_group', ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null]);
$t->addColumn('reference', ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null]);
$t->addColumn('created', ['type' => 'datetime', 'null' => true, 'default' => null]);
$t->addColumn('notbefore', ['type' => 'datetime', 'null' => true, 'default' => null]);
$t->addColumn('fetched', ['type' => 'datetime', 'null' => true, 'default' => null]);
$t->addColumn('progress', ['type' => 'float', 'length' => '3,2', 'null' => true, 'default' => null]);
$t->addColumn('status', ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null]);
$t->addColumn('completed', ['type' => 'datetime', 'null' => true, 'default' => null]);
$t->addColumn('failed', ['type' => 'integer', 'null' => false, 'default' => '0', 'length' => 3]);
$t->addColumn('failure_message', ['type' => 'text', 'null' => true, 'default' => null]);
$t->addColumn('workerkey', ['type' => 'string', 'null' => true, 'length' => 45]);
$t->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$t->options(['collate' => 'utf8_unicode_ci']);