-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added parameter default_dbname
to pdo_pgsql driver, used to override the default database
#2284
Added parameter default_dbname
to pdo_pgsql driver, used to override the default database
#2284
Conversation
// as it is certainly present in every server setup. | ||
$dsn .= 'dbname=postgres' . ' '; | ||
} elseif (isset($params['default_dbname'])) { | ||
$dsn .= 'dbname=' . $params['default_dbname'] . ' '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should still connect to postgres
if the parameter is not set as we will have errors again otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, postgres is the default if dont provide one. Ive tested it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kimhemsoe that is not true. It defaults to a database that is named equally to the connection user. This is what originally caused trouble. See PHP issue and doctrine/DoctrineBundle#402
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deeky666 @kimhemsoe Ah yes, I was wrong - you can verify this using:
PDO
php -r "$pdo = new PDO('pgsql:host=localhost port=5432', 'your_username', 'your_password');"
If no db matching your username exists, you get:
PDOException: SQLSTATE[08006] [7] FATAL: database "your_username" does not exist in Command line code on line 1
Call Stack:
0.0000 125096 1. {main}() Command line code:0
0.0000 125520 2. PDO->__construct() Command line code:1
pgsql
php -r "$conn = pg_connect('host=localhost port=5432 user=your_username password=your_password');"
If no db matching your username exists, you get:
Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: database "your_username" does not exist in Command line code on line 1
Call Stack:
0.0000 124792 1. {main}() Command line code:0
0.0000 124928 2. pg_connect() Command line code:1
@@ -20,6 +21,26 @@ protected function setUp() | |||
} | |||
} | |||
|
|||
public function testDefaultDatabaseOption() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please adjust this test case to the following to cover all variants?
/**
* @dataProvider getDatabaseParameter
*/
public function testDatabaseParameter($databaseName, $defaultDatabaseName, $expectedDatabaseName)
{
$params = $this->_conn->getParams();
$params['dbname'] = $databaseName;
$params['default_dbname'] = $defaultDatabaseName;
$connection = new Connection(
$params,
$this->_conn->getDriver(),
$this->_conn->getConfiguration(),
$this->_conn->getEventManager()
);
$this->assertSame(
$expectedDatabaseName,
$this->driver->getDatabase($connection)
);
}
public function getDatabaseParameter()
{
$params = TestUtil::getConnection()->getParams();
$realDatabaseName = $params['dbname'];
$dummyDatabaseName = $realDatabaseName . 'a';
return array(
// dbname, default_dbname, expected
array($realDatabaseName, null, $realDatabaseName),
array($realDatabaseName, $dummyDatabaseName, $realDatabaseName),
array(null, $realDatabaseName, $realDatabaseName),
array(null, null, $this->getDatabaseNameForConnectionWithoutDatabaseNameParameter()),
);
}
ba950e4
to
f471a0f
Compare
@@ -21,6 +23,43 @@ protected function setUp() | |||
} | |||
|
|||
/** | |||
@dataProvider getDatabaseParameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kimhemsoe this looks like borken indentation. Can you fix this? After that I'll merge.
@deeky666 ping |
Added parameter "default_dbname" to pdo_pgsql driver which can be use…
@kimhemsoe merged, thanks. |
@deeky666 Did you merge into 2.5 too? |
@kimhemsoe no. It is actually an improvement, no? |
default_dbname
to pdo_pgsql driver, used to override the default database
No description provided.