<commit_before><?php namespace System\DB\Query;

class Compiler {

	/**
	 * Build a SQL SELECT statement.
	 *
	 * @param  Query  $query
	 * @return string
	 */
	public static function select($query)
	{
		// ----------------------------------------------------
		// Add the SELECT, FROM, and WHERE clause to the query.
		// ----------------------------------------------------
		$sql = $query->select.' '.$query->from.' '.$query->where;

		// ----------------------------------------------------
		// Add the ORDER BY clause to the query.
		// ----------------------------------------------------
		if (count($query->orderings) > 0)
		{
			$sql .= ' ORDER BY '.implode(', ', $query->orderings);
		}

		// ----------------------------------------------------
		// Add the LIMIT clause to the query.
		// ----------------------------------------------------
		if ( ! is_null($query->limit))
		{
			$sql .= ' LIMIT '.$query->limit;
		}

		// ----------------------------------------------------
		// Add the OFFSET clause to the query.
		// ----------------------------------------------------
		if ( ! is_null($query->offset))
		{
			$sql .= ' OFFSET '.$query->offset;
		}

		return $sql;
	}

	/**
	 * Build a SQL INSERT statement.
	 *
	 * @param  Query   $query
	 * @param  array   $values
	 * @return string
	 */
	public static function insert($query, $values)
	{
		// -----------------------------------------------------
		// Begin the INSERT statement.
		// -----------------------------------------------------
		$sql = 'INSERT INTO '.$query->table.' (';

		// ----------------------------------------------------
		// Wrap each column name in keyword identifiers.
		// ----------------------------------------------------
		$columns = array();

		foreach (array_keys($values) as $column)
		{
			$columns[] = $query->wrap($column);
		}

		// -----------------------------------------------------
		// Concatenante the columns and values to the statement.
		// -----------------------------------------------------
		return $sql .= implode(', ', $columns).') VALUES ('.$query->parameterize($values).')';
	}

	/**
	 * Build a SQL UPDATE statement.
	 *
	 * @param  Query   $query
	 * @param  array   $values
	 * @return string
	 */
	public static function update($query, $values)
	{
		// ----------------------------------------------------
		// Initialize the UPDATE statement.
		// ----------------------------------------------------
		$sql = 'UPDATE '.$query->table.' SET ';

		// ---------------------------------------------------
		// Add each column set the statement.
		// ---------------------------------------------------
		$columns = array();

		foreach (array_keys($values) as $column)
		{
			$columns[] = $query->wrap($column).' = ?';
		}

		// ---------------------------------------------------
		// Concatenate the SETs to the statement.
		// ---------------------------------------------------
		return $sql .= implode(', ', $columns).' '.$query->where;		
	}

	/**
	 * Build a SQL DELETE statement.
	 *
	 * @param  Query  $query
	 * @return string
	 */
	public static function delete($query)
	{
		return 'DELETE FROM '.$query->wrap($query->table).' '.$query->where;
	}

}<commit_msg>Refactor Query\Compiler.<commit_after><?php namespace System\DB\Query;

class Compiler {

	/**
	 * Build a SQL SELECT statement.
	 *
	 * @param  Query  $query
	 * @return string
	 */
	public static function select($query)
	{
		$sql = $query->select.' '.$query->from.' '.$query->where;

		if (count($query->orderings) > 0)
		{
			$sql .= ' ORDER BY '.implode(', ', $query->orderings);
		}

		if ( ! is_null($query->limit))
		{
			$sql .= ' LIMIT '.$query->limit;
		}

		if ( ! is_null($query->offset))
		{
			$sql .= ' OFFSET '.$query->offset;
		}

		return $sql;
	}

	/**
	 * Build a SQL INSERT statement.
	 *
	 * @param  Query   $query
	 * @param  array   $values
	 * @return string
	 */
	public static function insert($query, $values)
	{
		$sql = 'INSERT INTO '.$query->wrap($query->table);

		$columns = array();

		foreach (array_keys($values) as $column)
		{
			$columns[] = $query->wrap($column);
		}

		return $sql .= ' ('.implode(', ', $columns).') VALUES ('.$query->parameterize($values).')';
	}

	/**
	 * Build a SQL UPDATE statement.
	 *
	 * @param  Query   $query
	 * @param  array   $values
	 * @return string
	 */
	public static function update($query, $values)
	{
		$sql = 'UPDATE '.$query->wrap($query->table).' SET ';

		$sets = array();

		foreach (array_keys($values) as $column)
		{
			$sets[] = $query->wrap($column).' = ?';
		}

		return $sql .= implode(', ', $sets).' '.$query->where;		
	}

	/**
	 * Build a SQL DELETE statement.
	 *
	 * @param  Query  $query
	 * @return string
	 */
	public static function delete($query)
	{
		return 'DELETE FROM '.$query->wrap($query->table).' '.$query->where;
	}

}
{'fraction_non_alphanumeric': 0.36627304744147504, 'fraction_numerical': 0.0004143360265175057, 'mean_word_length': 1.2656030032848429, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '7031562', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1312, 'n_words': 334}