Exemple #1
0
 /**
  * execute
  * Executes a prepared statement
  *
  * If the prepared statement included parameter markers, you must either:
  * call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
  * bound variables pass their value as input and receive the output value,
  * if any, of their associated parameter markers or pass an array of input-only
  * parameter values
  *
  *
  * @param array $params             An array of values with as many elements as there are
  *                                  bound parameters in the SQL statement being executed.
  * @return boolean                  Returns TRUE on success or FALSE on failure.
  */
 public function execute($params = null)
 {
     try {
         $event = new Doctrine_Event($this, Doctrine_Event::STMT_EXECUTE, $this->getQuery(), $params);
         $this->_conn->getListener()->preStmtExecute($event);
         $result = true;
         if (!$event->skipOperation) {
             if ($this->_conn->getAttribute(Doctrine::PORTABILITY_EMPTY_TO_NULL)) {
                 foreach ($params as $key => $value) {
                     if ($value == '') {
                         $params[$key] = null;
                     }
                 }
             }
             $result = $this->_stmt->execute($params);
             $this->_conn->incrementQueryCount();
         }
         $this->_conn->getListener()->postStmtExecute($event);
         return $result;
     } catch (PDOException $e) {
     } catch (Doctrine_Adapter_Exception $e) {
     }
     $this->_conn->rethrowException($e, $this);
     return false;
 }
Exemple #2
0
 /**
  * Retrieves an enum index.
  * @see enumValue()
  *
  * @param string $fieldName
  * @param mixed $value          value of the enum considered
  * @return integer              can be string if native enums are used.
  */
 public function enumIndex($fieldName, $value)
 {
     $values = $this->getEnumValues($fieldName);
     if ($this->_conn->getAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM)) {
         return $value;
     }
     return array_search($value, $values);
 }
Exemple #3
0
 public function _execute($params)
 {
     $params = $this->_conn->convertBooleans(array_merge($this->_params, $params));
     if (!$this->_view) {
         $query = $this->getQuery($params);
     } else {
         $query = $this->_view->getSelectSql();
     }
     $params = $this->convertEnums($params);
     if ($this->isLimitSubqueryUsed() && $this->_conn->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') {
         $params = array_merge($params, $params);
     }
     if ($this->type !== self::SELECT) {
         return $this->_conn->exec($query, $params);
     }
     $stmt = $this->_conn->execute($query, $params);
     return $stmt;
 }
Exemple #4
0
 /**
  * execute
  * Executes a prepared statement
  *
  * If the prepared statement included parameter markers, you must either:
  * call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
  * bound variables pass their value as input and receive the output value,
  * if any, of their associated parameter markers or pass an array of input-only
  * parameter values
  *
  *
  * @param array $params             An array of values with as many elements as there are
  *                                  bound parameters in the SQL statement being executed.
  * @return boolean                  Returns TRUE on success or FALSE on failure.
  */
 public function execute($params = null)
 {
     try {
         $event = new Doctrine_Event($this, Doctrine_Event::STMT_EXECUTE, $this->getQuery(), $params);
         $this->_conn->getListener()->preStmtExecute($event);
         $result = true;
         if (!$event->skipOperation) {
             if ($this->_conn->getAttribute(Doctrine_Core::ATTR_PORTABILITY) & Doctrine_Core::PORTABILITY_EMPTY_TO_NULL) {
                 foreach ($params as $key => $value) {
                     if ($value === '') {
                         $params[$key] = null;
                     }
                 }
             }
             if ($params) {
                 $pos = 0;
                 foreach ($params as $key => $value) {
                     $pos++;
                     $param = is_numeric($key) ? $pos : $key;
                     if (is_resource($value)) {
                         $this->_stmt->bindParam($param, $params[$key], Doctrine_Core::PARAM_LOB);
                     } else {
                         $this->_stmt->bindParam($param, $params[$key]);
                     }
                 }
             }
             $result = $this->_stmt->execute();
             $this->_conn->incrementQueryCount();
         }
         $this->_conn->getListener()->postStmtExecute($event);
         //fix a possible "ORA-01000: maximum open cursors exceeded" when many non-SELECTs are executed and the profiling is enabled
         if ('Oracle' == $this->getConnection()->getDriverName()) {
             $queryBeginningSubstring = strtoupper(substr(ltrim($this->_stmt->queryString), 0, 6));
             if ($queryBeginningSubstring != 'SELECT' && substr($queryBeginningSubstring, 0, 4) != 'WITH') {
                 $this->closeCursor();
             }
         }
         return $result;
     } catch (PDOException $e) {
     } catch (Doctrine_Adapter_Exception $e) {
     }
     $this->_conn->rethrowException($e, $this);
     return false;
 }
 /**
  * execute
  * Executes a prepared statement
  *
  * If the prepared statement included parameter markers, you must either:
  * call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
  * bound variables pass their value as input and receive the output value,
  * if any, of their associated parameter markers or pass an array of input-only
  * parameter values
  *
  *
  * @param array $params             An array of values with as many elements as there are
  *                                  bound parameters in the SQL statement being executed.
  * @return boolean                  Returns TRUE on success or FALSE on failure.
  */
 public function execute($params = null)
 {
     try {
         $event = new Doctrine_Event($this, Doctrine_Event::STMT_EXECUTE, $this->getQuery(), $params);
         $this->_conn->getListener()->preStmtExecute($event);
         $result = true;
         if (!$event->skipOperation) {
             if ($this->_conn->getAttribute(Doctrine_Core::ATTR_PORTABILITY) & Doctrine_Core::PORTABILITY_EMPTY_TO_NULL) {
                 foreach ($params as $key => $value) {
                     if ($value === '') {
                         $params[$key] = null;
                     }
                 }
             }
             if ($params) {
                 $pos = 0;
                 foreach ($params as $key => $value) {
                     if ($value === null) {
                         continue;
                     }
                     $pos++;
                     $param = is_numeric($key) ? $pos : $key;
                     if (is_resource($value)) {
                         $this->_stmt->bindParam($param, $params[$key], Doctrine_Core::PARAM_LOB);
                     } else {
                         $this->_stmt->bindParam($param, $params[$key]);
                     }
                 }
             }
             $result = $this->_stmt->execute();
             $this->_conn->incrementQueryCount();
         }
         $this->_conn->getListener()->postStmtExecute($event);
         return $result;
     } catch (PDOException $e) {
     } catch (Doctrine_Adapter_Exception $e) {
     }
     $this->_conn->rethrowException($e, $this);
     return false;
 }
Exemple #6
0
 /**
  * Generates a string representation of a connection.
  *
  * This method returns an html dump of a connection, containing state, open
  * transactions and loaded tables.
  *
  * @param Doctrine_Connection $connection
  * @return string
  */
 public static function getConnectionAsString(Doctrine_Connection $connection)
 {
     $r[] = '<pre>';
     $r[] = 'Doctrine_Connection object';
     $r[] = 'State               : ' . Doctrine_Lib::getConnectionStateAsString($connection->transaction->getState());
     $r[] = 'Open Transactions   : ' . $connection->transaction->getTransactionLevel();
     $r[] = 'Table in memory     : ' . $connection->count();
     $r[] = 'Driver name         : ' . $connection->getAttribute(Doctrine::ATTR_DRIVER_NAME);
     $r[] = "</pre>";
     return implode("\n", $r) . "<br>";
 }