• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Schema\Table类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _initializeSchema

 /**
  * @param \Cake\Database\Schema\Table $table Table schema
  * @return \Cake\Database\Schema\Table
  */
 protected function _initializeSchema(Schema $table)
 {
     $table->columnType('payload', 'serialize');
     $table->columnType('options', 'serialize');
     $table->columnType('history', 'json');
     return parent::_initializeSchema($table);
 }
开发者ID:uafrica,项目名称:delayed-jobs,代码行数:11,代码来源:DelayedJobsTable.php


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


示例3: _initializeSchema

 /**
  * Initialize schema method
  *
  * @param \Cake\Database\Schema\Table $schema The schema of the Table.
  *
  * @return \Cake\Database\Schema\Table
  */
 protected function _initializeSchema(Schema $schema)
 {
     $schema->columnType('secret', 'encryptedsecurity');
     $schema->columnType('username', 'encryptedsecurity');
     $schema->columnType('session', 'encryptedsecurity');
     $schema->columnType('recovery_code', 'encryptedsecurity');
     return $schema;
 }
开发者ID:Xety,项目名称:Xeta,代码行数:15,代码来源:UsersTwoFactorAuthTable.php


示例4: fieldValidation

 /**
  * Does individual field validation handling.
  *
  * @param \Cake\Database\Schema\Table $schema The table schema for the current field.
  * @param string $fieldName Name of field to be validated.
  * @param array $metaData metadata for field
  * @param string $primaryKey The primary key field
  * @return array Array of validation for the field.
  */
 public function fieldValidation($schema, $fieldName, array $metaData, $primaryKey)
 {
     $ignoreFields = ['created', 'modified', 'updated'];
     if (in_array($fieldName, $ignoreFields)) {
         return false;
     }
     $rule = false;
     if ($fieldName === 'email') {
         $rule = 'email';
     } elseif ($metaData['type'] === 'uuid') {
         $rule = 'uuid';
     } elseif ($metaData['type'] === 'integer') {
         $rule = 'numeric';
     } elseif ($metaData['type'] === 'float') {
         $rule = 'numeric';
     } elseif ($metaData['type'] === 'decimal') {
         $rule = 'decimal';
     } elseif ($metaData['type'] === 'boolean') {
         $rule = 'boolean';
     } elseif ($metaData['type'] === 'date') {
         $rule = 'date';
     } elseif ($metaData['type'] === 'time') {
         $rule = 'time';
     } elseif ($metaData['type'] === 'datetime') {
         $rule = 'datetime';
     } elseif ($metaData['type'] === 'inet') {
         $rule = 'ip';
     }
     $allowEmpty = false;
     if (in_array($fieldName, $primaryKey)) {
         $allowEmpty = 'create';
     } elseif ($metaData['null'] === true) {
         $allowEmpty = true;
     }
     $validation = ['valid' => ['rule' => $rule, 'allowEmpty' => $allowEmpty]];
     foreach ($schema->constraints() as $constraint) {
         $constraint = $schema->constraint($constraint);
         if (!in_array($fieldName, $constraint['columns']) || count($constraint['columns']) > 1) {
             continue;
         }
         if ($constraint['type'] === SchemaTable::CONSTRAINT_UNIQUE) {
             $validation['unique'] = ['rule' => 'validateUnique', 'provider' => 'table'];
         }
     }
     return $validation;
 }
开发者ID:gbauso,项目名称:asirb,代码行数:55,代码来源:ModelTask.php


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


