/** * Executes an, optionally parameterized, SQL query. * * If the query is parameterized, a prepared statement is used. * If an SQLLogger is configured, the execution is logged. * * @param string $query The SQL query to execute. * @param array $params The parameters to bind to the query, if any. * @param array $types The types the previous parameters are in. * @param QueryCacheProfile $qcp * @return Doctrine\DBAL\Driver\Statement The executed statement. * @internal PERF: Directly prepares a driver statement, not a wrapper. */ public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null) { if ($qcp !== null) { return $this->executeCacheQuery($query, $params, $types, $qcp); } $this->connect(); $hasLogger = $this->_config->getSQLLogger() !== null; if ($hasLogger) { $this->_config->getSQLLogger()->startQuery($query, $params, $types); } if ($params) { list($query, $params, $types) = SQLParserUtils::expandListParameters($query, $params, $types); $stmt = $this->_conn->prepare($query); if ($types) { $this->_bindTypedValues($stmt, $params, $types); $stmt->execute(); } else { $stmt->execute($params); } } else { $stmt = $this->_conn->query($query); } if ($hasLogger) { $this->_config->getSQLLogger()->stopQuery(); } return $stmt; }
/** * Executes an, optionally parameterized, SQL query. * * If the query is parameterized, a prepared statement is used. * If an SQLLogger is configured, the execution is logged. * * @param string $query The SQL query to execute. * @param array $params The parameters to bind to the query, if any. * @param array $types The types the previous parameters are in. * @param QueryCacheProfile $qcp * @return \Doctrine\DBAL\Driver\Statement The executed statement. * @internal PERF: Directly prepares a driver statement, not a wrapper. */ public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null) { if ($qcp !== null) { return $this->executeCacheQuery($query, $params, $types, $qcp); } $this->connect(); $logger = $this->_config->getSQLLogger(); if ($logger) { $logger->startQuery($query, $params, $types); } try { if ($params) { list($query, $params, $types) = SQLParserUtils::expandListParameters($query, $params, $types); $stmt = $this->_conn->prepare($query); if ($types) { $this->_bindTypedValues($stmt, $params, $types); $stmt->execute(); } else { $stmt->execute($params); } } else { $stmt = $this->_conn->query($query); } } catch (\Exception $ex) { throw DBALException::driverExceptionDuringQuery($ex, $query, $this->resolveParams($params, $types)); } $stmt->setFetchMode($this->_defaultFetchMode); if ($logger) { $logger->stopQuery(); } return $stmt; }
protected function executeQueries(array $queries, \Closure $logger = null) { $this->conn->beginTransaction(); try { foreach ($queries as $query) { if (null !== $logger) { $logger($query); } $this->conn->query($query); } $this->conn->commit(); } catch (\Exception $e) { $this->conn->rollback(); throw $e; } }
/** * 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; }
/** * @return string */ private function getCurrentVersion() { /** @var $result Statement */ $result = $this->db->query('SELECT version FROM schema'); $version = $result->fetchColumn(); if (!$version) { $version = '0'; $this->db->exec("INSERT INTO schema VALUES ('{$version}')"); } return $version; }
/** * Executes an, optionally parameterized, SQL query. * * If the query is parameterized, a prepared statement is used. * If an SQLLogger is configured, the execution is logged. * * @param string $query The SQL query to execute. * @param array $params The parameters to bind to the query, if any. * @return Doctrine\DBAL\Driver\Statement The executed statement. * @internal PERF: Directly prepares a driver statement, not a wrapper. */ public function executeQuery($query, array $params = array(), $types = array()) { $this->connect(); if ($this->_config->getSQLLogger() !== null) { $this->_config->getSQLLogger()->logSQL($query, $params); } if ($params) { $stmt = $this->_conn->prepare($query); if ($types) { $this->_bindTypedValues($stmt, $params, $types); $stmt->execute(); } else { $stmt->execute($params); } } else { $stmt = $this->_conn->query($query); } 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 { $statement = $this->_conn->query(...$args); } catch (Exception $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $args[0]); } $statement->setFetchMode($this->defaultFetchMode); if ($logger) { $logger->stopQuery(); } return $statement; }