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


PHP Table::addConstraint方法代码示例

本文整理汇总了PHP中Cake\Database\Schema\Table::addConstraint方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::addConstraint方法的具体用法?PHP Table::addConstraint怎么用?PHP Table::addConstraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Database\Schema\Table的用法示例。


在下文中一共展示了Table::addConstraint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _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

示例2: createConstraints

 /**
  * {@inheritDoc}
  */
 public function createConstraints(ConnectionInterface $db)
 {
     if (empty($this->_constraints)) {
         return true;
     }
     foreach ($this->_constraints as $name => $data) {
         $this->_schema->addConstraint($name, $data);
     }
     $sql = $this->_schema->addConstraintSql($db);
     if (empty($sql)) {
         return true;
     }
     foreach ($sql as $stmt) {
         $db->execute($stmt)->closeCursor();
     }
     return true;
 }
开发者ID:taodf,项目名称:cakephp,代码行数:20,代码来源:TestFixture.php

示例3: _ensureTable

 protected function _ensureTable($archiveTable)
 {
     try {
         $archiveTable->schema();
     } catch (Exception $e) {
         $djSchema = TableRegistry::get('DelayedJobs.DelayedJobs')->schema();
         $djColumns = $djSchema->columns();
         $columns = [];
         foreach ($djColumns as $djColumn) {
             $columns[$djColumn] = $djSchema->column($djColumn);
         }
         $columns['payload']['type'] = 'binary';
         $columns['options']['type'] = 'binary';
         $archiveTableSchema = new Table($archiveTable->table(), $columns);
         $archiveTableSchema->addConstraint('primary', $djSchema->constraint('primary'));
         $createSql = $archiveTableSchema->createSql($archiveTable->connection());
         foreach ($createSql as $createSqlQuery) {
             $archiveTable->connection()->query($createSqlQuery);
         }
     }
 }
