Inheritance: extends Exception
Esempio n. 1
2
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     try {
         $pdo = new PDOConnection($this->_constructPdoDsn($params), $username, $password, $driverOptions);
         if (PHP_VERSION_ID >= 50600 && (!isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES]) || true === $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES])) {
             $pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
         }
         return $pdo;
     } catch (PDOException $e) {
         throw DBALException::driverException($this, $e);
     }
 }
Esempio n. 2
0
 /**
  * Only tested with PDO
  *
  * @param DBALException $error
  * @return bool
  */
 public function isDuplicateException(DBALException $error)
 {
     /** @var \PDOException $previous */
     $previous = $error->getPrevious();
     if (!$previous || $previous->getCode() != 23505) {
         return false;
     }
     return true;
 }
Esempio n. 3
0
 /**
  * Only tested with PDO
  *
  * @param DBALException $error
  * @return bool
  */
 public function isDuplicateException(DBALException $error)
 {
     /** @var \PDOException $previous */
     $previous = $error->getPrevious();
     if (!$previous || $previous->getCode() != 23000) {
         return false;
     }
     return isset($previous->errorInfo[1]) && $previous->errorInfo[1] == 1062;
 }
 /**
  * Adds an adapter-specific LIMIT clause to the SELECT statement.
  * [ borrowed from Zend Framework ]
  *
  * @param string $query
  * @param mixed $limit
  * @param mixed $offset
  * @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html
  * @return string
  * @override
  */
 public function writeLimitClause($query, $limit = false, $offset = false)
 {
     if ($limit > 0) {
         $count = intval($limit);
         $offset = intval($offset);
         if ($offset < 0) {
             throw DBALException::limitOffsetInvalid($offset);
         }
         $orderby = stristr($query, 'ORDER BY');
         if ($orderby !== false) {
             $sort = stripos($orderby, 'desc') !== false ? 'desc' : 'asc';
             $order = str_ireplace('ORDER BY', '', $orderby);
             $order = trim(preg_replace('/ASC|DESC/i', '', $order));
         }
         $query = preg_replace('/^SELECT\\s/i', 'SELECT TOP ' . ($count + $offset) . ' ', $query);
         $query = 'SELECT * FROM (SELECT TOP ' . $count . ' * FROM (' . $query . ') AS inner_tbl';
         if ($orderby !== false) {
             $query .= ' ORDER BY ' . $order . ' ';
             $query .= stripos($sort, 'asc') !== false ? 'DESC' : 'ASC';
         }
         $query .= ') AS outer_tbl';
         if ($orderby !== false) {
             $query .= ' ORDER BY ' . $order . ' ' . $sort;
         }
         return $query;
     }
     return $query;
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     try {
         return new MysqliConnection($params, $username, $password, $driverOptions);
     } catch (MysqliException $e) {
         throw DBALException::driverException($this, $e);
     }
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     try {
         return new PDOConnection($this->constructPdoDsn($params), $username, $password, $driverOptions);
     } catch (\PDOException $e) {
         throw DBALException::driverException($this, $e);
     }
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  *
  * @throws \Doctrine\DBAL\DBALException if there was a problem establishing the connection.
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     try {
         return new SQLAnywhereConnection($this->buildDsn(isset($params['host']) ? $params['host'] : null, isset($params['port']) ? $params['port'] : null, isset($params['server']) ? $params['server'] : null, isset($params['dbname']) ? $params['dbname'] : null, $username, $password, $driverOptions), isset($params['persistent']) ? $params['persistent'] : false);
     } catch (SQLAnywhereException $e) {
         throw DBALException::driverException($this, $e);
     }
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     try {
         return new OCI8Connection($username, $password, $this->_constructDsn($params), isset($params['charset']) ? $params['charset'] : null, isset($params['sessionMode']) ? $params['sessionMode'] : OCI_DEFAULT, isset($params['persistent']) ? $params['persistent'] : false);
     } catch (OCI8Exception $e) {
         throw DBALException::driverException($this, $e);
     }
 }
 /**
  * Constructor.
  *
  * @param string                                $message         The exception message.
  * @param \Doctrine\DBAL\Driver\DriverException $driverException The DBAL driver exception to chain.
  */
 public function __construct($message, \Doctrine\DBAL\Driver\DriverException $driverException)
 {
     $exception = null;
     if ($driverException instanceof \Exception) {
         $exception = $driverException;
     }
     parent::__construct($message, 0, $exception);
     $this->driverException = $driverException;
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     try {
         $conn = new \Doctrine\DBAL\Driver\PDOConnection($this->_constructPdoDsn($params), $username, $password, $driverOptions);
     } catch (PDOException $e) {
         throw DBALException::driverException($this, $e);
     }
     return $conn;
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = NULL, $password = NULL, array $driverOptions = [])
 {
     try {
         // create our special driver
         $conn = new PDOConnection($this->constructPdoDsn($params), $username, $password, $driverOptions);
     } catch (PDOException $e) {
         throw DBALException::driverException($this, $e);
     }
     return $conn;
 }
 public function testDoctrineExceptionFailedTransaction()
 {
     $db = $this->db();
     $ex = new \PDOException('SQLSTATE[25P02]: In failed sql transaction: 7 ERROR:  current transaction is aborted, commands ignored until end of transaction block');
     $first = DBALException::driverExceptionDuringQuery($ex, 'SELECT * FROM auth_users WHERE ok = ?', $db->resolveParams(array(1), array()));
     $second = DBALException::driverExceptionDuringQuery($ex, 'SELECT * FROM product WHERE id = ?', $db->resolveParams(array(2), array()));
     $firstContext = MonologBubble::exceptionContext($first);
     $secondContext = MonologBubble::exceptionContext($second);
     $this->assertNotEquals($firstContext, $secondContext);
     $this->assertEquals($this->loggerRecord($first), $this->loggerRecord($second));
 }
