Permalink
Browse files

Make connection exceptions more helpful.

Fixes #3204
  • Loading branch information...
markstory committed Sep 13, 2012
1 parent 99a9cc9 commit fb9360767ea25281bc0d9761b80e068131a96beb
@@ -149,7 +149,10 @@ public function connect() {
);
$this->connected = true;
} catch (PDOException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => $e->getMessage()
));
}
$this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">=");
@@ -121,7 +121,10 @@ public function connect() {
$this->_execute('SET search_path TO ' . $config['schema']);
}
} catch (PDOException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => $e->getMessage()
));
}
return $this->connected;
@@ -113,7 +113,10 @@ public function connect() {
$this->_connection = new PDO('sqlite:' . $config['database'], null, null, $flags);
$this->connected = true;
} catch(PDOException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => $e->getMessage()
));
}
return $this->connected;
}
@@ -129,7 +129,10 @@ public function connect() {
);
$this->connected = true;
} catch (PDOException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => $e->getMessage()
));
}
return $this->connected;
@@ -253,6 +253,7 @@ public function __construct($config = null, $autoConnect = true) {
if (!$this->enabled()) {
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => __d('cake_dev', 'Selected driver is not enabled'),
'enabled' => false
));
}
@@ -552,18 +552,18 @@ public static function testProvider() {
500
),
array(
new MissingConnectionException(array('class' => 'Article')),
new MissingConnectionException(array('class' => 'Mysql')),
array(
'/<h2>Missing Database Connection<\/h2>/',
'/Article requires a database connection/'
'/A Database connection using "Mysql" was missing or unable to connect./',
),
500
),
array(
new MissingConnectionException(array('class' => 'Mysql', 'enabled' => false)),
array(
'/<h2>Missing Database Connection<\/h2>/',
'/Mysql requires a database connection/',
'/A Database connection using "Mysql" was missing or unable to connect./',
'/Mysql driver is NOT enabled/'
),
500
@@ -19,7 +19,13 @@
<h2><?php echo __d('cake_dev', 'Missing Database Connection'); ?></h2>
<p class="error">
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
<?php echo __d('cake_dev', '%s requires a database connection', $class); ?>
<?php echo __d('cake_dev', 'A Database connection using "%s" was missing or unable to connect. ', $class); ?>
<br />
<?php
if (isset($message)):
echo __d('cake_dev', 'The database server returned this error: %s', $message);
endif;
?>
</p>
<?php if (!$enabled) : ?>
<p class="error">

0 comments on commit fb93607

Please sign in to comment.