Make connection exceptions more helpful.

Fixes #3204
This commit is contained in:
mark_story 2012-09-12 22:31:07 -04:00
parent 99a9cc9669
commit fb9360767e
7 changed files with 27 additions and 8 deletions

View file

@ -149,7 +149,10 @@ class Mysql extends DboSource {
);
$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", ">=");

View file

@ -121,7 +121,10 @@ class Postgres extends DboSource {
$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;

View file

@ -113,7 +113,10 @@ class Sqlite extends DboSource {
$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;
}

View file

@ -129,7 +129,10 @@ class Sqlserver extends DboSource {
);
$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;

View file

@ -253,6 +253,7 @@ class DboSource extends DataSource {
if (!$this->enabled()) {
throw new MissingConnectionException(array(
'class' => get_class($this),
'message' => __d('cake_dev', 'Selected driver is not enabled'),
'enabled' => false
));
}

View file

@ -552,10 +552,10 @@ class ExceptionRendererTest extends CakeTestCase {
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
),
@ -563,7 +563,7 @@ class ExceptionRendererTest extends CakeTestCase {
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

View file

@ -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">