Esempio n. 13
0
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     if (isset($driverOptions['userDefinedFunctions'])) {
         $this->_userDefinedFunctions = array_merge($this->_userDefinedFunctions, $driverOptions['userDefinedFunctions']);
         unset($driverOptions['userDefinedFunctions']);
     }
     try {
         $pdo = new PDOConnection($this->_constructPdoDsn($params), $username, $password, $driverOptions);
     } catch (PDOException $ex) {
         throw DBALException::driverException($this, $ex);
     }
     foreach ($this->_userDefinedFunctions as $fn => $data) {
         $pdo->sqliteCreateFunction($fn, $data['callback'], $data['numArgs']);
     }
     return $pdo;
 }
Esempio n. 14
0
 /**
  * {@inheritdoc}
  *
  * @throws \Doctrine\DBAL\DBALException if there was a problem establishing the connection.
  * @throws SQLAnywhereException         if a mandatory connection parameter is missing.
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     if (!isset($params['host'])) {
         throw new SQLAnywhereException("Missing 'host' in configuration for sqlanywhere driver.");
     }
     if (!isset($params['server'])) {
         throw new SQLAnywhereException("Missing 'server' in configuration for sqlanywhere driver.");
     }
     if (!isset($params['dbname'])) {
         throw new SQLAnywhereException("Missing 'dbname' in configuration for sqlanywhere driver.");
     }
     try {
         return new SQLAnywhereConnection($this->buildDsn($params['host'], isset($params['port']) ? $params['port'] : null, $params['server'], $params['dbname'], $username, $password, $driverOptions), isset($params['persistent']) ? $params['persistent'] : false);
     } catch (SQLAnywhereException $e) {
         throw DBALException::driverException($this, $e);
     }
 }
Esempio n. 15
0
 /**
  * @param string                 $tableName
  * @param Column[]               $columns
  * @param Index[]                $indexes
  * @param ForeignKeyConstraint[] $fkConstraints
  * @param integer                $idGeneratorType
  * @param array                  $options
  *
  * @throws DBALException
  */
 public function __construct($tableName, array $columns = array(), array $indexes = array(), array $fkConstraints = array(), $idGeneratorType = 0, array $options = array())
 {
     if (strlen($tableName) == 0) {
         throw DBALException::invalidTableName($tableName);
     }
     $this->_setName($tableName);
     foreach ($columns as $column) {
         $this->_addColumn($column);
     }
     foreach ($indexes as $idx) {
         $this->_addIndex($idx);
     }
     foreach ($fkConstraints as $constraint) {
         $this->_addForeignKeyConstraint($constraint);
     }
     $this->_options = $options;
 }
 /**
  * {@inheritdoc}
  */
 public function exec($statement)
 {
     $this->connect();
     $logger = $this->_config->getSQLLogger();
     if ($logger) {
         $logger->startQuery($statement);
     }
     try {
         $this->executeQuery($statement);
     } catch (\Exception $ex) {
         throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
     }
     if ($logger) {
         $logger->stopQuery();
     }
     return 1;
 }
 /**
  * {@inheritdoc}
  */
 public function createDatabasePlatformForVersion($version)
 {
     if (!preg_match('/^(?P<major>\\d+)(?:\\.(?P<minor>\\d+)(?:\\.(?P<patch>\\d+))?)?/', $version, $versionParts)) {
         throw DBALException::invalidPlatformVersionSpecified($version, '<major_version>.<minor_version>.<patch_version>');
     }
     $majorVersion = $versionParts['major'];
     $minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
     $patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
     $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
     switch (true) {
         case version_compare($version, '9.2', '>='):
             return new PostgreSQL92Platform();
         case version_compare($version, '9.1', '>='):
             return new PostgreSQL91Platform();
         default:
             return new PostgreSqlPlatform();
     }
 }
