/** * {@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()]); }
/** * @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(); }
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); }
protected function execute() { if ($this->currentStatement === null) { $this->currentStatement = $this->db->query($this->buildQuery()); $this->rowCount = $this->currentStatement->rowCount(); } return $this->currentStatement; }
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(); }
/** * 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().'); }
/** * @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); } }
/** * 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; }
/** * {@inheritdoc} */ public function count() { if (null === $this->rowCount) { if ($this->rowCountCalculated) { $this->doCalcRowCount(); } else { if (null === $this->stmt) { $this->rewind(); } $this->rowCount = $this->stmt->rowCount(); } } return $this->rowCount; }
/** * Performs binding of variables bound with bindValue and bindParam on the statement $stmt. * * This method must be called if you have used the bind methods * in your query and you build the method yourself using build. * * @param \Doctrine\DBAL\Statement $stmt */ private function doBind(Statement $stmt) { foreach ($this->boundValues as $key => $value) { $stmt->bindValue($key, $value, $this->boundValuesType[$key]); } foreach ($this->boundParameters as $key => &$value) { $stmt->bindParam($key, $value, $this->boundParametersType[$key]); } }
/** * @param \Doctrine\DBAL\Connection $connection * @param \Doctrine\DBAL\Statement $stmt */ function it_get_keys($connection, $stmt) { $stmt->fetchAll(\PDO::FETCH_COLUMN)->willReturn(array('filename', 'filename1', 'filename2')); $connection->quoteIdentifier(Argument::any())->will(function ($argument) { return sprintf('"%s"', $argument[0]); }); $connection->executeQuery('SELECT "key" FROM "someTableName"')->willReturn($stmt); $this->keys()->shouldReturn(array('filename', 'filename1', 'filename2')); }
private function prepareInsert(ClassMetadata $meta, array $data) { // construct sql $columns = array(); foreach ($data as $column) { $columns[] = $column['quotedColumn']; } $insertSql = 'INSERT INTO ' . $this->quotes->getTableName($meta, $this->platform) . ' (' . implode(', ', $columns) . ')' . ' VALUES (' . implode(', ', array_fill(0, count($columns), '?')) . ')'; // create statement $statement = new Statement($insertSql, $this->db); // bind values $paramIndex = 1; foreach ($data as $column) { $statement->bindValue($paramIndex++, $column['value'], $column['type']); } return $statement; }
/** * @return mixed */ public function rowCount() { return $this->stmt->rowCount(); }
public function bindAllParams(Statement $stmt) { foreach ($this->bind as $k => $d) { $stmt->bindValue(":{$k}", $d, PDO::PARAM_STR); } return $this; }
public function registerBindings(Statement $stmt) { if (null !== $this->where) { $this->where->registerBindings($this); } foreach ($this->bindings as $key => $value) { $stmt->bindValue($key, $value); } }
/** * Биндит значения плейсхолдеров * @param Statement $preparedStatement * @param string $query SQL, сформированный билдером для текущего запроса * (например, подзапроса, вложенного в основной) */ protected function bind(Statement $preparedStatement, $query) { foreach ($this->values as $placeholder => $value) { if (strpos($query, $placeholder) !== false) { $preparedStatement->bindValue($placeholder, $value[0], $value[1]); } } foreach ($this->variables as $placeholder => $value) { if (strpos($query, $placeholder) !== false) { $variable =& $value[0]; $preparedStatement->bindParam($placeholder, $variable, $value[1]); } } foreach ($this->arrays as $placeholder => $values) { $count = count($values); for ($i = 0; $i < $count; $i++) { $value = $values[$i]; $nextPlaceholder = $placeholder . $i; if (is_null($value)) { $preparedStatement->bindValue($nextPlaceholder, $value, \PDO::PARAM_NULL); } elseif (is_int($value)) { $preparedStatement->bindValue($nextPlaceholder, $value, \PDO::PARAM_INT); } else { $preparedStatement->bindValue($nextPlaceholder, $value, \PDO::PARAM_STR); } } } }
/** * @param Statement $sth * @param ArrayCollection $parameters * * @return Statement * * @throws \Doctrine\DBAL\DBALException */ private function bindParameters(Statement $sth, array $parameters) { foreach ($parameters as $key => $value) { $typeInferer = Query\ParameterTypeInferer::inferType($value); if (!is_int($typeInferer)) { $findType = Type::getType($typeInferer); $value = $findType->convertToDatabaseValue($value, new MySqlPlatform()); $bindingType = $findType->getBindingType(); } else { $bindingType = $typeInferer; } $sth->bindValue($key, $value, $bindingType); } return $sth; }
/** * Prepares an SQL statement. * * @param string $statement The SQL statement to prepare. * * @return \Doctrine\DBAL\Driver\Statement The prepared statement. * * @throws \Doctrine\DBAL\DBALException */ public function prepare($statement) { $this->connect(); try { $stmt = new Statement($statement, $this); } catch (\Exception $ex) { throw DBALException::driverExceptionDuringQuery($ex, $statement); } $stmt->setFetchMode($this->defaultFetchMode); return $stmt; }
/** * Prepares an SQL statement. * * @param string $statement The SQL statement to prepare. * @return \Doctrine\DBAL\Driver\Statement The prepared statement. */ public function prepare($statement) { $this->connect(); $stmt = new Statement($statement, $this); $stmt->setFetchMode($this->_defaultFetchMode); return $stmt; }