Browse Source

minor adjustment of db exception.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
b3b8fadfcf
  1. 6
      framework/db/Command.php
  2. 4
      framework/db/Connection.php
  3. 7
      framework/db/Exception.php
  4. 2
      framework/db/mysql/QueryBuilder.php

6
framework/db/Command.php

@ -134,7 +134,7 @@ class Command extends \yii\base\Component
} catch (\Exception $e) { } catch (\Exception $e) {
\Yii::error($e->getMessage() . "\nFailed to prepare SQL: $sql", __CLASS__); \Yii::error($e->getMessage() . "\nFailed to prepare SQL: $sql", __CLASS__);
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
throw new Exception($e->getMessage(), (int)$e->getCode(), $errorInfo); throw new Exception($e->getMessage(), $errorInfo, (int)$e->getCode());
} }
} }
} }
@ -292,7 +292,7 @@ class Command extends \yii\base\Component
\Yii::error("$message\nFailed to execute SQL: {$sql}{$paramLog}", __CLASS__); \Yii::error("$message\nFailed to execute SQL: {$sql}{$paramLog}", __CLASS__);
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
throw new Exception($message, (int)$e->getCode(), $errorInfo); throw new Exception($message, $errorInfo, (int)$e->getCode());
} }
} }
@ -431,7 +431,7 @@ class Command extends \yii\base\Component
$message = $e->getMessage(); $message = $e->getMessage();
\Yii::error("$message\nCommand::$method() failed: {$sql}{$paramLog}", __CLASS__); \Yii::error("$message\nCommand::$method() failed: {$sql}{$paramLog}", __CLASS__);
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
throw new Exception($message, (int)$e->getCode(), $errorInfo); throw new Exception($message, $errorInfo, (int)$e->getCode());
} }
} }

4
framework/db/Connection.php

@ -320,7 +320,7 @@ class Connection extends Component
{ {
if ($this->pdo === null) { if ($this->pdo === null) {
if (empty($this->dsn)) { if (empty($this->dsn)) {
throw new InvalidConfigException('Connection.dsn cannot be empty.'); throw new InvalidConfigException('Connection::dsn cannot be empty.');
} }
try { try {
\Yii::trace('Opening DB connection: ' . $this->dsn, __CLASS__); \Yii::trace('Opening DB connection: ' . $this->dsn, __CLASS__);
@ -330,7 +330,7 @@ class Connection extends Component
catch (\PDOException $e) { catch (\PDOException $e) {
\Yii::error("Failed to open DB connection ({$this->dsn}): " . $e->getMessage(), __CLASS__); \Yii::error("Failed to open DB connection ({$this->dsn}): " . $e->getMessage(), __CLASS__);
$message = YII_DEBUG ? 'Failed to open DB connection: ' . $e->getMessage() : 'Failed to open DB connection.'; $message = YII_DEBUG ? 'Failed to open DB connection: ' . $e->getMessage() : 'Failed to open DB connection.';
throw new Exception($message, (int)$e->getCode(), $e->errorInfo); throw new Exception($message, $e->errorInfo, (int)$e->getCode());
} }
} }
} }

7
framework/db/Exception.php

@ -24,13 +24,14 @@ class Exception extends \yii\base\Exception
/** /**
* Constructor. * Constructor.
* @param string $message PDO error message * @param string $message PDO error message
* @param integer $code PDO error code
* @param mixed $errorInfo PDO error info * @param mixed $errorInfo PDO error info
* @param integer $code PDO error code
* @param \Exception $previous The previous exception used for the exception chaining.
*/ */
public function __construct($message, $code = 0, $errorInfo = null) public function __construct($message, $errorInfo = null, $code = 0, \Exception $previous = null)
{ {
$this->errorInfo = $errorInfo; $this->errorInfo = $errorInfo;
parent::__construct($message, $code); parent::__construct($message, $code, $previous);
} }
/** /**

2
framework/db/mysql/QueryBuilder.php

@ -52,7 +52,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
$quotedTable = $this->db->quoteTableName($table); $quotedTable = $this->db->quoteTableName($table);
$row = $this->db->createCommand('SHOW CREATE TABLE ' . $quotedTable)->queryRow(); $row = $this->db->createCommand('SHOW CREATE TABLE ' . $quotedTable)->queryRow();
if ($row === false) { if ($row === false) {
throw new Exception("Unable to find '$oldName' in table '$table'."); throw new Exception("Unable to find column '$oldName' in table '$table'.");
} }
if (isset($row['Create Table'])) { if (isset($row['Create Table'])) {
$sql = $row['Create Table']; $sql = $row['Create Table'];

Loading…
Cancel
Save