123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
-
-
- namespace Doctrine\DBAL;
-
- use PDO,
- Doctrine\DBAL\Types\Type,
- Doctrine\DBAL\Driver\Statement as DriverStatement;
-
-
- class Statement implements \IteratorAggregate, DriverStatement
- {
-
-
- protected $sql;
-
-
- protected $params = array();
-
-
- protected $types = array();
-
-
- protected $stmt;
-
-
- protected $platform;
-
-
- protected $conn;
-
-
-
- public function __construct($sql, Connection $conn)
- {
- $this->sql = $sql;
- $this->stmt = $conn->getWrappedConnection()->prepare($sql);
- $this->conn = $conn;
- $this->platform = $conn->getDatabasePlatform();
- }
-
-
-
- public function bindValue($name, $value, $type = null)
- {
- $this->params[$name] = $value;
- $this->types[$name] = $type;
- if ($type !== null) {
- if (is_string($type)) {
- $type = Type::getType($type);
- }
- if ($type instanceof Type) {
- $value = $type->convertToDatabaseValue($value, $this->platform);
- $bindingType = $type->getBindingType();
- } else {
- $bindingType = $type;
- }
- return $this->stmt->bindValue($name, $value, $bindingType);
- } else {
- return $this->stmt->bindValue($name, $value);
- }
- }
-
-
-
- public function bindParam($name, &$var, $type = PDO::PARAM_STR, $length = null)
- {
- return $this->stmt->bindParam($name, $var, $type, $length );
- }
-
-
-
- public function execute($params = null)
- {
- $logger = $this->conn->getConfiguration()->getSQLLogger();
- if ($logger) {
- $logger->startQuery($this->sql, $this->params, $this->types);
- }
-
- try {
- $stmt = $this->stmt->execute($params);
- } catch (\Exception $ex) {
- throw DBALException::driverExceptionDuringQuery($ex, $this->sql, $this->conn->resolveParams($this->params, $this->types));
- }
-
- if ($logger) {
- $logger->stopQuery();
- }
- $this->params = array();
- $this->types = array();
- return $stmt;
- }
-
-
-
- public function closeCursor()
- {
- return $this->stmt->closeCursor();
- }
-
-
-
- public function columnCount()
- {
- return $this->stmt->columnCount();
- }
-
-
-
- public function errorCode()
- {
- return $this->stmt->errorCode();
- }
-
-
-
- public function errorInfo()
- {
- return $this->stmt->errorInfo();
- }
-
- public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
- {
- if ($arg2 === null) {
- return $this->stmt->setFetchMode($fetchMode);
- } else if ($arg3 === null) {
- return $this->stmt->setFetchMode($fetchMode, $arg2);
- }
-
- return $this->stmt->setFetchMode($fetchMode, $arg2, $arg3);
- }
-
- public function getIterator()
- {
- return $this->stmt;
- }
-
-
-
- public function fetch($fetchMode = null)
- {
- return $this->stmt->fetch($fetchMode);
- }
-
-
-
- public function fetchAll($fetchMode = null, $fetchArgument = 0)
- {
- if ($fetchArgument !== 0) {
- return $this->stmt->fetchAll($fetchMode, $fetchArgument);
- }
- return $this->stmt->fetchAll($fetchMode);
- }
-
-
-
- public function fetchColumn($columnIndex = 0)
- {
- return $this->stmt->fetchColumn($columnIndex);
- }
-
-
-
- public function rowCount()
- {
- return $this->stmt->rowCount();
- }
-
-
-
- public function getWrappedStatement()
- {
- return $this->stmt;
- }
- }
|