09-30-2019, 07:04 AM
Hi,
I use the $this->db->select second parameters, to disable protect in my subquery,
so the subquery string would not contain quotes. Ex:
But if I put my subquery into second select's 'from' function (Ex: $this->db->from('('.$subquery.')' AS Foo) ),
my query string will contain quotes.
I found in the from function of the query builder class, a $this->protect_identifiers function with fix third parameters (NULL).
If I change the original NULL value to FALSE, the query will works properly.
My solution:
My question: Is there another way to fix the error, without modifying the core code?
Thanks, Steve
I use the $this->db->select second parameters, to disable protect in my subquery,
so the subquery string would not contain quotes. Ex:
Code:
$this->db->select('col1, col2, col3, col4', FALSE);
...
...
$subquery = $this->db->get_compiled_select();
But if I put my subquery into second select's 'from' function (Ex: $this->db->from('('.$subquery.')' AS Foo) ),
my query string will contain quotes.
I found in the from function of the query builder class, a $this->protect_identifiers function with fix third parameters (NULL).
If I change the original NULL value to FALSE, the query will works properly.
My solution:
Code:
public function from($from, $protected = NULL)
{
foreach ((array) $from as $val)
{
if (strpos($val, ',') !== FALSE)
{
foreach (explode(',', $val) as $v)
{
$v = trim($v);
$this->_track_aliases($v);
$this->qb_from[] = $v = $this->protect_identifiers($v, TRUE, $protected, FALSE);
if ($this->qb_caching === TRUE)
{
$this->qb_cache_from[] = $v;
$this->qb_cache_exists[] = 'from';
}
}
}
else
{
$val = trim($val);
$this->_track_aliases($val);
$this->qb_from[] = $val = $this->protect_identifiers($val, TRUE, $protected, FALSE);
if ($this->qb_caching === TRUE)
{
$this->qb_cache_from[] = $val;
$this->qb_cache_exists[] = 'from';
}
}
}
return $this;
}
My question: Is there another way to fix the error, without modifying the core code?
Thanks, Steve