/** * {@inheritdoc} */ protected function write(array $record) { $this->createStatement(); /** @var \DateTime $date */ $date = $record['datetime']; /** @var ContaoContext $context */ $context = $record['extra']['contao']; $this->statement->execute(['tstamp' => $date->format('U'), 'text' => StringUtil::specialchars((string) $record['formatted']), 'source' => (string) $context->getSource(), 'action' => (string) $context->getAction(), 'username' => (string) $context->getUsername(), 'func' => (string) $context->getFunc(), 'ip' => (string) $context->getIp(), 'browser' => (string) $context->getBrowser()]); }
protected function write(array $record) { if (!$this->initialized) { $this->initialize(); } $this->statement->bindValue('channel', $record['channel'], Type::STRING); $this->statement->bindValue('level', $record['level'], Type::INTEGER); $this->statement->bindValue('level_name', $record['level_name'], Type::STRING); $this->statement->bindValue('message', $record['message'], Type::TEXT); $this->statement->bindValue('context', $record['context'], Type::TARRAY); $this->statement->bindValue('extra', $record['extra'], Type::TARRAY); $this->statement->bindValue('datetime', $record['datetime'], Type::DATETIME); $this->statement->execute(); }
/** * @param null $params * @throws DBALException * @return bool */ public function execute($params = NULL) { try { return parent::execute($params); } catch (\Exception $e) { $conn = $this->conn; /** @var Connection $conn */ throw $conn->resolveException($e, $this->sql, (is_array($params) ? $params : array()) + $this->params); } }
/** * {@inheritdoc} */ public function execute() { $sql = $this->getSql(); if (is_null($this->preparedStatement)) { $this->preparedStatement = $this->connection->prepare($sql); } $this->bind($this->preparedStatement, $sql); $this->preparedStatement->execute(); $this->executed = true; return $this->preparedStatement; }
/** * {@inheritdoc} */ public function rewind() { if (null === $this->stmt) { $this->stmt = $this->prepare($this->sql, $this->params); } if (0 !== $this->key) { $this->stmt->execute(); $this->data = $this->stmt->fetch(\PDO::FETCH_ASSOC); $this->key = 0; } }
/** * @expectedException \Doctrine\DBAL\DBALException */ public function testExecuteCallsLoggerStopQueryOnException() { $logger = $this->getMock('\\Doctrine\\DBAL\\Logging\\SQLLogger'); $this->configuration->expects($this->once())->method('getSQLLogger')->will($this->returnValue($logger)); // Needed to satisfy construction of DBALException $this->conn->expects($this->any())->method('resolveParams')->will($this->returnValue(array())); $logger->expects($this->once())->method('startQuery'); $logger->expects($this->once())->method('stopQuery'); $this->pdoStatement->expects($this->once())->method('execute')->will($this->throwException(new \Exception("Mock test exception"))); $statement = new Statement("", $this->conn); $statement->execute(); }
/** * Executes the statement with the currently bound parameters * * @param array $params Parameters OPTIONAL * * @return boolean * @throws \XLite\Core\PDOException */ public function execute($params = null) { try { $result = parent::execute($params); } catch (\PDOException $e) { $sql = $this->_sql; if (!$sql && is_object($this->_stmt) && $this->_stmt->queryString) { $sql = $this->_stmt->queryString; } throw new \XLite\Core\PDOException($e, $sql, $this->_params); } return $result; }
/** * @param null $params * @return null * @throws */ public function execute($params = null) { $stmt = null; $attempt = 0; $retry = true; while ($retry) { $retry = false; try { $stmt = $this->stmt->execute($params); } catch (\Exception $e) { if ($this->conn->canTryAgain($attempt) && $this->conn->getDriver()->isGoneAwayException($e)) { $this->conn->close(); $this->createStatement(); $attempt++; $retry = true; } else { throw $e; } } } return $stmt; }
public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedToExecute() { $name = 'foo'; $var = 'bar'; $values = array($name => $var); $types = array(); $sql = ''; $logger = $this->getMock('\\Doctrine\\DBAL\\Logging\\SQLLogger'); $logger->expects($this->once())->method('startQuery')->with($this->equalTo($sql), $this->equalTo($values), $this->equalTo($types)); $this->configuration->expects($this->once())->method('getSQLLogger')->will($this->returnValue($logger)); $statement = new Statement($sql, $this->conn); $statement->execute($values); }
/** * Tests whether UnbufferedConnectionHelper works as intended in normal circumstances. * * @runInSeparateProcess */ public function testUnbufferedConnectionHelper() { $this->importData('Import/stress.sql'); UnbufferedConnectionHelper::unbufferConnection($this->getConnection()); $this->getConnection()->close(); $bufferredTimeStart = microtime(); $statementBuff = new Statement('SELECT * FROM generator_64k', $this->getConnection()); $statementBuff->execute(); $bufferredTime = microtime() - $bufferredTimeStart; $this->getConnection()->close(); UnbufferedConnectionHelper::unbufferConnection($this->getConnection()); $unBufferredTimeStart = microtime(); $statement = new Statement('SELECT * FROM generator_64k', $this->getConnection()); $statement->execute(); $unBufferedTime = microtime() - $unBufferredTimeStart; $this->getConnection()->close(); $this->assertTrue($unBufferedTime < $bufferredTime, 'Unbuffered query should return faster after execute().'); }