public static driverExceptionDuringQuery ( Doctrine\DBAL\Driver $driver, Exception $driverEx, string $sql, array $params = [] ) : |
||
$driver | Doctrine\DBAL\Driver | |
$driverEx | Exception | |
$sql | string | |
$params | array | |
return |
/** * @return array */ public function validateDataProvider() { return [[$this->getDataSourceInterfaceMock(), false, DBALException::driverExceptionDuringQuery(new \Exception('failed'), 'sql')], [$this->getDataSourceInterfaceMock(), false, new InvalidConfigurationException()], [$this->getDataSourceInterfaceMock(), false, null], [$this->getOrmDataSourceInterfaceMock(), true, DBALException::driverExceptionDuringQuery(new \Exception('failed'), 'sql')], [$this->getOrmDataSourceInterfaceMock(), true, new InvalidConfigurationException()], [$this->getOrmDataSourceInterfaceMock(), true, null]]; }
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)); }
/** * {@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; }
/** * 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; }
/** * Executes an SQL statement, returning a result set as a Statement object. * * @return \Doctrine\DBAL\Driver\Statement * * @throws \Doctrine\DBAL\DBALException */ public function query() { $this->connect(); $args = func_get_args(); $logger = $this->_config->getSQLLogger(); if ($logger) { $logger->startQuery($args[0]); } try { switch (func_num_args()) { case 1: $statement = $this->_conn->query($args[0]); break; case 2: $statement = $this->_conn->query($args[0], $args[1]); break; default: $statement = call_user_func_array(array($this->_conn, 'query'), $args); break; } } catch (\Exception $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $args[0]); } $statement->setFetchMode($this->defaultFetchMode); if ($logger) { $logger->stopQuery(); } return $statement; }
/** * Prepares an SQL statement. * * @param string $statement The SQL statement to prepare. * @throws DBALException * @return PDOStatement The prepared statement. */ public function prepare($statement) { $this->connect(); try { $stmt = new PDOStatement($statement, $this); } catch (\Exception $ex) { throw $this->resolveException(Doctrine\DBAL\DBALException::driverExceptionDuringQuery($this->getDriver(), $ex, $statement), $statement); } $stmt->setFetchMode(PDO::FETCH_ASSOC); return $stmt; }
public function testDriverExceptionDuringQueryAcceptsBinaryData() { $driver = $this->getMock('\\Doctrine\\DBAL\\Driver'); $e = DBALException::driverExceptionDuringQuery($driver, new \Exception(), '', array('ABC', chr(128))); $this->assertContains('with params ["ABC", "\\x80"]', $e->getMessage()); }