Esempio n. 18
0
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     try {
         $pdo = new PDOConnection($this->_constructPdoDsn($params), $username, $password, $driverOptions);
         if (defined('PDO::PGSQL_ATTR_DISABLE_PREPARES') && (!isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES]) || true === $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES])) {
             $pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
         }
         /* defining client_encoding via SET NAMES to avoid inconsistent DSN support
          * - the 'client_encoding' connection param only works with postgres >= 9.1
          * - passing client_encoding via the 'options' param breaks pgbouncer support
          */
         if (isset($params['charset'])) {
             $pdo->query('SET NAMES \'' . $params['charset'] . '\'');
         }
         return $pdo;
     } catch (PDOException $e) {
         throw DBALException::driverException($this, $e);
     }
 }
 public function createConnection($config)
 {
     $driver = $this->driver_manager->driver(array_get($config, 'driver', ''));
     if (!$driver instanceof \Doctrine\DBAL\Driver) {
         $driver = $this->driver_manager->driver();
     }
     $params = $config;
     $params['host'] = array_get($params, 'host', array_get($config, 'server'));
     $params['user'] = array_get($params, 'user', array_get($config, 'username'));
     $params['wrapperClass'] = array_get($config, 'wrapperClass', '\\Concrete\\Core\\Database\\Connection\\Connection');
     unset($params['driver']);
     $wrapperClass = 'Doctrine\\DBAL\\Connection';
     if (isset($params['wrapperClass'])) {
         if (is_subclass_of($params['wrapperClass'], $wrapperClass)) {
             $wrapperClass = $params['wrapperClass'];
         } else {
             throw DBALException::invalidWrapperClass($params['wrapperClass']);
         }
     }
     return new $wrapperClass($params, $driver);
 }
 /**
  * {@inheritdoc}
  */
 public function createDatabasePlatformForVersion($version)
 {
     if (!preg_match('/^(?P<major>\\d+)(?:\\.(?P<minor>\\d+)(?:\\.(?P<patch>\\d+)(?:\\.(?P<build>\\d+))?)?)?/', $version, $versionParts)) {
         throw DBALException::invalidPlatformVersionSpecified($version, '<major_version>.<minor_version>.<patch_version>.<build_version>');
     }
     $majorVersion = $versionParts['major'];
     $minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
     $patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
     $buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0;
     $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
     switch (true) {
         case version_compare($version, '11.00.2100', '>='):
             return new SQLServer2012Platform();
         case version_compare($version, '10.00.1600', '>='):
             return new SQLServer2008Platform();
         case version_compare($version, '9.00.1399', '>='):
             return new SQLServer2005Platform();
         default:
             return new SQLServerPlatform();
     }
 }
Esempio n. 21
0
 /**
  * {@inheritdoc}
  */
 public function getIndexDeclarationSQL($name, Index $index)
 {
     // Index declaration in statements like CREATE TABLE is not supported.
     throw DBALException::notSupported(__METHOD__);
 }
