Driver_Database_Driver_MySQL::_quote_identifier
null Driver_Database_Driver_MySQL::_quote_identifier( )
File: ./drivers/database/mysql/mysql.class.php
protected function _quote_identifier($column)
{
if (is_array($column))
{
list($column, $alias) = $column;
}
if (is_object($column))
{
if ($column instanceof Database)
{
// Create a sub-query
$column = '(' . $column->compile() . ')';
}
elseif ($column instanceof Database_Expression)
{
// Use a raw expression
$column = $column->value();
}
else
{
// Convert the object to a string
$column = $this->_quote_identifier((string)$column);
}
}
else
{
转换为字符串
$column = trim((string)$column);
if (preg_match('#^(.*) AS (.*)$#i', $column, $m))
{
$column = $m[1];
$alias = $m[2];
}
if ($column === '*')
{
return $column;
}
elseif (strpos($column, '"') !== false)
{
// Quote the column in FUNC("column") identifiers
$column = preg_replace('/"(.+?)"/e', '$this->_quote_identifier("$1")', $column);
}
elseif (strpos($column, '.') !== false)
{
$parts = explode('.', $column);
$prefix = $this->config['table_prefix'];
if ($prefix)
{
// Get the offset of the table name, 2nd-to-last part
$offset = count($parts) - 2;
if (!$this->_as_table || !in_array($parts[$offset], $this->_as_table))
{
$parts[$offset] = $prefix . $parts[$offset];
}
}
foreach ($parts as & $part)
{
if ($part !== '*')
{
// Quote each of the parts
$this->_change_charset($part);
$part = $this->_identifier . str_replace($this->_identifier, '', $part) . $this->_identifier;
}
}
$column = implode('.', $parts);
}
else
{
$this->_change_charset($column);
$column = $this->_identifier . str_replace($this->_identifier, '', $column) . $this->_identifier;
}
}
if (isset($alias))
{
$this->_change_charset($alias);
column .= ' AS ' . $this->_identifier . str_replace($this->_identifier, '', $alias) . $this->_identifier;
}
return $column;
}