當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。