Esempio n. 22
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) {
         if ($logger) {
             $logger->stopQuery();
         }
         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;
 }
 /**
  * {@inheritdoc}
  */
 public function createDatabasePlatformForVersion($version)
 {
     if (!preg_match('/^(?P<major>\\d+)(?:\\.(?P<minor>\\d+)(?:\\.(?P<patch>\\d+))?)?/', $version, $versionParts)) {
         throw DBALException::invalidPlatformVersionSpecified($version, '<major_version>.<minor_version>.<patch_version>');
     }
     if (false !== stripos($version, 'mariadb')) {
         return $this->getDatabasePlatform();
     }
     $majorVersion = $versionParts['major'];
     $minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
     $patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
     $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
     if (version_compare($version, '5.7', '>=')) {
         return new MySQL57Platform();
     }
     return $this->getDatabasePlatform();
 }
Esempio n. 24
0
 /**
  * @param array $sequence
  * @return Sequence
  */
 protected function _getPortableSequenceDefinition($sequence)
 {
     throw DBALException::notSupported('Sequences');
 }
Esempio n. 25
0
 /**
  * Checks the list of parameters.
  *
  * @param array $params
  */
 private static function _checkParams(array $params)
 {
     // check existance of mandatory parameters
     // driver
     if (!isset($params['driver']) && !isset($params['driverClass'])) {
         throw DBALException::driverRequired();
     }
     // check validity of parameters
     // driver
     if (isset($params['driver']) && !isset(self::$_driverMap[$params['driver']])) {
         throw DBALException::unknownDriver($params['driver'], array_keys(self::$_driverMap));
     }
     if (isset($params['driverClass']) && !in_array('Doctrine\\DBAL\\Driver', class_implements($params['driverClass'], true))) {
         throw DBALException::invalidDriverClass($params['driverClass']);
     }
 }
Esempio n. 26
0
 /**
  * The class name of the reserved keywords list.
  *
  * @return string
  */
 protected function getReservedKeywordsClass()
 {
     throw DBALException::notSupported(__METHOD__);
 }
Esempio n. 27
0
 /**
  * Initializes a new instance of the Connection class.
  *
  * @param array $params  The connection parameters.
  * @param Driver $driver
  * @param Configuration $config
  * @param EventManager $eventManager
  */
 public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null)
 {
     $this->_driver = $driver;
     $this->_params = $params;
     if (isset($params['pdo'])) {
         $this->_conn = $params['pdo'];
         $this->_isConnected = true;
     }
     // Create default config and event manager if none given
     if (!$config) {
         $config = new Configuration();
     }
     if (!$eventManager) {
         $eventManager = new EventManager();
     }
     $this->_config = $config;
     $this->_eventManager = $eventManager;
     if (!isset($params['platform'])) {
         $this->_platform = $driver->getDatabasePlatform();
     } else {
         if ($params['platform'] instanceof Platforms\AbstractPlatform) {
             $this->_platform = $params['platform'];
         } else {
             throw DBALException::invalidPlatformSpecified();
         }
     }
     $this->_transactionIsolationLevel = $this->_platform->getDefaultTransactionIsolationLevel();
 }
Esempio n. 28
0
 public function getSequenceNextValSQL($sequenceName)
 {
     throw DBALException::notSupported(__METHOD__);
 }
 /**
  * Gets the SQL Snippet used to declare a BLOB column type.
  */
 public function getBlobTypeDeclarationSQL(array $field)
 {
     throw DBALException::notSupported(__METHOD__);
 }
Esempio n. 30
0
 /**
  * Parses the scheme part from given connection URL and resolves the given connection parameters.
  *
  * @param array $url    The connection URL parts to evaluate.
  * @param array $params The connection parameters to resolve.
  *
  * @return array The resolved connection parameters.
  *
  * @throws DBALException if parsing failed or resolution is not possible.
  */
 private static function parseDatabaseUrlScheme(array $url, array $params)
 {
     if (isset($url['scheme'])) {
         // The requested driver from the URL scheme takes precedence
         // over the default custom driver from the connection parameters (if any).
         unset($params['driverClass']);
         // URL schemes must not contain underscores, but dashes are ok
         $driver = str_replace('-', '_', $url['scheme']);
         // The requested driver from the URL scheme takes precedence
         // over the default driver from the connection parameters (if any).
         $params['driver'] = isset(self::$driverSchemeAliases[$driver]) ? self::$driverSchemeAliases[$driver] : $driver;
         return $params;
     }
     // If a schemeless connection URL is given, we require a default driver or default custom driver
     // as connection parameter.
     if (!isset($params['driverClass']) && !isset($params['driver'])) {
         throw DBALException::driverRequired($params['url']);
     }
     return $params;
 }