/** * @throws \RuntimeException * @return string */ public function getQuery() { $config = $this->connection->getParams(); $driver = $config['driver']; if (!isset($this->configClasses[$driver])) { throw new \RuntimeException('Driver "%s" not found'); } /** @var PdoMysql $className */ $className = $this->configClasses[$driver]; return $className::getPlainSql(); }
/** * {@inheritdoc} */ public function getDatabase(\Doctrine\DBAL\Connection $conn) { $params = $conn->getParams(); if (isset($params['dbname'])) { return $params['dbname']; } return null; }
/** * Add a connection to the pool * * @param Connection $connection */ public function add(Connection $connection) { $key = md5(serialize($connection->getParams())); if (isset($this->connections[$key]) && $connection !== $this->connections[$key]) { throw new \InvalidArgumentException('Expects a non registered connection.'); } $this->connections[$key] = $connection; }
public function getDatabase(\Doctrine\DBAL\Connection $conn) { $params = $conn->getParams(); if (isset($params['dbname'])) { return $params['dbname']; } return $conn->query('SELECT DATABASE()')->fetchColumn(); }
/** * @param Connection $conn * @param string $generatorTableName */ public function __construct(Connection $conn, $generatorTableName = 'sequences') { $params = $conn->getParams(); if ($params['driver'] == 'pdo_sqlite') { throw new \Doctrine\DBAL\DBALException("Cannot use TableGenerator with SQLite."); } $this->conn = DriverManager::getConnection($params, $conn->getConfiguration(), $conn->getEventManager()); $this->generatorTableName = $generatorTableName; }
protected function dropDatabaseForConnection(Connection $connection, OutputInterface $output) { $params = $connection->getParams(); $name = isset($params['path']) ? $params['path'] : $params['dbname']; try { $connection->getSchemaManager()->dropDatabase($name); $output->writeln(sprintf('<info>Dropped database for connection named <comment>%s</comment></info>', $name)); } catch (\Exception $e) { $output->writeln(sprintf('<error>Could not drop database for connection named <comment>%s</comment></error>', $name)); $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); } }
/** * Create Newscoop Database * * @param Connection $connection */ public function createNewscoopDatabase($connection) { $params = $connection->getParams(); if (isset($params['master'])) { $params = $params['master']; } unset($params['dbname']); $tmpConnection = DriverManager::getConnection($params); $name = $tmpConnection->getDatabasePlatform()->quoteSingleIdentifier($connection->getDatabase()); $tmpConnection->getSchemaManager()->createDatabase($name); unset($tmpConnection); $this->logger->addInfo('Database ' . $name . ' created'); }
/** * @return string */ public function getPanel() { if (empty($this->queries)) { return ''; } $connParams = $this->connection->getParams(); if ($connParams['driver'] === 'pdo_sqlite' && isset($connParams['path'])) { $host = 'path: ' . basename($connParams['path']); } else { $host = sprintf('host: %s%s/%s', $this->connection->getHost(), ($p = $this->connection->getPort()) ? ':' . $p : '', $this->connection->getDatabase()); } return $this->renderStyles() . sprintf('<h1>Queries: %s %s, %s</h1>', count($this->queries), $this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '', $host) . '<div class="nette-inner tracy-inner nette-Doctrine2Panel">' . implode('<br>', array_filter([$this->renderPanelCacheStatistics(), $this->renderPanelQueries()])) . '</div>'; }
public function __construct(Connection $db = null, $tableName, $tableAlias = null, $tablesAliases = null) { $this->db = $db; $this->tableName = $tableName; $this->tableAlias = $tableAlias; $this->tablesAliases = $tablesAliases; $this->table = $this->tableAlias !== null ? $this->tableAlias : "`{$this->tableName}`"; if ($db !== null && $db->getParams()['driver'] !== 'pdo_sqlite') { $tableColumns = $db->executeQuery("DESCRIBE {$tableName}")->fetchAll(\PDO::FETCH_COLUMN); $this->isTimestampable = count(array_intersect(['created_at', 'updated_at'], $tableColumns)) == 2; $this->isSoftdeletable = in_array('deleted_at', $tableColumns); } }
/** * Creates the configuration for this schema. * * @return \Doctrine\DBAL\Schema\SchemaConfig */ public function createSchemaConfig() { $schemaConfig = new SchemaConfig(); $schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength()); $searchPaths = $this->getSchemaSearchPaths(); if (isset($searchPaths[0])) { $schemaConfig->setName($searchPaths[0]); } $params = $this->_conn->getParams(); if (isset($params['defaultTableOptions'])) { $schemaConfig->setDefaultTableOptions($params['defaultTableOptions']); } return $schemaConfig; }
protected function createDatabaseForConnection(Connection $connection, OutputInterface $output) { $params = $connection->getParams(); $name = isset($params['path']) ? $params['path'] : $params['dbname']; unset($params['dbname']); $tmpConnection = \Doctrine\DBAL\DriverManager::getConnection($params); try { $tmpConnection->getSchemaManager()->createDatabase($name); $output->writeln(sprintf('<info>Created database for connection named <comment>%s</comment></info>', $name)); } catch (\Exception $e) { $output->writeln(sprintf('<error>Could not create database for connection named <comment>%s</comment></error>', $name)); $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); } $tmpConnection->close(); }
/** * @param \Doctrine\DBAL\Connection $conn * * @throws \Doctrine\DBAL\Sharding\ShardingException */ public function __construct(Connection $conn) { $this->conn = $conn; $params = $conn->getParams(); if (!isset($params['sharding']['federationName'])) { throw ShardingException::missingDefaultFederationName(); } if (!isset($params['sharding']['distributionKey'])) { throw ShardingException::missingDefaultDistributionKey(); } if (!isset($params['sharding']['distributionType'])) { throw ShardingException::missingDistributionType(); } $this->federationName = $params['sharding']['federationName']; $this->distributionKey = $params['sharding']['distributionKey']; $this->distributionType = $params['sharding']['distributionType']; $this->filteringEnabled = isset($params['sharding']['filteringEnabled']) ? (bool) $params['sharding']['filteringEnabled'] : false; }
/** * Connect using the deprecated mysql extension. * * This method is often required when working with some legacy admin pages. * * Most people won't need this, but it is here if they do. * * @param array $params an array of mysql connection optons that match the PDO dsn. * If you do not specify any parameters. it will use the * <code>apps.store.database.default</code> settings. * @return resource an ext/mysql resource */ public function mysql_connect($params = null) { if (!extension_loaded('mysql')) { throw new \RuntimeException('The mysql extension must be installed to use this method.'); } $defaults = $this->conn->getParams(); $params = array_merge($defaults, (array) $params); $link = mysql_connect($params['host'], $params['user'], $params['password'], true); if (is_resource($link) && mysql_select_db($params['dbname'])) { if (!isset($params['charset']) && !empty($params['charset'])) { mysql_set_charset($params['charset']); } $this->link = $link; return $this->link; } else { throw new RuntimeException(mysql_error(), mysql_errno()); } }
private function getServerVersion() { $params = $this->con->getParams(); // Explicit platform version requested (supersedes auto-detection), so we respect it. if (isset($params['serverVersion'])) { return $params['serverVersion']; } $wrappedConnection = $this->con->getWrappedConnection(); if ($wrappedConnection instanceof ServerInfoAwareConnection) { return $wrappedConnection->getServerVersion(); } // Support DBAL 2.4 by accessing it directly when using PDO PgSQL if ($wrappedConnection instanceof \PDO) { return $wrappedConnection->getAttribute(\PDO::ATTR_SERVER_VERSION); } // If we cannot guess the version, the empty string will mean we won't use the code for newer versions when doing version checks. return ''; }
public function __construct(Connection $conn) { $this->pdo = $conn; $params = $conn->getParams(); $driver = $params['driver']; $commands = []; switch ($driver) { case 'pdo_mysql': $commands[] = 'SET SQL_MODE=ANSI_QUOTES'; break; case 'pdo_sqlite': break; case 'pdo_pgsql': break; case 'pdo_oci': break; case 'pdo_sqlsrv': $commands[] = 'SET QUOTED_IDENTIFIER ON'; break; } foreach ($commands as $comm) { $this->pdo->exec($comm); } }
private function getDbMockBuilder(Connection $db) { return $this->getMockBuilder('\\Doctrine\\DBAL\\Connection')->setConstructorArgs([$db->getParams(), $db->getDriver(), $db->getConfiguration(), $db->getEventManager()])->enableOriginalConstructor(); }
/** * {@inheritdoc} */ public function getDatabase(Connection $conn) { $params = $conn->getParams(); return $params['user']; }
/** * {@inheritdoc} * @param \Doctrine\DBAL\Connection $connection * * @throws \umi\dbal\exception\RuntimeException */ public function initConnection(Connection $connection) { /** @var $pdo PDO */ $pdo = $connection->getWrappedConnection(); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $params = $connection->getParams(); if (!isset($params['charset'])) { throw new RuntimeException("No connection charset specified"); } $pdo->exec('SET NAMES ' . $pdo->quote($params['charset'])); }
/** * {@inheritdoc} */ public function getDatabase(\Doctrine\DBAL\Connection $conn) { $params = $conn->getParams(); return isset($params['dbname']) ? $params['dbname'] : $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn(); }
/** * {@inheritdoc} */ public function getParams() { return $this->activeShardId ? $this->connections[$this->activeShardId] : parent::getParams(); }
/** * @todo make the mysql bit dynamic * @param Connection $connection */ private function formatDSN(Connection $connection) { $driver_name = $this->getPropelDriverName($connection->getDriver()); if ($connection->getDriver()->getName() == 'pdo_sqlite') { return sprintf('%s://hack.nl/%s', $driver_name, $connection->getDatabase()); } $params = $connection->getParams(); return sprintf('%s://%s:%s@%s%s/%s?encoding=%s', $driver_name, $connection->getUsername(), $connection->getPassword(), $connection->getHost(), $connection->getPort() ? ':' . $connection->getPort() : '', $connection->getDatabase(), isset($params['charset']) ? $params['charset'] : 'utf8'); }
public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO() { $params['pdo'] = new \stdClass(); $driverMock = $this->getMock('Doctrine\\DBAL\\Driver'); $conn = new Connection($params, $driverMock); $this->assertArrayNotHasKey('pdo', $conn->getParams(), "Connection is maintaining additional reference to the PDO connection"); }
public function getDatabase(\Doctrine\DBAL\Connection $conn) { $params = $conn->getParams(); return isset($params['path']) ? $params['path'] : null; }
private function connectToDatabase(Connection $db, $databaseName) { $db->close(); $db->__construct(['dbname' => $databaseName] + $db->getParams(), $db->getDriver(), $db->getConfiguration(), $db->getEventManager()); $db->connect(); }
protected function getTableName($name) { return sprintf('%s_%s', $this->connection->getParams()['prefix'], $name); }
public function getDatabase(Connection $conn) { return $conn->getParams()["dbname"]; }
/** * Restore the backup for the given connection / hash * * @param \Doctrine\DBAL\Connection $connection * @param string $hash */ public function restoreBackup(Connection $connection, $hash) { $platform = $connection->getDatabasePlatform(); $filename = $this->getBackupFile($hash); $database = $connection->getDatabase(); $params = $connection->getParams(); $platformName = $platform->getName(); $this->getPlatformBackup($platformName)->restore($database, $filename, $params); }
/** * @param ConnectionInterface $conn * * @return mixed */ public function getDatabase(ConnectionInterface $conn) { $params = $conn->getParams(); return $params['dbname']; }
public function getDatabase(\Doctrine\DBAL\Connection $conn) { $params = $conn->getParams(); return $params['user']; }
/** * @param Connection $connection * * @return string */ protected function getPrefix(Connection $connection) { $params = $connection->getParams(); return array_get($params, 'prefix'); }