当前位置: 首页>>代码示例>>PHP>>正文


PHP Table::addColumn方法代码示例

本文整理汇总了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);
 }
开发者ID:byu-oit-appdev,项目名称:eam,代码行数:28,代码来源:OracleSchema.php

示例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']);
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:40,代码来源:TestFixture.php

示例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']);
     }
 }
开发者ID:taodf,项目名称:cakephp,代码行数:33,代码来源:TestFixture.php

示例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']);
     }
 }
开发者ID:malhan23,项目名称:assignment-3,代码行数:28,代码来源:TestFixture.php

示例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);
 }
开发者ID:AlexandreSGV,项目名称:siteentec,代码行数:21,代码来源:PostgresSchema.php

示例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]);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:16,代码来源:PostgresSchemaTest.php

示例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);
     }
 }
开发者ID:cakephp,项目名称:cakephp,代码行数:24,代码来源:SqliteSchema.php

示例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');
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:18,代码来源:MysqlSchemaTest.php

示例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);
 }
开发者ID:cakedc,项目名称:cakephp-oracle-driver,代码行数:60,代码来源:OracleSchema.php

示例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.');
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:16,代码来源:SqliteSchemaTest.php

示例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]);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:17,代码来源:SqlserverSchemaTest.php

示例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]);
     }
 }
开发者ID:radphp,项目名称:cake-orm-bundle,代码行数:15,代码来源:BuildAction.php

示例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);
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:12,代码来源:TableTest.php

示例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);
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:12,代码来源:MysqlSchema.php

示例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']);
开发者ID:dereuromark,项目名称:cakephp-queue,代码行数:26,代码来源:queued_tasks.php


注:本文中的Cake\Database\Schema\Table::addColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。