Skip to content
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

Treat SQLite Connection URLs Differently in DriverManager #813

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/Doctrine/DBAL/DriverManager.php
Expand Up @@ -258,10 +258,16 @@ private static function parseDatabaseUrl(array $params)
}

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
if (isset($url['scheme']) && strpos($url['scheme'], 'sqlite') !== false) {
// sqlite::memory: OR :sqlite:///:memory:
if (':memory:' === $url['path'] || substr($url['path'], 1) === ':memory:') {
$params['memory'] = true;
$params['dbname'] = ':memory:';
} else {
$params['dbname'] = $params['path'] = substr($url['path'], 1);
}
} else {
$params['dbname'] = substr($url['path'], 1); // strip the leading slash from the URL
$params['dbname'] = ltrim($url['path'], '/'); // strip the leading slash from the URL
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Doctrine/Tests/DBAL/DriverManagerTest.php
Expand Up @@ -151,27 +151,27 @@ public function databaseUrls()
),
'sqlite relative URL with host' => array(
'sqlite://localhost/foo/dbname.sqlite',
array('dbname' => 'foo/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
array('dbname' => 'foo/dbname.sqlite', 'path' => 'foo/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use different data-provider entries: don't change the existing ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original data provider entries test things that don't matter: dbname does nothing for the SQLite driver. I can create new data provider entries if you'd like, but it seemed that changing the existing ones to test something that mattered made more sense.

),
'sqlite absolute URL with host' => array(
'sqlite://localhost//tmp/dbname.sqlite',
array('dbname' => '/tmp/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
array('dbname' => '/tmp/dbname.sqlite', 'path' => '/tmp/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'sqlite relative URL without host' => array(
'sqlite:///foo/dbname.sqlite',
array('dbname' => 'foo/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
array('dbname' => 'foo/dbname.sqlite', 'path' => 'foo/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'sqlite absolute URL without host' => array(
'sqlite:////tmp/dbname.sqlite',
array('dbname' => '/tmp/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
array('dbname' => '/tmp/dbname.sqlite', 'path' => '/tmp/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'sqlite memory' => array(
'sqlite:///:memory:',
array('dbname' => ':memory:', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
array('dbname' => ':memory:', 'memory' => true, 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'sqlite memory with host' => array(
'sqlite://localhost/:memory:',
array('dbname' => ':memory:', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
array('dbname' => ':memory:', 'memory' => true, 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'params parsed from URL override individual params' => array(
array('url' => 'mysql://foo:bar@localhost/baz', 'password' => 'lulz'),
Expand Down Expand Up @@ -199,4 +199,4 @@ public function databaseUrls()
),
);
}
}
}