本文整理汇总了PHP中Doctrine\DBAL\Platforms\AbstractPlatform::getCreateTableSQL方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractPlatform::getCreateTableSQL方法的具体用法?PHP AbstractPlatform::getCreateTableSQL怎么用?PHP AbstractPlatform::getCreateTableSQL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Platforms\AbstractPlatform
的用法示例。
在下文中一共展示了AbstractPlatform::getCreateTableSQL方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processQueueCallback
/**
* ->processQueueCallback(function (\Dja\Db\Model\Metadata $metadata, \Doctrine\DBAL\Schema\Table $table, array $sql, \Doctrine\DBAL\Connection $db) {})
* @param callable|\Closure $callBack
*/
public function processQueueCallback(\Closure $callBack)
{
$callbackQueue = [];
while (count($this->generateQueue)) {
$modelName = array_shift($this->generateQueue);
try {
/** @var Metadata $metadata */
$metadata = $modelName::metadata();
$tblName = $metadata->getDbTableName();
if ($this->db->getSchemaManager()->tablesExist($tblName)) {
continue;
}
if (isset($this->generated[$tblName])) {
continue;
}
$table = $this->metadataToTable($metadata);
$this->generated[$tblName] = 1;
$sql = $this->dp->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES);
array_unshift($callbackQueue, [$metadata, $table, $sql]);
$fks = $table->getForeignKeys();
if (count($fks)) {
$sql = [];
foreach ($fks as $fk) {
$sql[] = $this->dp->getCreateForeignKeySQL($fk, $table);
}
array_push($callbackQueue, [$metadata, $table, $sql]);
}
} catch (\Exception $e) {
pr($e->__toString());
}
}
foreach ($callbackQueue as $args) {
$callBack($args[0], $args[1], $args[2], $this->db);
}
}
示例2: dumpTableStructure
/**
* @param Table[] $tables
*/
public function dumpTableStructure(array $tables)
{
$this->logger->info('Dumping table structure');
foreach ($tables as $table) {
$structure = $this->platform->getCreateTableSQL($table);
$this->dumpOutput->writeln(implode(";\n", $structure) . ';');
}
}
示例3: testQuotedColumnInForeignKeyPropagation
/**
* @group DBAL-374
*/
public function testQuotedColumnInForeignKeyPropagation()
{
$table = new Table('`quoted`');
$table->addColumn('create', 'string');
$table->addColumn('foo', 'string');
$table->addColumn('`bar`', 'string');
// Foreign table with reserved keyword as name (needs quotation).
$foreignTable = new Table('foreign');
$foreignTable->addColumn('create', 'string');
// Foreign column with reserved keyword as name (needs quotation).
$foreignTable->addColumn('bar', 'string');
// Foreign column with non-reserved keyword as name (does not need quotation).
$foreignTable->addColumn('`foo-bar`', 'string');
// Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite).
$table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_RESERVED_KEYWORD');
// Foreign table with non-reserved keyword as name (does not need quotation).
$foreignTable = new Table('foo');
$foreignTable->addColumn('create', 'string');
// Foreign column with reserved keyword as name (needs quotation).
$foreignTable->addColumn('bar', 'string');
// Foreign column with non-reserved keyword as name (does not need quotation).
$foreignTable->addColumn('`foo-bar`', 'string');
// Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite).
$table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_NON_RESERVED_KEYWORD');
// Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite).
$foreignTable = new Table('`foo-bar`');
$foreignTable->addColumn('create', 'string');
// Foreign column with reserved keyword as name (needs quotation).
$foreignTable->addColumn('bar', 'string');
// Foreign column with non-reserved keyword as name (does not need quotation).
$foreignTable->addColumn('`foo-bar`', 'string');
// Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite).
$table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_INTENDED_QUOTATION');
$sql = $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS);
$this->assertEquals($this->getQuotedColumnInForeignKeySQL(), $sql);
}
示例4: _toSql
/**
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
* @param boolean $saveMode
*
* @return array
*/
protected function _toSql(AbstractPlatform $platform, $saveMode = false)
{
$sql = array();
if ($platform->supportsSchemas()) {
foreach ($this->newNamespaces as $newNamespace) {
$sql[] = $platform->getCreateSchemaSQL($newNamespace);
}
}
if ($platform->supportsForeignKeyConstraints() && $saveMode == false) {
foreach ($this->orphanedForeignKeys as $orphanedForeignKey) {
$sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTableName());
}
}
if ($platform->supportsSequences() == true) {
foreach ($this->changedSequences as $sequence) {
$sql[] = $platform->getAlterSequenceSQL($sequence);
}
if ($saveMode === false) {
foreach ($this->removedSequences as $sequence) {
$sql[] = $platform->getDropSequenceSQL($sequence);
}
}
foreach ($this->newSequences as $sequence) {
$sql[] = $platform->getCreateSequenceSQL($sequence);
}
}
$foreignKeySql = array();
foreach ($this->newTables as $table) {
$sql = array_merge($sql, $platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES));
if ($platform->supportsForeignKeyConstraints()) {
foreach ($table->getForeignKeys() as $foreignKey) {
$foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table);
}
}
}
$sql = array_merge($sql, $foreignKeySql);
if ($saveMode === false) {
foreach ($this->removedTables as $table) {
$sql[] = $platform->getDropTableSQL($table);
}
}
foreach ($this->changedTables as $tableDiff) {
$sql = array_merge($sql, $platform->getAlterTableSQL($tableDiff));
}
return $sql;
}
示例5: createTable
/**
* Create a new table.
*
* @param Table $table
* @param int $createFlags
*/
public function createTable(Table $table)
{
$createFlags = AbstractPlatform::CREATE_INDEXES | AbstractPlatform::CREATE_FOREIGNKEYS;
$this->_execSql($this->_platform->getCreateTableSQL($table, $createFlags));
}
示例6: acceptTable
/**
* Generate DDL Statements to create the accepted table with all its dependencies.
*
* @param Table $table
*/
public function acceptTable(Table $table)
{
$namespace = $this->getNamespace($table);
$this->_createTableQueries[$namespace] = array_merge($this->_createTableQueries[$namespace], $this->_platform->getCreateTableSQL($table));
}
示例7: getCreateTableSQL
/**
* {@inheritDoc}
*/
public function getCreateTableSQL(Table $table, $createFlags = null)
{
$createFlags = null === $createFlags ? self::CREATE_INDEXES | self::CREATE_FOREIGNKEYS : $createFlags;
return parent::getCreateTableSQL($table, $createFlags);
}
示例8: acceptTable
/**
* {@inheritdoc}
*/
public function acceptTable(Table $table)
{
$this->createTableQueries = array_merge($this->createTableQueries, (array) $this->platform->getCreateTableSQL($table));
}
示例9: getCreateTableSQL
/**
* @override
*/
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
{
$sql = parent::getCreateTableSQL($table, $createFlags);
$primary = array();
foreach ($table->getIndexes() as $index) {
/* @var $index Index */
if ($index->isPrimary()) {
$primary = $index->getColumns();
}
}
if (count($primary) === 1) {
foreach ($table->getForeignKeys() as $definition) {
$columns = $definition->getLocalColumns();
if (count($columns) === 1 && in_array($columns[0], $primary)) {
$sql[0] = str_replace(' IDENTITY', '', $sql[0]);
}
}
}
return $sql;
}