Invalid catalog name: 1046 No database selected #177

Open
tonivdv opened this Issue Sep 3, 2012 · 8 comments

Comments

Projects
None yet
5 participants

tonivdv commented Sep 3, 2012

Hello,

I'm trying to make a test with a database applying the instructions from the propel site but I always get the error Invalid catalog name: 1046 No database selected!

I debugged the code a little bit and it works when I comment following part of the code:

protected static function runCommand($command)
{
    $command = sprintf('%s --quiet', $command);

    return self::getApplication();//->run(new \Symfony\Component\Console\Input\StringInput($command));
}

The test I'm trying to run is:

class ATest extends DatabaseWebTestCase {

  /**
   * @test
   */
  public function test() {

    $test = new \Something\Model\Test();
    $test 
      ->setValue("test")
      ->save();
  }

Any idea's if this is an issue, or if I'm doing something completely wrong?

Thx in advance

tonivdv commented Sep 3, 2012

Hello,

I found the issue, well my issue :p ...

I added an extra command to run in the setUpBeforeClass:

public static function setUpBeforeClass() {
    \Propel::disableInstancePooling();

    self::runCommand('propel:database:create');
    self::runCommand('propel:build --insert-sql');
  }

The propel:database:create is the one who triggered the issue ... I removed it and will launch it outside of the test.

But could someone explain me the reason? What is so different with that execution?

Owner

willdurand commented Sep 10, 2012

Which database vendor do you use in your tests? SQLite doesn't need to create a database for example, and we use a trick to create new databases (but it's a trick and it doesn't work well with all db vendors).

tonivdv commented Sep 10, 2012

Hello William,

It was MySql 5.1.x.

Regards

Owner

willdurand commented Sep 10, 2012

Ah, then there is another issue :/

On Mon, Sep 10, 2012 at 10:39 AM, tonivdv notifications@github.com wrote:

Hello William,

It was MySql 5.1.x.

Regards


Reply to this email directly or view it on GitHubhttps://github.com/propelorm/PropelBundle/issues/177#issuecomment-8417191.

tonivdv commented Sep 10, 2012

So if I understand it correctly it should work like this:

public static function setUpBeforeClass() {
        \Propel::disableInstancePooling();

    self::runCommand('propel:database:create');
    self::runCommand('propel:build --insert-sql');
}

But due to "another issue" it isn't?

I have a similar issue, This is my setUp :

$this->runConsole("propel:database:drop", array("--force" => true));
$this->runConsole("propel:database:create");
$this->runConsole("propel:build", array("--insert-sql" => true));
$this->runConsole("propel:fixtures:load");

The 3 firsts commands are executed but the 4th is failing :

Use connection named default in test environment.
Database ******* has been dropped.
Use connection named default in test environment.
Database ******* has been created.
>>         FOSUserBundle    Generated model classes from schema.xml
>>  *****Bundle    Generated model classes from schema.xml
>>  *****Bundle    Generated model classes from schema.xml
>>  *****Bundle    Generated model classes from schema.xml
>>  *****Bundle    Generated model classes from schema.xml
>>  *****Bundle    Generated model classes from schema.xml
>>  File+    *****/app/cache/test/sql/sqldb.map
>>  File+    *****/app/cache/test/sql/default.sql
1 SQL file has been generated.
Use connection named default in test environment.
All SQL statements have been inserted.
Use connection named default in test environment.
No SQL fixtures found.
No XML fixtures found.


  [Propel] Exception

  Unable to execute DELETE ALL statement [DELETE FROM `*****`] [wrapped: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected]

But, when I run the task manually, it work fine. I'm a bit confused.

@willdurand : 1) Do you have any idea how I can fix it ? I tryed to add th "propel.database.url" propertie in my config but it still not work. 2) Do you have a doc entry for sqlite / memory settings ? 3) Can you add the Bug label to the issue ?

Hi! I struck this today. How can I work it out? Anythink I can help with?

Solved this problem by the following workaround

to run

\Propel::setConfiguration($this->getContainer()->get('propel.configuration'));
\Propel::initialize();

before

\Propel::getConnection();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment