当前位置: 首页>>代码示例>>PHP>>正文


PHP QuickBuilder::setPlatform方法代码示例

本文整理汇总了PHP中Propel\Generator\Util\QuickBuilder::setPlatform方法的典型用法代码示例。如果您正苦于以下问题:PHP QuickBuilder::setPlatform方法的具体用法?PHP QuickBuilder::setPlatform怎么用?PHP QuickBuilder::setPlatform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Propel\Generator\Util\QuickBuilder的用法示例。


在下文中一共展示了QuickBuilder::setPlatform方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
 }
开发者ID:disider,项目名称:Propel2,代码行数:39,代码来源:MigrationTestCase.php

示例2: 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;
 }
开发者ID:a-melnichuk,项目名称:Movies-Demo,代码行数:33,代码来源:MigrationTestCase.php

示例3: setUp

    public function setUp()
    {
        if (!class_exists('\\ChildTable')) {
            $schema = <<<EOF
<database name="composite_number_range_test">
    <table name="parent_table">
        <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
        <column name="name" type="VARCHAR" required="false" />
    </table>
    <table name="child_table">
        <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
        <column name="name" type="VARCHAR" size="50" required="false" />
        <behavior name="\\APinnecke\\CompositeNumberRange\\CompositeNumberRangeBehavior">
            <parameter name="foreignTable" value="parent_table"/>
        </behavior>
    </table>
</database>
EOF;
            $builder = new QuickBuilder();
            $builder->setPlatform(new MysqlPlatform());
            $builder->setSchema($schema);
            $builder->build('mysql:host=127.0.0.1;dbname=' . getenv('DB_NAME'), getenv('DB_USER'), getenv('DB_PASS'), new MysqlAdapter());
        }
        $this->parent = new \ParentTable();
        $this->parent->setName('test');
        $this->parent->save();
        $this->parent2 = new \ParentTable();
        $this->parent2->setName('test2');
        $this->parent2->save();
        \ChildTableQuery::create()->deleteAll();
        \ParentTableSequenceQuery::create()->deleteAll();
    }
开发者ID:apinnecke,项目名称:composite-number-range-behavior,代码行数:32,代码来源:CompositeNumberRangeBehaviorTest.php

示例4: testGetPlatform

 public function testGetPlatform()
 {
     $builder = new QuickBuilder();
     $builder->setPlatform(new MysqlPlatform());
     $this->assertTrue($builder->getPlatform() instanceof MysqlPlatform);
     $builder = new QuickBuilder();
     $this->assertTrue($builder->getPlatform() instanceof SqlitePlatform);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:8,代码来源:QuickBuilderTest.php

示例5: migrate

 /**
  * Migrates the database.
  *
  * @param string $schema xml schema
  */
 public function migrate($schema)
 {
     $builder = new QuickBuilder();
     $platform = $this->getPlatform();
     $builder->setPlatform($platform);
     $builder->setParser($this->getParser($this->con));
     $builder->getParser()->setPlatform($platform);
     $builder->setSchema($schema);
     $builder->updateDB($this->con);
 }
开发者ID:bondarovich,项目名称:Propel2,代码行数:15,代码来源:PlatformDatabaseBuildTimeBase.php

示例6: 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());
    }
开发者ID:disider,项目名称:Propel2,代码行数:46,代码来源:Issue617Test.php

示例7: 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());
    }
开发者ID:disider,项目名称:Propel2,代码行数:41,代码来源:Issue730Test.php

示例8: 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());
    }
开发者ID:bondarovich,项目名称:Propel2,代码行数:64,代码来源:Issue617Test.php

示例9: testHydrateWithMysqlInvalidDate

    public function testHydrateWithMysqlInvalidDate()
    {
        $schema = <<<EOF
<database name="generated_object_complex_type_test_6">
<table name="complex_column_type_entity_6">
    <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
    <column name="bar1" type="DATE" />
    <column name="bar2" type="TIME"  />
    <column name="bar3" type="TIMESTAMP" />
</table>
</database>
EOF;
        $builder = new QuickBuilder();
        $builder->setSchema($schema);
        $builder->setPlatform(new MysqlPlatform());
        $builder->buildClasses();
        $r = new \ComplexColumnTypeEntity6();
        $r->hydrate(array(123, '0000-00-00', '00:00:00', '0000-00-00 00:00:00'));
        $this->assertNull($r->getBar1());
        $this->assertEquals('00:00:00', $r->getBar2()->format('H:i:s'));
        $this->assertNull($r->getBar3());
    }
开发者ID:norfil,项目名称:Propel2,代码行数:22,代码来源:GeneratedObjectTemporalColumnTypeTest.php


注:本文中的Propel\Generator\Util\QuickBuilder::setPlatform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。