本文整理汇总了PHP中Propel\Generator\Util\QuickBuilder::setIdentifierQuoting方法的典型用法代码示例。如果您正苦于以下问题:PHP QuickBuilder::setIdentifierQuoting方法的具体用法?PHP QuickBuilder::setIdentifierQuoting怎么用?PHP QuickBuilder::setIdentifierQuoting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Generator\Util\QuickBuilder
的用法示例。
在下文中一共展示了QuickBuilder::setIdentifierQuoting方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyXml
/**
* @param string $xml
*
* @return Database|boolean
*/
public function applyXml($xml, $changeRequired = false)
{
$this->readDatabase();
$builder = new QuickBuilder();
$builder->setIdentifierQuoting(true);
$builder->setPlatform($this->database->getPlatform());
$builder->setSchema($xml);
$database = $builder->getDatabase();
$database->setSchema('migration');
$database->setPlatform($this->database->getPlatform());
$diff = DatabaseComparator::computeDiff($this->database, $database);
if (false === $diff) {
if ($changeRequired) {
throw new BuildException(sprintf("No changes in schema to current database: \nSchema database:\n%s\n\nCurrent Database:\n%s", $database, $this->database));
}
return false;
}
$sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
$this->con->beginTransaction();
if (!$sql) {
throw new BuildException(sprintf('Ooops. There is a diff between current database and schema xml but no SQL has been generated. Change: %s', $diff));
}
$statements = SqlParser::parseString($sql);
foreach ($statements as $statement) {
try {
$stmt = $this->con->prepare($statement);
$stmt->execute();
} catch (\Exception $e) {
throw new BuildException(sprintf("Can not execute SQL: \n%s\nFrom database: \n%s\n\nTo database: \n%s\n", $statement, $this->database, $database), null, $e);
}
}
$this->con->commit();
return $database;
}
示例2: dropForeignKey
/**
* Drop the foreign key in the `_user` table and check whether it generates
* the correct `DROP` SQL.
*/
private function dropForeignKey()
{
$this->readDatabase();
$updatedSchema = '
<database name="reverse-bookstore" identifierQuoting="true">
<table name="issue617_user">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
<parameter name="Charset" value="utf8"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="full_name" type="VARCHAR" size="50" required="true" />
</table>
<table name="issue617_group">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
<parameter name="Charset" value="utf8"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="VARCHAR" size="50" required="true" />
</table>
</database>
';
$this->updatedBuilder = new QuickBuilder();
$this->updatedBuilder->setIdentifierQuoting(true);
$this->updatedBuilder->setPlatform($this->database->getPlatform());
$this->updatedBuilder->setSchema($updatedSchema);
$diff = DatabaseComparator::computeDiff($this->database, $this->updatedBuilder->getDatabase());
$sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
$expected = '
ALTER TABLE `issue617_user` DROP FOREIGN KEY `issue617_user_fk_5936b3`;
DROP INDEX `issue617_user_fi_5936b3` ON `issue617_user`;
ALTER TABLE `issue617_user`
DROP `group_id`;
';
$this->assertContains($expected, $sql);
$this->updateSchema($this->updatedBuilder->getDatabase());
}
示例3: testNamespace
public function testNamespace()
{
$schema = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<database name="default" defaultIdMethod="native" namespace="Tests\\Issue730\\">
<table name="issue730_group" idMethod="native" phpName="Group">
<column name="id" phpName="Id" type="INTEGER" primaryKey="true" required="true"/>
<column name="name" phpName="Name" type="VARCHAR" size="100" required="true"/>
</table>
<table name="issue730_department_group" idMethod="native" phpName="Group" namespace="\\Tests\\Issue730\\Department">
<column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
<column name="name" type="VARCHAR" size="100" required="true"/>
<column name="group_id" phpName="GroupId" type="INTEGER"/>
<foreign-key foreignTable="issue730_group" phpName="Group" refPhpName="DepartmentGroup">
<reference local="group_id" foreign="id"/>
</foreign-key>
</table>
</database>
EOF;
$quickBuilder = new QuickBuilder();
$quickBuilder->setSchema($schema);
$quickBuilder->setIdentifierQuoting(true);
$platform = new SqlitePlatform();
$quickBuilder->setPlatform($platform);
$quickBuilder->build();
$groupA = new \Tests\Issue730\Group();
$groupA->setName('groupA');
$departmentGroup = new \Tests\Issue730\Department\Group();
$departmentGroup->setName('my department');
$departmentGroup->setGroup($groupA);
$this->assertEquals($groupA, $departmentGroup->getGroup());
$departmentGroups = $groupA->getDepartmentGroups();
$this->assertCount(1, $departmentGroups);
$this->assertEquals($departmentGroup, $departmentGroups->getFirst());
$groupA->save();
$departmentGroups = \Tests\Issue730\Department\GroupQuery::create()->filterByGroup($groupA)->find();
$this->assertCount(1, $departmentGroups);
$this->assertEquals($departmentGroup, $departmentGroups->getFirst());
$this->assertEquals('my department', $departmentGroups->getFirst()->getName());
}