/**
  * Rolls back a transaction.
  * @throws TDbException if the transaction or the DB connection is not active.
  */
 public function rollback()
 {
     if ($this->_compatible) {
         $this->getConnection()->setForceMaster(TMasterSlaveDbConnectionForceMaster::OFF_AUTOMATIC);
     }
     Prado::log('rollback, ForceMaster: OFF_AUTOMATIC', TLogger::DEBUG, 'System.Testing.Data.Distributed.MasterSlave.TMasterSlaveDbTransaction');
     parent::rollback();
 }
Ejemplo n.º 2
0
 /**
  * Handles external error caused by end-users.
  * This method overrides the parent implementation.
  * It is invoked by PRADO when an external exception is thrown.
  */
 protected function handleExternalError($statusCode, $exception)
 {
     // log the error (only for BlogException)
     if ($exception instanceof BlogException) {
         Prado::log($exception->getErrorMessage(), TLogger::ERROR, 'BlogApplication');
     }
     // call parent implementation to display the error
     parent::handleExternalError($statusCode, $exception);
 }
Ejemplo n.º 3
0
 /**
  * Displays error to the client user.
  * THttpException and errors happened when the application is in <b>Debug</b>
  * mode will be displayed to the client user.
  * @param integer response status code
  * @param Exception exception instance
  */
 protected function handleExternalError($statusCode, $exception)
 {
     if ($exception instanceof BlogException) {
         $message = $exception->getMessage();
         Prado::log($message, TLogger::ERROR, 'BlogApplication');
         $message = urldecode($this->getApplication()->getSecurityManager()->hashData($message));
         $this->Response->redirect($this->Service->constructUrl('ErrorReport', array('msg' => $message), false));
     } else {
         parent::handleExternalError($statusCode, $exception);
     }
 }
Ejemplo n.º 4
0
 public function onError($param)
 {
     Prado::log($param->getMessage(), TLogger::ERROR, 'System.TApplication');
     $this->raiseEvent('OnError', $this, $param);
     $this->getErrorHandler()->handleError($this, $param);
 }
Ejemplo n.º 5
0
 /**
  * @param string method of PDOStatement to be called
  * @param mixed the first parameter to be passed to the method
  * @return mixed the method execution result
  */
 private function queryInternal($method, $mode)
 {
     $params = $this->_connection->enableParamLogging && !empty($this->_params) ? '. Bind with parameter ' . implode(', ', $this->_params) : '';
     Prado::trace('Querying SQL: ' . $this->getText() . $params, 'System.Testing.Data.TDbCommand');
     try {
         /*
         if($this->_connection->enableProfiling)
         	Prado::beginProfile('System.Testing.Data.TDbCommand.query('.$this->getText().')','System.Testing.Data.TDbCommand.query');
         */
         if ($this->_statement instanceof PDOStatement) {
             $this->_statement->execute();
         } else {
             $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText());
         }
         if ($method === '') {
             $result = new TDbDataReader($this);
         } else {
             $result = $this->_statement->{$method}($mode);
             $this->_statement->closeCursor();
         }
         /*
         if($this->_connection->enableProfiling)
         	Prado::endProfile('System.Testing.Data.TDbCommand.query('.$this->getText().')','System.Testing.Data.TDbCommand.query');
         */
         return $result;
     } catch (Exception $e) {
         /*
         if($this->_connection->enableProfiling)
         	prado::endProfile('System.Testing.Data.TDbCommand.query('.$this->getText().')','System.Testing.Data.TDbCommand.query');
         */
         Prado::log('Error in querying SQL: ' . $this->getText() . $params, TLogger::ERROR, 'System.Testing.Data..TDbCommand');
         throw new TDbException('TDbCommand failed to execute the SQL statement: {0}', $e->getMessage());
     }
 }
 /**
  * Constructor.
  * @param TDbConnection the database connection
  * @param string the SQL statement to be executed
  * @param TDbStatementClassification Defaults to 'UNKNOWN'
  */
 public function __construct(TDbConnection $connection, $text, $classification = TDbStatementClassification::UNKNOWN)
 {
     $connection->setActive(true);
     parent::__construct($connection, $text);
     $this->_statementClassification = $classification;
     Prado::log($classification . ', ' . $connection->getServerRole() . ': ' . preg_replace('/[\\s]+/', ' ', $text), TLogger::DEBUG, 'System.Testing.Data.Distributed.TDistributedDbCommand');
 }
 /**
  * Creates a command for execution.
  * @param string SQL statement associated with the new command.
  * @return TDistributedDbCommand the DB command
  * @throws TDbException if the connection is not active
  */
 public function createCommand($sql)
 {
     $force = $this->getForceMaster();
     if ($force == TMasterSlaveDbConnectionForceMaster::ON_MANUAL || $force == TMasterSlaveDbConnectionForceMaster::ON_TRANSACTION) {
         Prado::log('ForceMaster: ' . $force, TLogger::DEBUG, 'System.Testing.Data.Distributed.MasterSlave.TSlaveDbConnection');
         return new TDistributedDbCommand($this->getMasterConnection(), $sql, TDbStatementClassification::UNKNOWN);
     }
     $bEnqueue = false;
     $bMaster = false;
     $classification = $this->getStatementClassification($sql);
     switch ($classification) {
         case TDbStatementClassification::SQL:
             $bMaster = false;
             break;
         case TDbStatementClassification::CONTEXT:
             $bEnqueue = true;
             $bMaster = true;
             break;
         case TDbStatementClassification::TCL:
             $this->setForceMaster(TMasterSlaveDbConnectionForceMaster::ON_TCL);
         case TDbStatementClassification::DDL:
         case TDbStatementClassification::DML:
         case TDbStatementClassification::DCL:
         case TDbStatementClassification::UNKNOWN:
         default:
             $bMaster = true;
             break;
     }
     $bMaster = $bMaster || $this->getForceMaster();
     $result = new TDistributedDbCommand($bMaster ? $this->getMasterConnection() : $this, $sql, $classification);
     if ($bEnqueue) {
         $this->getMasterConnection()->getStatementQueue()->enqueue($result);
     }
     return $result;
 }