lithium\data\source\Database::_conditions()

protected method

Returns a string of formatted conditions to be inserted into the query statement.

If the query conditions are defined as an array, key pairs are converted to SQL strings. If $key is numeric and $value is a string, $value is treated as a literal SQL fragment and returned.

Parameters

  • string|array $conditions

    The conditions for this query.

  • object $context

    The current lithium\data\model\Query instance.

  • array $options

    Available options are:

    • 'prepend' boolean|string: The string to prepend or false for no prepending. Defaults to false.

Returns

string

Returns an SQL conditions clause.

Source

	protected function _conditions($conditions, $context, array $options = []) {
		$defaults = ['prepend' => false];
		$options += $defaults;

		switch (true) {
			case empty($conditions):
				return '';
			case is_string($conditions):
				return $options['prepend'] ? $options['prepend'] . " {$conditions}" : $conditions;
			case !is_array($conditions):
				return '';
		}
		$result = [];

		foreach ($conditions as $key => $value) {
			$return = $this->_processConditions($key, $value, $context);

			if ($return) {
				$result[] = $return;
			}
		}
		$result = join(" AND ", $result);
		return ($options['prepend'] && $result) ? $options['prepend'] . " {$result}" : $result;
	}