Commit b3b8fadf by Qiang Xue

minor adjustment of db exception.

parent 8c7b1efa
...@@ -134,7 +134,7 @@ class Command extends \yii\base\Component ...@@ -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 ...@@ -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 ...@@ -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());
} }
} }
......
...@@ -320,7 +320,7 @@ class Connection extends Component ...@@ -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 ...@@ -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());
} }
} }
} }
......
...@@ -24,13 +24,14 @@ class Exception extends \yii\base\Exception ...@@ -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);
} }
/** /**
......
...@@ -52,7 +52,7 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -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'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment