public function execute()
 {
     $configLoader = $this->getConfigLoader(true);
     $dsId = $this->getCurrentDataSourceId();
     $ds = $configLoader->getDataSource($dsId);
     $dsnParser = new DSNParser();
     $dsn = $dsnParser->parse($ds['dsn']);
     $dbName = $dsn->getAttribute('dbname');
     $dsn->removeAttribute('dbname');
     $this->logger->debug("Connection DSN: " . $dsn);
     $pdo = new PDO($dsn, @$ds['user'], @$ds['pass'], @$ds['connection_options']);
     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $q = new DropDatabaseQuery($dbName);
     $q->ifExists();
     // Create query Driver object
     $queryDriver = PDODriverFactory::create($pdo);
     $sql = $q->toSql($queryDriver, new ArgumentArray());
     $this->logger->info($sql);
     if ($pdo->query($sql) === false) {
         list($statusCode, $errorCode, $message) = $pdo->errorInfo();
         $this->logger->error("{$statusCode}:{$errorCode} {$message}");
         return false;
     }
     $this->logger->info('Database dropped successfully.');
 }
 public function testCreateDatabaseQuery()
 {
     $q = new DropDatabaseQuery('test_db');
     $q->ifExists();
     $this->assertDriverQuery(new PgSQLDriver(), $q);
     $this->assertDriverQuery(new MySQLDriver(), $q);
     $q = new CreateDatabaseQuery();
     $q->create('test_db')->characterSet('utf8')->collate('en_US.UTF-8')->owner('postgres')->ctype('en_US.UTF-8')->template('template0')->encoding('UTF8')->tablespace('pg_default')->connectionLimit(3);
     $this->assertSqlStrings($q, [[new MySQLDriver(), "CREATE DATABASE `test_db` CHARACTER SET 'utf8' COLLATE 'en_US.UTF-8'"], [new PgSQLDriver(), 'CREATE DATABASE "test_db" OWNER \'postgres\' TEMPLATE \'template0\' ENCODING \'UTF8\' LC_COLLATE \'en_US.UTF-8\' LC_CTYPE \'en_US.UTF-8\' TABLESPACE \'pg_default\' CONNECTION LIMIT 3']]);
     $this->assertDriverQuery(new PgSQLDriver(), $q);
     $this->assertDriverQuery(new MySQLDriver(), $q);
 }