本文整理汇总了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;
}
示例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);
}
}
}
示例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()));
}
示例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));
}
示例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);
}