-
-
Notifications
You must be signed in to change notification settings - Fork 455
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
create:database fails, when dbname is set via URL #434
create:database fails, when dbname is set via URL #434
Conversation
OK, easier than expected. The |
ping @guilhermeblanco (because you are the last one who merged a PR 😉 ) Can you have a look? |
Tests ? |
There is still the dbname within the url. Need to get rid of this in CreateDatabaseCommand, because else it still tries to connect to the server with this dbname, which probably doesn't exists yet.
@kimhemsoe Hi The issue the PR tries to solve doesn't appear with SQLite, thus I cannot test it with the current setup. When you try to connect to a SQLite-Database, that doesn't exists, The solution would be to extend the tests to use a database server (MySQL, Postgresql, ..) instead of SQLite... |
create:database fails, when dbname is set via URL
👎 For this without proper test. I got an error when using SQLite. // Need to get rid of _every_ occurrence of dbname from connection configuration and we have already extracted all relevant info from url
unset($params['dbname'], $params['path'], $params['url']);
$tmpConnection = DriverManager::getConnection($params);
$shouldNotCreateDatabase = $ifNotExists && in_array($name, $tmpConnection->getSchemaManager()->listDatabases());
// Only quote if we don't have a path
if (!isset($params['path'])) {
$name = $tmpConnection->getDatabasePlatform()->quoteSingleIdentifier($name);
} So the database name will ALWAYS be quoted and the generated name is wrong. Without your change, I got the database name of SQLite (which is a path):
With your change:
Which is obviously wrong. So I can't create a database anymore. Doctrine keeps telling me:
Edit: |
Because of a bad change, SQLite database cannot be created anymore. :arrow_right: doctrine/DoctrineBundle#434
Hi @j0k3r However:
So why is it not needed to quote the databasoe name from the URL anymore?! Maybe somebody can explain me. My very very cautious gues is, that this was a fix for a different issue, that only accidentally solved the path issue for SQLite. Remember: Now database names for other drivers aren't quoted too, but this is rarely a problem, so probably nobody noticed. Regarding a solution: if (isset($url['path'])) {
if (!isset($url['scheme']) || (strpos($url['scheme'], 'sqlite') !== false && $url['path'] == ':memory:')) {
$params['dbname'] = $url['path']; // if the URL was just "sqlite::memory:", which parses to scheme and path only
} else {
$params['dbname'] = substr($url['path'], 1); // strip the leading slash from the URL
}
} So either one can test, wether or not |
I agree about every thing @kingcrunch :) And the commit (20a3598) that add this check doesn't really describe what it should fix and why :
So we don't really know if this commit try to fix something related to SQLite or any other platform. This mean, we can't really rely on verifying what driver is used to quote database name. And since there is no test at all on that command, it's hard to rewrite the condition without side effects. And this PR affect SQLite because I guess Doctrine is trying to create a file with this name Instead of trying to rethink the way we should perform this verification, I think the solution in ##483 might be a good solution for you and me |
Hi @MarcelHernandez Please read the comments (and see #483 ) |
First of all: This may be a DBAL-issue.
However, when I specify the database connection via URL like
mysql://foo:bar@localhost/dbname
the commanddoctrine:data:create
fails with an exception. I was able to extract the original exception from the driver (see below). It works, when I omitdbname
from the URL and set it directly with thedbname
configuration key.