Commit 2fe7fbf1 authored by Steve Müller's avatar Steve Müller

Merge pull request #2267 from erikjwaxx/pass-correct-sqlite-driver-key

Pass "path" to pdo-sqlite drivers from DriverManager instead of "dbname"
parents df7aeeaa a2cdd8a5
......@@ -259,11 +259,7 @@ final class DriverManager
}
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
}
$params = self::parseDatabaseUrlPath($url, $params);
}
if (isset($url['query'])) {
......@@ -274,4 +270,52 @@ final class DriverManager
return $params;
}
/**
* Parses the given URL and resolves the given connection parameters.
*
* @param array $url The URL parts to evaluate.
* @param array $params The connection parameters to resolve.
*
* @return array The resolved connection parameters.
*/
private static function parseDatabaseUrlPath(array $url, array $params)
{
if (!isset($url['scheme'])) {
$params['dbname'] = $url['path'];
return $params;
}
$url['path'] = substr($url['path'], 1);
if (strpos($url['scheme'], 'sqlite') !== false) {
return self::parseSqliteDatabaseUrlPath($url, $params);
}
$params['dbname'] = $url['path'];
return $params;
}
/**
* Parses the given SQLite URL and resolves the given connection parameters.
*
* @param array $url The SQLite URL parts to evaluate.
* @param array $params The connection parameters to resolve.
*
* @return array The resolved connection parameters.
*/
private static function parseSqliteDatabaseUrlPath(array $url, array $params)
{
if ($url['path'] === ':memory:') {
$params['memory'] = true;
return $params;
}
$params['path'] = $url['path']; // pdo_sqlite driver uses 'path' instead of 'dbname' key
return $params;
}
}
......@@ -151,27 +151,27 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
),
'sqlite relative URL with host' => array(
'sqlite://localhost/foo/dbname.sqlite',
array('dbname' => 'foo/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
array('path' => 'foo/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'sqlite absolute URL with host' => array(
'sqlite://localhost//tmp/dbname.sqlite',
array('dbname' => '/tmp/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
array('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('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('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('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('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'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment