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


PHP Table::createSql方法代码示例

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


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

示例1: create

 /**
  * {@inheritDoc}
  */
 public function create(ConnectionInterface $db)
 {
     if (empty($this->_schema)) {
         return false;
     }
     try {
         $queries = $this->_schema->createSql($db);
         foreach ($queries as $query) {
             $db->execute($query)->closeCursor();
         }
     } catch (Exception $e) {
         $msg = sprintf('Fixture creation for "%s" failed "%s"', $this->table, $e->getMessage());
         Log::error($msg);
         trigger_error($msg, E_USER_WARNING);
         return false;
     }
     return true;
 }
开发者ID:HarkiratGhotra,项目名称:cake,代码行数:21,代码来源:TestFixture.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: 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

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

示例5: createSql

 /**
  * Generate the SQL to create the Table without foreign keys.
  *
  * Uses the connection to access the schema dialect
  * to generate platform specific SQL.
  *
  * @param Connection $connection The connection to generate SQL for.
  * @return array List of SQL statements to create the table and the
  *    required indexes.
  */
 public function createSql(ConnectionInterface $connection)
 {
     $this->_extractForeignKeys($connection);
     return parent::createSql($connection);
 }
开发者ID:scherersoftware,项目名称:cakephp-schema,代码行数:15,代码来源:Table.php


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