Jump to content

Explicit Select


Rubens Cury

Recommended Posts

I'm was getting trouble sometimes when I defined explicitSelect as true. I decided to investigate the code to try to figure out what I should do different or if anything was not working properly...

 

What I concluded is that the first foreach condition commented by "// Add it only if it is not already in $this->_select" is not doing the right validation to "decide" when skipping to next field_list or not.

 

If you wonder a select string that contains a column like SELECT CONCAT(column_one,  column_two) AS column_formatted (...) you going to notice that if explicitSelect is set true, these foreach conditions will amiss consider that columns one and two are already in $this->_select.

 

It's not true. That columns are not there. They are a part of an expression.

 

Well... the problem is that by doing this conditional code mistake, what is going to happen is that this line "$this->_listsql = rtrim($this->_listsql, ',');" will add a comma separating a blank space from the rest of columns and you going to get a Bad SQL error.

 

Example: SELECT , column_abc, columns_xpt (...)

 

 

 

AdminController.php

			if ($this->explicitSelect)
			{
				foreach ($this->fields_list as $key => $array_value)
				{
					// Add it only if it is not already in $this->_select
					if (isset($this->_select) && preg_match('/[\s]`?'.preg_quote($key, '/').'`?\s*,/', $this->_select))
						continue;

					if (isset($array_value['filter_key']))
						$this->_listsql .= str_replace('!', '.', $array_value['filter_key']).' as '.$key.',';
					elseif ($key == 'id_'.$this->table)
						$this->_listsql .= 'a.`'.bqSQL($key).'`,';
					elseif ($key != 'image' && !preg_match('/'.preg_quote($key, '/').'/i', $this->_select))
						$this->_listsql .= '`'.bqSQL($key).'`,';
				}
				$this->_listsql = rtrim($this->_listsql, ',');
			}
			else
				$this->_listsql .= ($this->lang ? 'b.*,' : '').' a.*';
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...