3.0 Some Fixes for MSSQL (#438)
* Fix DatabaseCreateCommand for Mssql * parseDbName for Mssql * Use a simple connection for drop Else MSSQL will say ressource is in use * encoding
This commit is contained in:
parent
c4359c39b6
commit
5ea4110b62
|
@ -384,10 +384,10 @@ abstract class AbstractCommand extends ContainerAwareCommand
|
|||
*/
|
||||
protected function parseDbName($dsn)
|
||||
{
|
||||
preg_match('#dbname=([a-zA-Z0-9\_]+)#', $dsn, $matches);
|
||||
preg_match('#(dbname|Database)=([a-zA-Z0-9\_]+)#', $dsn, $matches);
|
||||
|
||||
if (isset($matches[1])) {
|
||||
return $matches[1];
|
||||
if (isset($matches[2])) {
|
||||
return $matches[2];
|
||||
}
|
||||
|
||||
// e.g. SQLite
|
||||
|
|
|
@ -83,7 +83,7 @@ class DatabaseCreateCommand extends AbstractCommand
|
|||
$dbName = $this->parseDbName($config['dsn']);
|
||||
|
||||
$config['dsn'] = preg_replace(
|
||||
'#;?dbname='.$dbName.'#',
|
||||
'#;?(dbname|Database)='.$dbName.'#',
|
||||
'',
|
||||
$config['dsn']
|
||||
);
|
||||
|
|
|
@ -14,6 +14,7 @@ use Propel\Runtime\Propel;
|
|||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Propel\Runtime\Connection\ConnectionManagerSingle;
|
||||
|
||||
/**
|
||||
* DatabaseDropCommand class.
|
||||
|
@ -79,9 +80,41 @@ EOT
|
|||
$query = 'DROP DATABASE '. $dbName .';';
|
||||
}
|
||||
|
||||
|
||||
$manager = new ConnectionManagerSingle();
|
||||
$manager->setConfiguration($this->getTemporaryConfiguration($config));
|
||||
|
||||
$serviceContainer = Propel::getServiceContainer();
|
||||
$serviceContainer->setAdapterClass($connectionName, $config['adapter']);
|
||||
$serviceContainer->setConnectionManager($connectionName, $manager);
|
||||
|
||||
$connection = Propel::getConnection($connectionName);
|
||||
|
||||
$statement = $connection->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
$output->writeln(sprintf('<info>Database <comment>%s</comment> has been dropped.</info>', $dbName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a temporary configuration to connect to the database in order
|
||||
* to create a given database. This idea comes from Doctrine1.
|
||||
*
|
||||
* @see https://github.com/doctrine/doctrine1/blob/master/lib/Doctrine/Connection.php#L1491
|
||||
*
|
||||
* @param array $config A Propel connection configuration.
|
||||
* @return array
|
||||
*/
|
||||
private function getTemporaryConfiguration($config)
|
||||
{
|
||||
$dbName = $this->parseDbName($config['dsn']);
|
||||
|
||||
$config['dsn'] = preg_replace(
|
||||
'#;?(dbname|Database)='.$dbName.'#',
|
||||
'',
|
||||
$config['dsn']
|
||||
);
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,6 +161,7 @@ class Configuration extends PropelConfiguration
|
|||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->booleanNode('ATTR_EMULATE_PREPARES')->defaultFalse()->end()
|
||||
->scalarNode('SQLSRV_ATTR_ENCODING')->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('model_paths')
|
||||
|
|
Loading…
Reference in a new issue