protected
function
_quote_identifier(
$column
)
{
if
(
is_array
(
$column
))
{
list(
$column
,
$alias
) =
$column
;
}
if
(
is_object
(
$column
))
{
if
(
$column
instanceof
Database)
{
$column
=
'('
.
$column
->compile() .
')'
;
}
elseif
(
$column
instanceof
Database_Expression)
{
$column
=
$column
->value();
}
else
{
$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)
{
$column
= preg_replace(
'/"(.+?)"/e'
,
'$this->_quote_identifier("$1")'
,
$column
);
}
elseif
(
strpos
(
$column
,
'.'
) !== false)
{
$parts
=
explode
(
'.'
,
$column
);
$prefix
=
$this
->config[
'table_prefix'
];
if
(
$prefix
)
{
$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
!==
'*'
)
{
$this
->_change_charset(
$part
);
$part
=
$this
->_identifier.
str_replace
(
$this
->_identifier,
''
,
$part
).
$this
->_identifier;
}
}
$column
= implode(
'.'
,
$parts
);
lse
$this
->_change_charset(
$column
);
$column
=
$this
->_identifier.
str_replace
(
$this
->_identifier,
''
,
$column
).
$this
->_identifier;
(isset(
$alias
))
$this
->_change_charset(
$alias
);
column .=
' AS '
.
$this
->_identifier.
str_replace
(
$this
->_identifier,
''
,
$alias
).
$this
->_identifier;
return
$column
;
}