本文整理汇总了PHP中Propel\Generator\Util\QuickBuilder::getDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP QuickBuilder::getDatabase方法的具体用法?PHP QuickBuilder::getDatabase怎么用?PHP QuickBuilder::getDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Generator\Util\QuickBuilder
的用法示例。
在下文中一共展示了QuickBuilder::getDatabase方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyXml
/**
* @param string $xml
*
* @return Database
*/
public function applyXml($xml)
{
$this->readDatabase();
$builder = new QuickBuilder();
$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) {
return null;
}
$sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
$this->con->beginTransaction();
$statements = SqlParser::parseString($sql);
foreach ($statements as $statement) {
try {
$stmt = $this->con->prepare($statement);
$stmt->execute();
} catch (\Exception $e) {
$this->con->rollBack();
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: 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;
}
示例3: checkDeletedFk
private function checkDeletedFk()
{
$this->readDatabase();
$diff = DatabaseComparator::computeDiff($this->database, $this->updatedBuilder->getDatabase());
$sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
$expected = 'issue617_user';
$this->assertNotContains($expected, $sql);
}
示例4: testValidateReturnsTrueForValidSchema
public function testValidateReturnsTrueForValidSchema()
{
$schema = <<<EOF
<database name="bookstore">
<table name="book">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="title" type="VARCHAR" size="100" primaryString="true" />
</table>
</database>
EOF;
$builder = new QuickBuilder();
$builder->setSchema($schema);
$database = $builder->getDatabase();
$appData = new AppData();
$appData->addDatabase($database);
$validator = new SchemaValidator($appData);
$this->assertTrue($validator->validate());
}
示例5: setupInitSchema
/**
* Setups the initial schema.
*/
private function setupInitSchema()
{
/*
* Create issue617 tables with foreign keys
*/
$schema = '
<database name="bookstore">
<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" />
<!-- this column (and FK) will be removed from schema, but not from DB on migrate -->
<column name="group_id" type="INTEGER" />
<foreign-key foreignTable="issue617_group" onDelete="setnull">
<reference local="group_id" foreign="id" />
</foreign-key>
</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>
';
$builder = new QuickBuilder();
$builder->setPlatform($this->database->getPlatform());
$builder->setSchema($schema);
$diff = DatabaseComparator::computeDiff($this->database, $builder->getDatabase());
$sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
$expected = '
CREATE TABLE `issue617_user`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`full_name` VARCHAR(50) NOT NULL,
`group_id` INTEGER,
PRIMARY KEY (`id`),
INDEX `issue617_user_fi_5936b3` (`group_id`),
CONSTRAINT `issue617_user_fk_5936b3`
FOREIGN KEY (`group_id`)
REFERENCES `issue617_group` (`id`)
ON DELETE SET NULL
) ENGINE=InnoDB CHARACTER SET=\'utf8\';
CREATE TABLE `issue617_group`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARACTER SET=\'utf8\';
';
$this->assertContains($expected, $sql);
$this->updateSchema($builder->getDatabase());
}
示例6: testModiFyTableDoesNotMoveValidatorsOnNonI18nColumns
public function testModiFyTableDoesNotMoveValidatorsOnNonI18nColumns()
{
$schema = <<<EOF
<database name="i18n_behavior_test_0">
<table name="i18n_behavior_test_0">
<column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
<validator column="id">
<rule name="minLength" value="4" message="title must be at least 4 characters !" />
</validator>
<column name="title" type="VARCHAR" />
<behavior name="i18n">
<parameter name="i18n_columns" value="title" />
</behavior>
</table>
</database>
EOF;
$builder = new QuickBuilder();
$builder->setSchema($schema);
$table = $builder->getDatabase()->getTable('i18n_behavior_test_0');
$this->assertEquals(1, count($table->getValidators()));
$i18nTable = $builder->getDatabase()->getTable('i18n_behavior_test_0_i18n');
$this->assertEquals(array(), $i18nTable->getValidators());
}