<commit_before><?php
namespace wcf\system\database\util;
use wcf\system\exception\SystemException;

/**
 * Builds a sql query 'where' condition for prepared statements.
 *
 * @author	<NAME>
 * @copyright	2001-2011 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.woltlab.wcf
 * @subpackage	system.database.util
 * @category 	Community Framework
 */
class PreparedStatementConditionBuilder extends ConditionBuilder {
	/**
	 * input parameters
	 * @var array
	 */
	protected $parameters = array();
	
	/**
	 * Adds a new condition.
	 * 
	 * @param	string		$condition
	 * @param	array		$parameters
	 */
	public function add($condition, array $parameters = array()) {
		if (count($parameters)) {
			$count = 0;
			$callback = function ($matches) use (&$count, $parameters) {
				if (!isset($parameters[$count])) {
					throw new SystemException();
				}

				$result = '?';
				if (is_array($parameters[$count]) && count($parameters[$count])) {
					$result .= str_repeat(',?', count($parameters[$count]) - 1);
				}
				
				$count++;
				return $result;
			};
			
			$condition = preg_replace_callback('/\?/', $callback, $condition);
		}
		
		// add condtion
		if (!empty($this->conditions)) $this->conditions .= " AND ";
		else $this->conditions = ($this->addWhereKeyword ? " WHERE " : '');
		$this->conditions .= $condition;
		
		// parameter handling
		if (count($parameters)) {
			foreach ($parameters as $parameter) {<commit_msg>Fixed multiple issues in PreparedStatementConditionBuilder - added missing exception message - replaced the usage of isset with array_key_exists<commit_after><?php
namespace wcf\system\database\util;
use wcf\system\exception\SystemException;

/**
 * Builds a sql query 'where' condition for prepared statements.
 *
 * @author	<NAME>
 * @copyright	2001-2011 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.woltlab.wcf
 * @subpackage	system.database.util
 * @category 	Community Framework
 */
class PreparedStatementConditionBuilder extends ConditionBuilder {
	/**
	 * input parameters
	 * @var array
	 */
	protected $parameters = array();
	
	/**
	 * Adds a new condition.
	 * 
	 * @param	string		$condition
	 * @param	array		$parameters
	 */
	public function add($condition, array $parameters = array()) {
		if (count($parameters)) {
			$count = 0;
			$callback = function ($matches) use (&$count, $parameters, $condition) {
				if (!array_key_exists($count, $parameters)) {
					throw new SystemException("missing parameter for token number " . ($count + 1) . " in condition '".$condition."'");
				}

				$result = '?';
				if (is_array($parameters[$count]) && count($parameters[$count])) {
					$result .= str_repeat(',?', count($parameters[$count]) - 1);
				}
				
				$count++;
				return $result;
			};
			
			$condition = preg_replace_callback('/\?/', $callback, $condition);
		}
		
		// add condtion
		if (!empty($this->conditions)) $this->conditions .= " AND ";
		else $this->conditions = ($this->addWhereKeyword ? " WHERE " : '');
		$this->conditions .= $condition;
		
		// parameter handling
		if (count($parameters)) {
			foreach ($parameters as $parameter) {
{'fraction_non_alphanumeric': 0.15606758832565285, 'fraction_numerical': 0.0064516129032258064, 'mean_word_length': 3.69164265129683, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3755876', 'n_tokens_mistral': 1116, 'n_tokens_neox': 945, 'n_words': 248}