PropelQuickBuilder: getDatabase() does not set the right platform #472

Closed
emagma opened this Issue Sep 21, 2012 · 2 comments

Comments

Projects
None yet
3 participants
@emagma

emagma commented Sep 21, 2012

Hi,
Trying to unit-test a behavior following this guide http://www.propelorm.org/cookbook/testing-your-behaviors.html I met and IDENTITY error at insert time in the sqlite database.
I changed the platform, adapter and dsn for using a mysql database and the issue remains.
I figured out that the getDatabase() method in PropelQuickBuilder does not pass the Platform to the Database object, and then the Dabase object uses the DefaultPlatform wihich returns "IDENTITY" for autoIncrement string.
I fixed my issue by modifying PropelQuickBuilder.php

// line 146
public function getSQL()
{
$this->getDatabase()->setPlatform($this->getPlatform());
return $this->getPlatform()->getAddTablesDDL($this->getDatabase());
}

Does anyone met this issue too ?

@oojacoboo

This comment has been minimized.

Show comment
Hide comment
@oojacoboo

oojacoboo Sep 29, 2012

Hey, this is what I'm doing...

\Propel::setConnection("propel", \Propel::getConnection(SqliteSetup::$databaseName));

This makes my test db defined in the config my propel default and then all my models will work with the default connection. As for init the sqlite instance...

public static $databaseName = "test"; //where test is the name of the db in the config and schema
$this->con = \Propel::getConnection(self::$databaseName);

/**
 * Builds out the SQLite Database into memory based on the schema we pass into it
 * @param \PropelPDO $connection
 */
public function buildSqliteDb(\PropelPDO $connection = null) {
    if(!$connection)
        $connection = $this->con;

    $tables = $this->getTables();

    //if we don't have these tables in the array, build the tables
    if(!in_array("company", $tables) && !in_array("zip_code", $tables)) {
        $builder = new PropelQuickBuilderModified();

        $config = $builder->getConfig();
        $builder->setConfig($config);

        $schema = $this->getSchema();
        $builder->setSchema($schema);

        $builder->buildSQL($connection);
    }
}

Hope that helps get you somewhere.

Hey, this is what I'm doing...

\Propel::setConnection("propel", \Propel::getConnection(SqliteSetup::$databaseName));

This makes my test db defined in the config my propel default and then all my models will work with the default connection. As for init the sqlite instance...

public static $databaseName = "test"; //where test is the name of the db in the config and schema
$this->con = \Propel::getConnection(self::$databaseName);

/**
 * Builds out the SQLite Database into memory based on the schema we pass into it
 * @param \PropelPDO $connection
 */
public function buildSqliteDb(\PropelPDO $connection = null) {
    if(!$connection)
        $connection = $this->con;

    $tables = $this->getTables();

    //if we don't have these tables in the array, build the tables
    if(!in_array("company", $tables) && !in_array("zip_code", $tables)) {
        $builder = new PropelQuickBuilderModified();

        $config = $builder->getConfig();
        $builder->setConfig($config);

        $schema = $this->getSchema();
        $builder->setSchema($schema);

        $builder->buildSQL($connection);
    }
}

Hope that helps get you somewhere.

@willdurand

This comment has been minimized.

Show comment
Hide comment
@willdurand

willdurand Oct 19, 2012

Member

Yes, you just need to update Propel. It's fixed now.

Le 21 sept. 2012 à 22:41, emagma notifications@github.com a écrit :

Hi,
Trying to unit-test a behavior following this guide http://www.propelorm.org/cookbook/testing-your-behaviors.html I met and IDENTITY error at insert time in the sqlite database.
I changed the platform, adapter and dsn for using a mysql database and the issue remains.
I figured out that the getDatabase() method in PropelQuickBuilder does not pass the Platform to the Database object, and then the Dabase object uses the DefaultPlatform wihich returns "IDENTITY" for autoIncrement string.
I fixed my issue by modifying PropelQuickBuilder.php

// line 146
public function getSQL()
{
$this->getDatabase()->setPlatform($this->getPlatform());
return $this->getPlatform()->getAddTablesDDL($this->getDatabase());
}

Does anyone met this issue too ?


Reply to this email directly or view it on GitHub.

Member

willdurand commented Oct 19, 2012

Yes, you just need to update Propel. It's fixed now.

Le 21 sept. 2012 à 22:41, emagma notifications@github.com a écrit :

Hi,
Trying to unit-test a behavior following this guide http://www.propelorm.org/cookbook/testing-your-behaviors.html I met and IDENTITY error at insert time in the sqlite database.
I changed the platform, adapter and dsn for using a mysql database and the issue remains.
I figured out that the getDatabase() method in PropelQuickBuilder does not pass the Platform to the Database object, and then the Dabase object uses the DefaultPlatform wihich returns "IDENTITY" for autoIncrement string.
I fixed my issue by modifying PropelQuickBuilder.php

// line 146
public function getSQL()
{
$this->getDatabase()->setPlatform($this->getPlatform());
return $this->getPlatform()->getAddTablesDDL($this->getDatabase());
}

Does anyone met this issue too ?


Reply to this email directly or view it on GitHub.

@willdurand willdurand closed this Nov 22, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment