getDriver() public method

Gets the DBAL driver instance.
public getDriver ( ) : Doctrine\DBAL\Driver
return Doctrine\DBAL\Driver
 public function getDsn()
 {
     $driver = $this->connection->getDriver()->getName();
     $user = $this->connection->getUsername();
     $pass = $this->connection->getPassword();
     $host = $this->connection->getHost();
     $db = $this->connection->getDatabase();
     return "{$driver}://{$user}:{$pass}@{$host}/{$db}";
 }
Ejemplo n.º 2
0
 /**
  * Create a new connection wrapping a Doctrine DBAL connection.
  * 
  * @param DoctrineConnection $conn 
  * @param array<string, mixed> $options
  */
 public function __construct(DoctrineConnection $conn, array $options = [])
 {
     $this->conn = $conn;
     $this->options = $options;
     switch ($conn->getDriver()->getName()) {
         case 'pdo_sqlite':
             $this->driverName = DB::DRIVER_SQLITE;
             $this->initializeSqlite();
             break;
         case 'pdo_mysql':
         case 'drizzle_pdo_mysql':
         case 'mysqli':
             $this->driverName = DB::DRIVER_MYSQL;
             break;
         case 'pdo_pgsql':
             $this->driverName = DB::DRIVER_POSTGRESQL;
             break;
         case 'pdo_oci':
         case 'oci8':
             $this->driverName = DB::DRIVER_ORACLE;
             break;
         case 'pdo_sqlsrv':
         case 'sqlsrv':
             $this->driverName = DB::DRIVER_MSSQL;
             break;
         case 'ibm_db2':
             $this->driverName = DB::DRIVER_DB2;
             break;
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string                    $name
  * @param \Doctrine\DBAL\Connection $connection
  */
 public static function addConnection($name, \Doctrine\DBAL\Connection $connection)
 {
     if ($connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOMySql\Driver) {
         static::$connections[$name] = $connection;
     } else {
         throw new ErrorException("Database connection must use a \\Doctrine\\DBAL\\Driver\\PDOMySql\\Driver Driver");
     }
 }
Ejemplo n.º 4
0
 public function run($sourceFile, Connection $dbConn)
 {
     $driverType = $dbConn->getDriver()->getName();
     $sqlite = preg_match('/sqlite/i', $driverType);
     $objPHPExcel = \PHPExcel_IOFactory::load($sourceFile);
     $dbConn->exec($sqlite ? 'DELETE FROM songs' : 'TRUNCATE TABLE songs');
     // empty table - reset autoincrement if it has one
     $iterator = $objPHPExcel->getSheet()->getRowIterator($this->startRow);
     $i = 1;
     $codeStored = [];
     foreach ($iterator as $row) {
         $raw = [];
         /** @var \PHPExcel_Worksheet_Row $row */
         //            $rowIdx = $row->getRowIndex();
         $cells = $row->getCellIterator();
         foreach ($cells as $cell) {
             /** @var \PHPExcel_Cell $cell */
             $column = $cell->getColumn();
             $content = $cell->getFormattedValue();
             $targetField = isset($this->fileFields[$column]) ? $this->fileFields[$column] : null;
             if ($targetField) {
                 $raw[$targetField] = trim($content);
             }
         }
         //map row
         $storable = $this->rowToStorable($raw);
         //            print_r($storable);
         if (strlen(join($storable, ''))) {
             if ($sqlite && !isset($storable['id'])) {
                 $storable['id'] = $i;
             }
             if (!isset($storable['codeNumber'])) {
                 $storable['codeNumber'] = (string) $this->makeCodeNumberFromArray($storable);
             }
             if (isset($codeStored[$storable['codeNumber']])) {
                 print "\nDuplicate: " . $storable[self::INPUT_FIELD_ARTIST] . ': ' . $storable[self::INPUT_FIELD_TITLE] . "\n";
             } else {
                 $dbConn->insert('songs', $storable);
                 if (!($i % 100)) {
                     echo $i;
                 } else {
                     if (!($i % 10)) {
                         echo '.';
                     }
                 }
                 if (!($i % 1000)) {
                     echo "\n";
                 }
                 $i++;
                 $codeStored[$storable['codeNumber']] = true;
             }
         }
     }
     $total = $i - 1;
     echo "\nImported {$total} songs\n";
 }
Ejemplo n.º 5
0
 /**
  * Get table fields
  *
  * Info: $schemaManager->listTableColumns($this->tableName) doesn't work if fields are geometries!
  *
  * @throws \Doctrine\DBAL\DBALException
  * @return array field names
  */
 public function getStoreFields()
 {
     $schemaManager = $this->connection->getDriver()->getSchemaManager($this->connection);
     $columns = array();
     $sql = $schemaManager->getDatabasePlatform()->getListTableColumnsSQL($this->tableName, $this->connection->getDatabase());
     foreach ($this->connection->fetchAll($sql) as $fieldInfo) {
         $columns[] = $fieldInfo["field"];
     }
     return $columns;
 }
 /**
  * Create a Connection Handler from given Doctrine $connection
  *
  * @param \Doctrine\DBAL\Connection $connection
  *
  * @return \eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler
  */
 public static function createFromConnection(Connection $connection)
 {
     $driver = $connection->getDriver()->getName();
     if ($driver === 'pdo_sqlite') {
         return new ConnectionHandler\SqliteConnectionHandler($connection);
     }
     if ($driver === 'pdo_pgsql') {
         return new ConnectionHandler\PostgresConnectionHandler($connection);
     }
     return new self($connection);
 }
Ejemplo n.º 7
0
 public static function datasourceFromDbConnection(Connection $connection)
 {
     $driverType = $connection->getDriver()->getName();
     switch ($driverType) {
         case 'pdo_mysql':
             return new MySql($connection);
             break;
         case 'pdo_sqlite':
             return new Sqlite($connection);
             break;
         default:
             throw new \InvalidArgumentException("Can't use Db of type {$driverType}");
     }
 }
Ejemplo n.º 8
0
 private function pathExists($path, $workspaceName = null)
 {
     if (null === $workspaceName) {
         $workspaceName = $this->workspaceName;
     }
     if ($this->conn->getDriver() instanceof \Doctrine\DBAL\Driver\PDOMySql\Driver) {
         $query = 'SELECT id FROM phpcr_nodes WHERE path COLLATE utf8_bin = ? AND workspace_name = ?';
     } else {
         $query = 'SELECT id FROM phpcr_nodes WHERE path = ? AND workspace_name = ?';
     }
     if ($nodeId = $this->conn->fetchColumn($query, array($path, $workspaceName))) {
         return $nodeId;
     }
     return false;
 }
Ejemplo n.º 9
0
 /**
  * Executes the statement with the currently bound parameters.
  *
  * @param array|null $params
  *
  * @return boolean TRUE on success, FALSE on failure.
  *
  * @throws \Doctrine\DBAL\DBALException
  */
 public function execute($params = null)
 {
     if (is_array($params)) {
         $this->params = $params;
     }
     $logger = $this->conn->getConfiguration()->getSQLLogger();
     if ($logger) {
         $logger->startQuery($this->sql, $this->params, $this->types);
     }
     try {
         $stmt = $this->stmt->execute($params);
     } catch (\Exception $ex) {
         throw DBALException::driverExceptionDuringQuery($this->conn->getDriver(), $ex, $this->sql, $this->conn->resolveParams($this->params, $this->types));
     }
     if ($logger) {
         $logger->stopQuery();
     }
     $this->params = array();
     $this->types = array();
     return $stmt;
 }
Ejemplo n.º 10
0
 /**
  * Creates a connection to the test database, if there is none yet, and
  * creates the necessary tables.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->setUpDBALTypes();
     $forceCreateTables = false;
     if (!isset(static::$_sharedConn)) {
         static::$_sharedConn = TestUtil::getConnection();
         if (static::$_sharedConn->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
             $forceCreateTables = true;
         }
     }
     if (isset($GLOBALS['DOCTRINE_MARK_SQL_LOGS'])) {
         if (in_array(static::$_sharedConn->getDatabasePlatform()->getName(), array("mysql", "postgresql"))) {
             static::$_sharedConn->executeQuery('SELECT 1 /*' . get_class($this) . '*/');
         } else {
             if (static::$_sharedConn->getDatabasePlatform()->getName() == "oracle") {
                 static::$_sharedConn->executeQuery('SELECT 1 /*' . get_class($this) . '*/ FROM dual');
             }
         }
     }
     if (!$this->_em) {
         $this->_em = $this->_getEntityManager();
         $this->_schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
     }
     $classes = array();
     foreach ($this->_usedModelSets as $setName => $bool) {
         if (!isset(static::$_tablesCreated[$setName])) {
             foreach (static::$_modelSets[$setName] as $className) {
                 $classes[] = $this->_em->getClassMetadata($className);
             }
             static::$_tablesCreated[$setName] = true;
         }
     }
     if ($classes) {
         $this->_schemaTool->createSchema($classes);
     }
     $this->_sqlLoggerStack->enabled = true;
 }
Ejemplo n.º 11
0
 /**
  * @return \Doctrine\DBAL\Driver
  */
 public function getDriver()
 {
     return $this->_connection->getDriver();
 }
Ejemplo n.º 12
0
 public function testGetDriver()
 {
     $this->assertInstanceOf('Doctrine\\DBAL\\Driver\\PDOMySql\\Driver', $this->_conn->getDriver());
 }
Ejemplo n.º 13
0
 private function getDbMockBuilder(Connection $db)
 {
     return $this->getMockBuilder('\\Doctrine\\DBAL\\Connection')->setConstructorArgs([$db->getParams(), $db->getDriver(), $db->getConfiguration(), $db->getEventManager()])->enableOriginalConstructor();
 }
 /**
  * Get a vendor-specific selector based on a connection instance.
  *
  * @param  Connection       $connection A connection instance
  * @param  string           $table      The table to select from
  * @return AbstractSelector A selector instance
  * @throws DBALException
  */
 public static function fromConnection(Connection $connection, $table, array $types = [])
 {
     $name = $connection->getDriver()->getName();
     switch ($name) {
         case 'pdo_mysql':
             return new MysqlSelector($connection, $table, $types);
         case 'pdo_sqlite':
             return new SqliteSelector($connection, $table, $types);
         default:
             throw new DBALException("Unsupported database type: {$name}");
     }
 }
 /**
  * Sets the collation for the provided connection.
  *
  * @param  Connection $connection
  * @param  array      $options
  * @throws InvalidArgumentException Occurs if collation is invalid
  */
 private static function setConnectionCollation(Connection $connection, array $options = array())
 {
     if (isset($options['collation'])) {
         try {
             if ('pdo_mysql' === $connection->getDriver()->getName()) {
                 $connection->executeQuery('SET SESSION collation_connection = "' . addslashes($options['collation']) . '";');
             }
         } catch (\Exception $e) {
             throw new InvalidArgumentException(sprintf('Invalid database collation `%s`', $options['collation']), InvalidArgumentException::INVALID_ARGUMENT, $e);
         }
     }
 }
Ejemplo n.º 16
0
	private function isSQLite() {
		return $this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver;
	}
Ejemplo n.º 17
0
 /**
  * @param Connection $connection
  *
  * @return string
  */
 private function getAclObjectIdentifierComparison(Connection $connection)
 {
     if ('pdo_mysql' === $connection->getDriver()->getName()) {
         return 'acl.object_identifier COLLATE utf8_unicode_ci';
     }
     return 'acl.object_identifier';
 }
 /**
  * @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');
 }
Ejemplo n.º 19
0
 /**
  * Get driver name
  *
  * @return string
  */
 public function getDriverName()
 {
     return (string) $this->connection->getDriver()->getName();
 }
Ejemplo n.º 20
0
 private function connectToDatabase(Connection $db, $databaseName)
 {
     $db->close();
     $db->__construct(['dbname' => $databaseName] + $db->getParams(), $db->getDriver(), $db->getConfiguration(), $db->getEventManager());
     $db->connect();
 }
Ejemplo n.º 21
0
 /**
  * Create the message we want to throw, if there was a connection error.
  *
  * @param Connection $connection The connection.
  *
  * @return string The message we want throw if there was a connection error.
  */
 protected function createConnectionErrorMessage($connection)
 {
     $message = 'Not connected to database. dsn: ' . $connection->getDriver()->getName() . '://' . '****:****@' . $connection->getHost() . ':' . $connection->getPort() . '/' . $connection->getDatabase();
     return $message;
 }