Merge branch 'datasource-enabled' into 1.2

This commit is contained in:
mark_story 2009-10-20 16:19:45 -04:00
commit 02df92a3a3
12 changed files with 97 additions and 2 deletions

View file

@ -364,6 +364,16 @@ class DataSource extends Object {
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)
*

View file

@ -102,7 +102,9 @@ class DboAdodb extends DboSource {
$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 @@ class DboAdodb extends DboSource {
$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.
*

View file

@ -136,6 +136,14 @@ class DboDb2 extends DboSource {
}
return $this->connected;
}
/**
* Check that the DB2 extension is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('ibm_db2');
}
/**
* Disconnects from database.
*

View file

@ -127,9 +127,18 @@ class DboFirebird extends DboSource {
$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.
*

View file

@ -152,6 +152,14 @@ class DboMssql extends DboSource {
}
return $this->connected;
}
/**
* Check that MsSQL is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('mssql');
}
/**
* Disconnects from database.
*

View file

@ -388,6 +388,14 @@ class DboMysql extends DboMysqlBase {
return $this->connected;
}
/**
* Check whether the MySQL extension is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('mysql');
}
/**
* Disconnects from database.
*

View file

@ -83,6 +83,14 @@ class DboMysqli extends DboMysqlBase {
}
return $this->connected;
}
/**
* Check that MySQLi is installed/enabled
*
* @return boolean
**/
function enabled() {
return extension_loaded('mysqli');
}
/**
* Disconnects from database.
*

View file

@ -105,6 +105,14 @@ class DboOdbc extends DboSource {
return $this->connected;
}
/**
* Check if the ODBC extension is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('odbc');
}
/**
* Disconnects from database.
*

View file

@ -122,6 +122,14 @@ class DboPostgres extends DboSource {
}
return $this->connected;
}
/**
* Check if PostgreSQL is enabled/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('pgsql');
}
/**
* Disconnects from database.
*

View file

@ -113,6 +113,14 @@ class DboSqlite extends DboSource {
}
return $this->connected;
}
/**
* Check that SQLite is enabled/installed
*
* @return boolean
**/
function enabled() {
return extension_loaded('sqlite');
}
/**
* Disconnects from database.
*

View file

@ -102,6 +102,14 @@ class DboSybase extends DboSource {
$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.
*

View file

@ -91,7 +91,9 @@ class DboSource extends DataSource {
}
parent::__construct($config);
$this->fullDebug = Configure::read() > 1;
if (!$this->enabled()) {
return false;
}
if ($autoConnect) {
return $this->connect();
} else {