Throw an exception in IdoQuery::getCustomvarColumnName() in case the custom variable has not been joined

Queries extending IdoQuery and using the method getCustomvarColumnName() must be notified in case the custom variable has not been joined.

refs #9692
This commit is contained in:
Eric Lippmann 2015-07-22 12:00:59 +02:00
parent 3ed13366a8
commit 15cb24c6dc
2 changed files with 8 additions and 6 deletions

View File

@ -4,7 +4,7 @@
namespace Icinga\Exception; namespace Icinga\Exception;
/** /**
* Exception thrown if a query contains invalid parameters * Exception thrown if a query encountered an error
*/ */
class QueryException extends IcingaException class QueryException extends IcingaException
{ {

View File

@ -12,6 +12,7 @@ use Icinga\Data\Filter\FilterExpression;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
use Icinga\Exception\NotImplementedError; use Icinga\Exception\NotImplementedError;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Exception\QueryException;
use Icinga\Web\Session; use Icinga\Web\Session;
/** /**
@ -870,18 +871,19 @@ abstract class IdoQuery extends DbQuery
} }
/** /**
* Get the query column of a custom variable or null in case the custom variable has not been joined * Get the query column of a already joined custom variable
* *
* @param string $customvar * @param string $customvar
* *
* @return null|string * @return string
* @throws QueryException If the custom variable has not been joined
*/ */
protected function getCustomvarColumnName($customvar) protected function getCustomvarColumnName($customvar)
{ {
if (isset($this->customVars[($customvar = strtolower($customvar))])) { if (! isset($this->customVars[($customvar = strtolower($customvar))])) {
return $this->customVars[$customvar] . '.varvalue'; throw new QueryException('Custom variable %s has not been joined', $customvar);
} }
return null; return $this->customVars[$customvar] . '.varvalue';
} }
public function aliasToColumnName($alias) public function aliasToColumnName($alias)