开发者ID:uafrica,项目名称:delayed-jobs,代码行数:21,代码来源:ArchiveWorker.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: convertForeignKeyDescription

 /**
  * {@inheritDoc}
  */
 public function convertForeignKeyDescription(Table $table, $row)
 {
     $data = ['type' => Table::CONSTRAINT_FOREIGN, 'columns' => [$row['COLUMN_NAME']], 'references' => [$row['REFERENCED_TABLE_NAME'], $row['REFERENCED_COLUMN_NAME']], 'update' => $this->_convertOnClause($row['UPDATE_RULE']), 'delete' => $this->_convertOnClause($row['DELETE_RULE'])];
     $name = $row['CONSTRAINT_NAME'];
     $table->addConstraint($name, $data);
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:9,代码来源:MysqlSchema.php

示例6: schema

 /**
  * Returns the schema table object describing this table's properties.
  *
  * If an \Cake\Database\Schema\Table is passed, it will be used for this table
  * instead of the default one.
  *
  * If an array is passed, a new \Cake\Database\Schema\Table will be constructed
  * out of it and used as the schema for this table.
  *
  * @param array|\Cake\Database\Schema\Table|null $schema New schema to be used for this table
  * @return \Cake\Database\Schema\Table
  */
 public function schema($schema = null)
 {
     if ($schema === null) {
         if ($this->_schema === null) {
             $this->_schema = $this->_initializeSchema($this->connection()->schemaCollection()->describe($this->table()));
         }
         return $this->_schema;
     }
     if (is_array($schema)) {
         $constraints = [];
         if (isset($schema['_constraints'])) {
             $constraints = $schema['_constraints'];
             unset($schema['_constraints']);
         }
         $schema = new Schema($this->table(), $schema);
         foreach ($constraints as $name => $value) {
             $schema->addConstraint($name, $value);
         }
     }
     return $this->_schema = $schema;
 }
开发者ID:yao-dev,项目名称:blog-mvc.github.io,代码行数:33,代码来源:Table.php

示例7: convertForeignKeyDescription

 /**
  * {@inheritDoc}
  */
 public function convertForeignKeyDescription(Table $table, $row)
 {
     preg_match('/REFERENCES ([^\\)]+)\\(([^\\)]+)\\)/', $row['definition'], $matches);
     $tableName = $matches[1];
     $column = $matches[2];
     preg_match('/FOREIGN KEY \\(([^\\)]+)\\) REFERENCES/', $row['definition'], $matches);
     $columns = $this->_convertColumnList($matches[1]);
     $data = ['type' => Table::CONSTRAINT_FOREIGN, 'columns' => $columns, 'references' => [$tableName, $column], 'update' => $this->_convertOnClause($row['update_type']), 'delete' => $this->_convertOnClause($row['delete_type'])];
     $name = $row['name'];
     $table->addConstraint($name, $data);
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:14,代码来源:PostgresSchema.php

示例8: _convertConstraint

 /**
  * Add/update a constraint into the schema object.
  *
  * @param \Cake\Database\Schema\Table $table The table to update.
  * @param string $name The index name.
  * @param string $type The index type.
  * @param array $row The metadata record to update with.
  * @return void
  */
 protected function _convertConstraint($table, $name, $type, $row)
 {
     $constraint = $table->constraint($name);
     if (!$constraint) {
         $constraint = ['type' => $type, 'columns' => []];
     }
     $constraint['columns'][] = $row['attname'];
     $table->addConstraint($name, $constraint);
 }
开发者ID:AlexandreSGV,项目名称:siteentec,代码行数:18,代码来源:PostgresSchema.php

示例9: testAddConstraintError

 /**
  * Test that an exception is raised when constraints
  * are added for fields that do not exist.
  *
  * @dataProvider addConstaintErrorProvider
  * @expectedException \Cake\Database\Exception
  * @return void
  */
 public function testAddConstraintError($props)
 {
     $table = new Table('articles');
     $table->addColumn('author_id', 'integer');
     $table->addConstraint('author_idx', $props);
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:14,代码来源:TableTest.php

示例10: testResetDbIfTableExists

 /**
  * Test that if a table already exists in the test database, it will dropped
  * before being recreated
  *
  * @return void
  */
 public function testResetDbIfTableExists()
 {
     $db = ConnectionManager::get('test');
     $restore = $db->logQueries();
     $db->logQueries(true);
     $this->manager->setDebug(true);
     $buffer = new ConsoleOutput();
     Log::config('testQueryLogger', ['className' => 'Console', 'stream' => $buffer]);
     $table = new Table('articles', ['id' => ['type' => 'integer', 'unsigned' => true], 'title' => ['type' => 'string', 'length' => 255]]);
     $table->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
     $sql = $table->createSql($db);
     foreach ($sql as $stmt) {
         $db->execute($stmt);
     }
     $test = $this->getMockBuilder('Cake\\TestSuite\\TestCase')->getMock();
     $test->fixtures = ['core.articles'];
     $this->manager->fixturize($test);
     $this->manager->load($test);
     $db->logQueries($restore);
     $this->assertContains('DROP TABLE', implode('', $buffer->messages()));
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:27,代码来源:FixtureManagerTest.php

示例11: testInitNoImportNoFields

 /**
  * test schema reflection without $import or $fields will reflect the schema
  *
  * @return void
  */
 public function testInitNoImportNoFields()
 {
     $db = ConnectionManager::get('test');
     $collection = $db->schemaCollection();
     if (!in_array('letters', $collection->listTables())) {
         $table = new Table('letters', ['id' => ['type' => 'integer'], 'letter' => ['type' => 'string', 'length' => 1]]);
         $table->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
         $sql = $table->createSql($db);
         foreach ($sql as $stmt) {
             $db->execute($stmt);
         }
     }
     $fixture = new LettersFixture();
     $fixture->init();
     $this->assertEquals(['id', 'letter'], $fixture->schema()->columns());
     $db = $this->getMockBuilder('Cake\\Database\\Connection')->setMethods(['prepare', 'execute'])->disableOriginalConstructor()->getMock();
     $db->expects($this->never())->method('prepare');
     $db->expects($this->never())->method('execute');
     $this->assertTrue($fixture->create($db));
     $this->assertTrue($fixture->drop($db));
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:26,代码来源:TestFixtureTest.php

示例12: 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

示例13: convertForeignKeyDescription

 /**
  * {@inheritDoc}
  */
 public function convertForeignKeyDescription(Table $table, $row)
 {
     $row = array_change_key_case($row);
     $data = ['type' => Table::CONSTRAINT_FOREIGN, 'columns' => strtoupper($row['column_name']), 'references' => [$row['referenced_owner'] . '.' . $row['referenced_table_name'], strtoupper($row['referenced_column_name'])], 'update' => Table::ACTION_SET_NULL, 'delete' => $this->_convertOnClause($row['delete_rule'])];
     $table->addConstraint($row['constraint_name'], $data);
 }
开发者ID:cakedc,项目名称:cakephp-oracle-driver,代码行数:9,代码来源:OracleSchema.php

示例14: preparePrimaryConstraint

 /**
  * Prepare primary constraint
  *
  * @param DOMElement $table
  * @param DOMXPath   $xpath
  * @param Table      $schemaTable
  */
 protected function preparePrimaryConstraint(DOMElement $table, DOMXPath $xpath, Table $schemaTable)
 {
     $primaryTags = $xpath->query(sprintf('/database/table[@name="%s"]/primary', $table->getAttribute('name')));
     /** @var DOMElement $primaryTag */
     foreach ($primaryTags as $primaryTag) {
         $primaryColumns = $primaryTag->getElementsByTagName('primary-column');
         $constraintName = $primaryTag->getAttribute('name');
         $tmpPrimaryColumn = [];
         /** @var DOMElement $primaryColumn */
         foreach ($primaryColumns as $primaryColumn) {
             $tmpPrimaryColumn[] = $primaryColumn->getAttribute('name');
         }
         if (empty(trim($constraintName))) {
             $constraintName = sprintf('%s_%s_%s', $table->getAttribute('name'), implode('_', $tmpPrimaryColumn), 'primary');
         }
         $schemaTable->addConstraint($constraintName, ['type' => 'primary', 'columns' => $tmpPrimaryColumn]);
     }
 }
开发者ID:radphp,项目名称:cake-orm-bundle,代码行数:25,代码来源:BuildAction.php

示例15: _prepareSchema

 /**
  * Gets an schema instance for the given fixture class.
  *
  * @param string $fixtureClassName The fixture to be "converted"
  * @return \Cake\Database\Schema\Table Schema instance
  */
 protected function _prepareSchema($fixtureClassName)
 {
     $fixture = new $fixtureClassName();
     if (!empty($fixture->table)) {
         $tableName = $fixture->table;
     } else {
         $tableName = (string) Inflector::underscore(str_replace_last('Fixture', '', $fixtureClassName));
     }
     list($fields, $constraints, $indexes, $options) = $this->_prepareSchemaProperties($fixture);
     $schema = new TableSchema($tableName, $fields);
     foreach ($constraints as $name => $attrs) {
         $schema->addConstraint($name, $attrs);
     }
     foreach ($indexes as $name => $attrs) {
         $schema->addIndex($name, $attrs);
     }
     if (!empty($options)) {
         $schema->options($options);
     }
     return $schema;
 }
开发者ID:quickapps-plugins,项目名称:installer,代码行数:27,代码来源:DatabaseInstaller.php


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