/** * gets database name * * @param \Dive\Connection\Connection $conn * @throws DriverException * @return string */ public function getDatabaseName(Connection $conn) { $parsed = parse_url($conn->getDsn()); if (isset($parsed['path'])) { return basename($parsed['path']); } throw new DriverException('Could not get database name'); }
/** * @dataProvider provideGetScheme * @param string $dsn * @param string $expected * @param bool $throwsException */ public function testGetScheme($dsn, $expected, $throwsException) { /** @var \Dive\Connection\Driver\DriverInterface $driver */ $driver = $this->getMockForAbstractClass('\\Dive\\Connection\\Driver\\DriverInterface'); if ($throwsException) { $this->setExpectedException('\\InvalidArgumentException'); } $conn = new Connection($driver, $dsn); $this->assertEquals($expected, $conn->getScheme()); }
/** * constructor * * @param Connection $conn * @param DataTypeMapper $dataTypeMapper * @param string $recordNamespace */ public function __construct(Connection $conn, DataTypeMapper $dataTypeMapper = null, $recordNamespace = '\\') { $this->conn = $conn; $this->recordNamespace = $recordNamespace; if ($dataTypeMapper === null) { // TODO potential security issue!! $class = '\\Dive\\Schema\\DataTypeMapper\\' . ucfirst($conn->getScheme()) . 'DataTypeMapper'; $dataTypeMapper = new $class(); } $this->dataTypeMapper = $dataTypeMapper; }
/** * @return Event\EventDispatcherInterface */ public function getEventDispatcher() { return $this->conn->getEventDispatcher(); }
/** * @return string[] */ protected function getDropTableStatements() { $sql = 'DROP TABLE ' . ($this->preventErrors ? ' IF EXISTS' : '') . ' ' . $this->conn->quoteIdentifier($this->tableName); return array($sql); }
/** * Creates database connection instance * * @param array $database must have keys: dsn, user, password * @return \Dive\Connection\Connection */ public static function createDatabaseConnection(array $database) { $dsn = $database['dsn']; if (!isset(self::$connectionPoolTestClass[$dsn])) { $scheme = self::getSchemeFromDsn($dsn); /** @var \Dive\Connection\Driver\DriverInterface $driver */ $driver = self::createInstance('Connection\\Driver', 'Driver', $scheme); $conn = new Connection($driver, $dsn, $database['user'], $database['password']); $eventDispatcher = $conn->getEventDispatcher(); $eventDispatcher->addListener(Connection::EVENT_POST_INSERT, array(__CLASS__, 'addToDatasetRegistry')); $dbInit = new DbInit($conn, self::getSchema()); $dbInit->init(); self::$connectionPoolTestClass[$dsn] = $conn; } return self::$connectionPoolTestClass[$dsn]; }
/** * (re)create view * * @param PlatformInterface $platform * @param string $viewName */ private function createView(PlatformInterface $platform, $viewName) { $sqlStatement = $this->schema->getViewStatement($viewName); $sql = $platform->getCreateViewSql($viewName, $sqlStatement); $this->conn->exec($sql); }
/** * gets database name * * @param \Dive\Connection\Connection $conn * @throws DriverException * @return string */ public function getDatabaseName(Connection $conn) { $result = $conn->query('SELECT DATABASE()', array(), \PDO::FETCH_COLUMN); return $result[0]; }