Skip to content
Permalink
Browse files

Adding Datasource::enabled()

Allows for checking a datasource's ability to be used before attempting to connect it.
Added enabled() to all the core dbo's.
Fixes whitescreen when trying to use a non installed database driver.
Fixes #131
  • Loading branch information...
markstory committed Oct 20, 2009
1 parent 0a79822 commit 072e1efc130fed9443783910fd6c4ddf884f40d3
@@ -364,6 +364,16 @@ function lastNumRows($source = null) {
function lastAffected($source = null) {
return false;
}
/**
* Check whether the conditions for the Datasource being available
* are satisfied. Often used from connect() to check for support
* before establishing a connection.
*
* @return boolean Whether or not the Datasources conditions for use are met.
**/
function enabled() {
return true;
}
/**
* Returns true if the DataSource supports the given interface (method)
*
@@ -102,7 +102,9 @@ function connect() {
$adodb_driver = substr($config['connect'], 0, $persistent);
$connect = 'PConnect';
}
if (!$this->enabled()) {
return false;
}
$this->_adodb = NewADOConnection($adodb_driver);
$this->_adodbDataDict = NewDataDictionary($this->_adodb, $adodb_driver);
@@ -114,6 +116,14 @@ function connect() {
$this->_adodbMetatyper = &$this->_adodb->execute('Select 1');
return $this->connected;
}
/**
* Check that AdoDB is available.
*
* @return boolean
**/
function enabled() {
return function_exists('NewADOConnection');
}
/**
* Disconnects from database.
*
@@ -136,6 +136,14 @@ function connect() {
}
return $this->connected;
}
/**
* Check that the DB2 extension is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('ibm_db2');
}
/**
* Disconnects from database.
*
@@ -127,9 +127,18 @@ function connect() {
$connect = $config['connect'];
$this->connected = false;
$this->connection = $connect($config['host'] . ':' . $config['database'], $config['login'], $config['password']);
$this->connected = true;
}
/**
* Check that the interbase extension is loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('interbase');
}
/**
* Disconnects from database.
*
@@ -152,6 +152,14 @@ function connect() {
}
return $this->connected;
}
/**
* Check that MsSQL is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('mssql');
}
/**
* Disconnects from database.
*
@@ -388,6 +388,14 @@ function connect() {
return $this->connected;
}
/**
* Check whether the MySQL extension is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('mysql');
}
/**
* Disconnects from database.
*
@@ -83,6 +83,14 @@ function connect() {
}
return $this->connected;
}
/**
* Check that MySQLi is installed/enabled
*
* @return boolean
**/
function enabled() {
return extension_loaded('mysqli');
}
/**
* Disconnects from database.
*
@@ -105,6 +105,14 @@ function connect() {
return $this->connected;
}
/**
* Check if the ODBC extension is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('odbc');
}
/**
* Disconnects from database.
*
@@ -122,6 +122,14 @@ function connect() {
}
return $this->connected;
}
/**
* Check if PostgreSQL is enabled/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('pgsql');
}
/**
* Disconnects from database.
*
@@ -113,6 +113,14 @@ function connect() {
}
return $this->connected;
}
/**
* Check that SQLite is enabled/installed
*
* @return boolean
**/
function enabled() {
return extension_loaded('sqlite');
}
/**
* Disconnects from database.
*
@@ -102,6 +102,14 @@ function connect() {
$this->connected = sybase_select_db($config['database'], $this->connection);
return $this->connected;
}
/**
* Check that one of the sybase extensions is installed
*
* @return boolean
**/
function enabled() {
return extension_loaded('sybase') || extension_loaded('sybase_ct');
}
/**
* Disconnects from database.
*
@@ -91,7 +91,9 @@ function __construct($config = null, $autoConnect = true) {
}
parent::__construct($config);
$this->fullDebug = Configure::read() > 1;
if (!$this->enabled()) {
return false;
}
if ($autoConnect) {
return $this->connect();
} else {

0 comments on commit 072e1ef

Please sign in to comment.
You can’t perform that action at this time.