* Framework - Improved support for dabase-specific quotes - Added support for pre-quoted table/database references
/trunk/Db/MySQLDB.php |
---|
33,6 → 33,18 |
*/ |
protected $_charset = null; |
/** |
* (non-PHPdoc) |
* @see Database::_leftQuote |
*/ |
protected $_leftQuote = '`'; |
/** |
* (non-PHPdoc) |
* @see Database::_rightQuote |
*/ |
protected $_rightQuote = '`'; |
public function __construct() |
{ |
$this->_dsn = "mysql:host={$this->_host}" |
46,40 → 58,4 |
parent::__construct(); |
} |
/** |
* Escapes a database name so that it can be used in a query. |
* |
* @param string $name |
* The name to be escaped |
* @return string |
* The escaped name |
*/ |
public function escapeName($name) |
{ |
return '`' . $name . '`'; |
} |
/** |
* (non-PHPdoc) |
* @see Database::_escapeAliasArray() |
*/ |
protected function _escapeAliasArray(array &$array) |
{ |
foreach ($array as $column => &$value) |
{ |
$value = $value . ' AS `' . $column . '`'; |
} |
return $array; |
} |
/** |
* (non-PHPdoc) |
* @see Database::_escapeValueArray() |
*/ |
protected function _escapeValueArray(array &$array, $suffix = '', array &$escape = array('`', '`')) |
{ |
return parent::_escapeValueArray($array, $suffix, $escape); |
} |
} |
/trunk/Db/ODBCDB.php |
---|
10,6 → 10,18 |
*/ |
protected $_alias; |
/** |
* (non-PHPdoc) |
* @see Database::_leftQuote |
*/ |
protected $_leftQuote = '['; |
/** |
* (non-PHPdoc) |
* @see Database::_rightQuote |
*/ |
protected $_rightQuote = ']'; |
public function __construct() |
{ |
// $this->_connection = @odbc_connect($this->_alias, $this->_username, $this->_password); |
16,13 → 28,4 |
$this->_dsn = 'odbc:' . $this->_alias; |
parent::__construct(); |
} |
/** |
* (non-PHPdoc) |
* @see Database::_escapeValueArray() |
*/ |
protected function _escapeValueArray(array &$array, $suffix = '', array &$escape = array('`', '`')) |
{ |
return parent::_escapeValueArray($array, $suffix, $escape); |
} |
} |
/trunk/Db/Database.php |
---|
21,6 → 21,8 |
*/ |
class Database extends AbstractModel |
{ |
/* Access properties */ |
/** |
* DSN of the database |
* @var string |
44,8 → 46,26 |
* @var array |
*/ |
protected $_options = array(); |
/** |
* Database-specific string to use for quoting a name or value |
* left-hand side (for security reasons and to prevent a name |
* from being parsed as a keyword). |
* @var string |
*/ |
protected $_leftQuote = ''; |
/** |
* Database-specific string to use for quoting a name or value |
* left-hand side (for security reasons and to prevent a name |
* from being parsed as a keyword). |
* @var string |
*/ |
protected $_rightQuote = ''; |
/* Status properties */ |
/** |
* Database connection |
* @var PDO |
*/ |
145,7 → 165,7 |
*/ |
public function escapeName($name) |
{ |
return $name; |
return $this->_leftQuote . $name . $this->_rightQuote; |
} |
/** |
183,7 → 203,14 |
{ |
foreach ($array as $column => &$value) |
{ |
$value = $value . ' AS ' . $column; |
$quotedColumn = $column; |
if (strpos($column, $this->_leftQuote) === false |
&& strpos($column, $this->_rightQuote) === false) |
{ |
$quotedColumn = $this->_leftQuote . $column . $this->_rightQuote; |
} |
$value = $value . ' AS ' . $quotedColumn; |
} |
return $array; |
228,7 → 255,7 |
* @return array |
* The escaped array |
*/ |
protected function _escapeValueArray(array &$array, $suffix = '', array &$escape = array('', '')) |
protected function _escapeValueArray(array &$array, $suffix = '') |
{ |
$result = array(); |
250,7 → 277,7 |
$placeholder = '(' . implode(',', self::_expand($value, $column)) . ')'; |
} |
$result[] = $escape[0] . $column . $escape[1] . "{$op}{$placeholder}{$suffix}"; |
$result[] = $this->_leftQuote . $column . $this->_rightQuote . "{$op}{$placeholder}{$suffix}"; |
} |
return $result; |