Commit 71a22f1c authored by Dries's avatar Dries

- Patch #337926 by Damien Tournoud: clean-up lower case handling.

parent 8900c615
......@@ -215,7 +215,14 @@ abstract class DatabaseConnection extends PDO {
*
* @var string
*/
protected $statementClass = NULL;
protected $statementClass = 'DatabaseStatementBase';
/**
* Whether this database connection supports transactions.
*
* @var bool
*/
protected $transactionSupport = TRUE;
/**
* The schema object for this connection.
......@@ -225,11 +232,6 @@ abstract class DatabaseConnection extends PDO {
protected $schema = NULL;
function __construct($dsn, $username, $password, $driver_options = array()) {
// Fallback to DatabaseStatementBase if the driver has not specified one.
if (empty($this->statementClass)) {
$this->statementClass = 'DatabaseStatementBase';
}
// Because the other methods don't seem to work right.
$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
......@@ -237,7 +239,7 @@ function __construct($dsn, $username, $password, $driver_options = array()) {
parent::__construct($dsn, $username, $password, $driver_options);
// Set a specific PDOStatement class if the driver requires that.
if ($this->statementClass != 'PDOStatement') {
if (!empty($this->statementClass)) {
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array($this->statementClass, array($this)));
}
}
......@@ -734,7 +736,9 @@ public function startTransaction($required = FALSE) {
/**
* Determine if this driver supports transactions.
*/
abstract public function supportsTransactions();
public function supportsTransactions() {
return $this->transactionSupport;
}
/**
* Returns the type of the database being accessed.
......
......@@ -13,11 +13,14 @@
class DatabaseConnection_mysql extends DatabaseConnection {
protected $transactionSupport = FALSE;
public function __construct(Array $connection_options = array()) {
$this->transactionSupport = isset($connection_options['transactions']) ? $connection_options['transactions'] : FALSE;
$connection_options['port'] = !empty($connection_options['port']) ? $connection_options['port'] : 3306;
// This driver defaults to non transaction support.
$this->transactionSupport = !empty($connection_option['transactions']);
// Default to TCP connection on port 3306.
if (empty($connection_options['port'])) {
$connection_options['port'] = 3306;
}
$dsn = 'mysql:host=' . $connection_options['host'] . ';port=' . $connection_options['port'] . ';dbname=' . $connection_options['database'];
parent::__construct($dsn, $connection_options['username'], $connection_options['password'], array(
......@@ -53,10 +56,6 @@ public function databaseType() {
return 'mysql';
}
public function supportsTransactions() {
return $this->transactionSupport;
}
public function mapConditionOperator($operator) {
// We don't want to override any of the defaults.
return NULL;
......
......@@ -92,7 +92,7 @@ protected function createFieldSql($name, $spec) {
$sql .= ' auto_increment';
}
// $spec['default'] can be NULL, so we explicitely check for the key here.
// $spec['default'] can be NULL, so we explicitly check for the key here.
if (array_key_exists('default', $spec)) {
if (is_string($spec['default'])) {
$spec['default'] = "'" . $spec['default'] . "'";
......
......@@ -13,11 +13,14 @@
class DatabaseConnection_pgsql extends DatabaseConnection {
protected $transactionSupport = TRUE;
public function __construct(Array $connection_options = array()) {
$this->transactionSupport = isset($connection_options['transactions']) ? $connection_options['transactions'] : TRUE;
$connection_options['port'] = !empty($connection_options['port']) ? $connection_options['port'] : 5432;
// This driver defaults to transaction support, except if explicitly passed FALSE.
$this->transactionSupport = !isset($connection_options['transactions']) || $connection_options['transactions'] === FALSE;
// Default to TCP connection on port 5432.
if (empty($connection_options['port'])) {
$connection_options['port'] = 5432;
}
$dsn = 'pgsql:host=' . $connection_options['host'] . ' dbname=' . $connection_options['database'] . ' port=' . $connection_options['port'];
parent::__construct($dsn, $connection_options['username'], $connection_options['password'], array(
......@@ -86,10 +89,6 @@ public function databaseType() {
return 'pgsql';
}
public function supportsTransactions() {
return $this->transactionSupport;
}
public function mapConditionOperator($operator) {
static $specials = array(
// In PostgreSQL, 'LIKE' is case-sensitive. For case-insensitive LIKE
......
......@@ -18,20 +18,14 @@
*/
class DatabaseConnection_sqlite extends DatabaseConnection {
/**
* Indicates that this connection supports transactions.
*
* @var bool
*/
protected $transactionSupport = TRUE;
public function __construct(Array $connection_options = array()) {
// We don't need a specific PDOStatement class here, we simulate it below.
$this->statementClass = 'PDOStatement';
$this->transactionSupport = isset($connection_options['transactions']) ? $connection_options['transactions'] : TRUE;
$this->statementClass = NULL;
$dns = 'sqlite:'. $connection_options['database'];
parent::__construct($dns, '', '', array(
// This driver defaults to transaction support, except if explicitly passed FALSE.
$this->transactionSupport = !isset($connection_options['transactions']) || $connection_options['transactions'] === FALSE;
parent::__construct('sqlite:'. $connection_options['database'], '', '', array(
// Force column names to lower case.
PDO::ATTR_CASE => PDO::CASE_LOWER,
));
......@@ -141,10 +135,6 @@ public function databaseType() {
return 'sqlite';
}
public function supportsTransactions() {
return $this->transactionSupport;
}
public function mapConditionOperator($operator) {
// We don't want to override any of the defaults.
return NULL;
......
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