示例6: indexSql

 /**
  * {@inheritDoc}
  */
 public function indexSql(Table $table, $name)
 {
     $data = $table->index($name);
     if ($data['type'] === Table::INDEX_INDEX) {
         $out = 'KEY ';
     }
     if ($data['type'] === Table::INDEX_FULLTEXT) {
         $out = 'FULLTEXT KEY ';
     }
     $out .= $this->_driver->quoteIdentifier($name);
     return $this->_keySql($out, $data);
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:15,代码来源:MysqlSchema.php


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


示例8: 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('articles');
     $result = $table->truncateSql($connection);
     $this->assertCount(1, $result);
     $this->assertEquals('TRUNCATE TABLE `articles`', $result[0]);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:15,代码来源:MysqlSchemaTest.php


示例9: testTruncateSqlNoSequences

 /**
  * Test truncateSql() with no sequences
  *
  * @return void
  */
 public function testTruncateSqlNoSequences()
 {
     $driver = $this->_getMockedDriver();
     $connection = $this->getMock('Cake\\Database\\Connection', [], [], '', false);
     $connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
     $statement = $this->getMock('\\PDOStatement', ['execute', 'rowCount', 'closeCursor', 'fetch']);
     $driver->connection()->expects($this->once())->method('prepare')->with('SELECT 1 FROM sqlite_master WHERE name = "sqlite_sequence"')->will($this->returnValue($statement));
     $statement->expects($this->once())->method('fetch')->will($this->returnValue(false));
     $table = new Table('articles');
     $result = $table->truncateSql($connection);
     $this->assertCount(1, $result);
     $this->assertEquals('DELETE FROM "articles"', $result[0]);
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:18,代码来源:SqliteSchemaTest.php


示例10: columnSql

 /**
  * {@inheritDoc}
  */
 public function columnSql(Table $table, $name)
 {
     $data = $table->column($name);
     $out = $this->_driver->quoteIdentifier($name);
     $typeMap = ['integer' => ' INTEGER', 'biginteger' => ' BIGINT', 'boolean' => ' BOOLEAN', 'binary' => ' LONGBLOB', 'float' => ' FLOAT', 'decimal' => ' DECIMAL', 'text' => ' TEXT', 'date' => ' DATE', 'time' => ' TIME', 'datetime' => ' DATETIME', 'timestamp' => ' TIMESTAMP', 'uuid' => ' CHAR(36)'];
     $specialMap = ['string' => true];
     if (isset($typeMap[$data['type']])) {
         $out .= $typeMap[$data['type']];
     }
     if (isset($specialMap[$data['type']])) {
         switch ($data['type']) {
             case 'string':
                 $out .= !empty($data['fixed']) ? ' CHAR' : ' VARCHAR';
                 if (!isset($data['length'])) {
                     $data['length'] = 255;
                 }
                 break;
         }
     }
     $hasLength = ['integer', 'string'];
     if (in_array($data['type'], $hasLength, true) && isset($data['length'])) {
         $out .= '(' . (int) $data['length'] . ')';
     }
     $hasPrecision = ['float', 'decimal'];
     if (in_array($data['type'], $hasPrecision, true) && (isset($data['length']) || isset($data['precision']))) {
         $out .= '(' . (int) $data['length'] . ',' . (int) $data['precision'] . ')';
     }
     $hasUnsigned = ['float', 'decimal', 'integer', 'biginteger'];
     if (in_array($data['type'], $hasUnsigned, true) && isset($data['unsigned']) && $data['unsigned'] === true) {
         $out .= ' UNSIGNED';
     }
     if (isset($data['null']) && $data['null'] === false) {
         $out .= ' NOT NULL';
     }
     $addAutoIncrement = [$name] == (array) $table->primaryKey() && !$table->hasAutoIncrement();
     if (in_array($data['type'], ['integer', 'biginteger']) && ($data['autoIncrement'] === true || $addAutoIncrement)) {
         $out .= ' AUTO_INCREMENT';
     }
     if (isset($data['null']) && $data['null'] === true) {
         $out .= $data['type'] === 'timestamp' ? ' NULL' : ' DEFAULT NULL';
         unset($data['default']);
     }
     if (isset($data['default']) && !in_array($data['type'], ['timestamp', 'datetime'])) {
         $out .= ' DEFAULT ' . $this->_driver->schemaValue($data['default']);
         unset($data['default']);
     }
     if (isset($data['default']) && in_array($data['type'], ['timestamp', 'datetime']) && strtolower($data['default']) === 'current_timestamp') {
         $out .= ' DEFAULT CURRENT_TIMESTAMP';
         unset($data['default']);
     }
     if (isset($data['comment']) && $data['comment'] !== '') {
         $out .= ' COMMENT ' . $this->_driver->schemaValue($data['comment']);
     }
     return $out;
 }
开发者ID:voycey,项目名称:cakephp-salesforce,代码行数:58,代码来源:SalesforceSchema.php


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


示例12: column

 /**
  * Returns an array of column data for a single column
  *
  * @param \Cake\Database\Schema\Table $tableSchema Name of the table to retrieve columns for
  * @param string $column A column to retrieve data for
  * @return array
  */
 public function column($tableSchema, $column)
 {
     return ['columnType' => $tableSchema->columnType($column), 'options' => $this->attributes($tableSchema->name(), $column)];
 }
开发者ID:josegonzalez,项目名称:migrations,代码行数:11,代码来源:MigrationHelper.php


示例13: Table

<?php

/**
 * Queued Tasks schema file
 *
 * @author David Yell <[email protected]>
 * @author [email protected]
 */
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


示例14: _initializeSchema

 /**
  * _initializeSchema
  */
 protected function _initializeSchema(\Cake\Database\Schema\Table $table)
 {
     $table->columnType('image', 'proffer.file');
     return $table;
 }
开发者ID:nadymain,项目名称:quebolu,代码行数:8,代码来源:UploadsTable.php


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


示例16: _initializeSchema

 /**
  * @param \Cake\Database\Schema\Table $schema
  *
  * @return \Cake\Database\Schema\Table
  */
 protected function _initializeSchema(Schema $schema)
 {
     $schema->columnType('year_of_birth', 'year');
     return $schema;
 }
开发者ID:dereuromark,项目名称:cakephp-shim,代码行数:10,代码来源:YearTypesTable.php


示例17: _initializeSchema

 /**
  * @param \Cake\Database\Schema\Table $table
  *
  * @return \Cake\Database\Schema\Table
  */
 protected function _initializeSchema(Schema $table)
 {
     $table->columnType('image', 'image');
     return $table;
 }
开发者ID:dereuromark,项目名称:cakephp-captcha,代码行数:10,代码来源:CaptchasTable.php


示例18: dropTableSql

 /**
  * Generate the SQL to drop a table.
  *
  * @param \Cake\Database\Schema\Table $table Table instance
  * @return array SQL statements to drop a table.
  */
 public function dropTableSql(Table $table)
 {
     $sql = sprintf('DROP TABLE %s CASCADE', $this->_driver->quoteIdentifier($table->name()));
     return [$sql];
 }
开发者ID:juanshot,项目名称:cakephp,代码行数:11,代码来源:PostgresSchema.php


示例19: _initializeSchema

 /**
  * Alter the schema used by this table.
  *
  * @param \Cake\Database\Schema\Table $table The table definition fetched from database
  * @return \Cake\Database\Schema\Table the altered schema
  */
 protected function _initializeSchema(Schema $table)
 {
     $table->columnType('data', 'serialized');
     return $table;
 }
开发者ID:quickapps-plugins,项目名称:content,代码行数:11,代码来源:ContentRevisionsTable.php


示例20: truncateTableSql

 /**
  * {@inheritDoc}
  */
 public function truncateTableSql(Table $table)
 {
     $name = $table->name();
     $sql = [];
     if ($this->hasSequences()) {
         $sql[] = sprintf('DELETE FROM sqlite_sequence WHERE name="%s"', $name);
     }
     $sql[] = sprintf('DELETE FROM "%s"', $name);
     return $sql;
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:13,代码来源:SqliteSchema.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Datasource\ConnectionManager类代码示例发布时间:2022-05-23
下一篇:
PHP Database\Type类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap