<commit_before><?php

/**
 * Used to build query strings using OOP
 */
class Query {
	const ACTION_COUNT = 'COUNT';
	const ACTION_DELETE = 'DELETE';
	const ACTION_SELECT = 'SELECT';

	// Comparison types
	const EQUAL = '=';
	const NOT_EQUAL = '<>';
	const ALT_NOT_EQUAL = '!=';
	const GREATER_THAN = '>';
	const LESS_THAN = '<';
	const GREATER_EQUAL = '>=';
	const LESS_EQUAL = '<=';
	const LIKE = 'LIKE';
	const NOT_LIKE = 'NOT LIKE';
	const CUSTOM = 'CUSTOM';
	const DISTINCT = 'DISTINCT';
	const IN = 'IN';
	const NOT_IN = 'NOT IN';
	const ALL = 'ALL';
	const IS_NULL = 'IS NULL';
	const IS_NOT_NULL = 'IS NOT NULL';
	const BETWEEN = 'BETWEEN';

	// Comparison type for update
	const CUSTOM_EQUAL = 'CUSTOM_EQUAL';

	// PostgreSQL comparison types
	const ILIKE = 'ILIKE';
	const NOT_ILIKE = 'NOT ILIKE';

	// JOIN TYPES
	const JOIN = 'JOIN';
	const LEFT_JOIN = 'LEFT JOIN';
	const RIGHT_JOIN = 'RIGHT JOIN';
	const INNER_JOIN = 'INNER JOIN';
	const OUTER_JOIN = 'OUTER JOIN';

	// Binary AND
	const BINARY_AND = '&';

	// Binary OR
	const BINARY_OR = '|';

	// 'Order by' qualifiers
	const ASC = 'ASC';
	const DESC = 'DESC';

	private $_action = self::ACTION_SELECT;
	/**
	 * @var array
	 */
	private $_columns = array();
	/**
	 * @var mixed
	 */
	private $_table;
	/**
	 * @var string
	 */
	private $_tableAlias;
	/**
	 * @var array
	 */
	private $_extraTables = array();
	/**
	 * @var QueryJoin[]
	 */
	private $_joins = array();
	/**
	 * @var Condition
	 */
	private $_where;
	/**
	 * @var array
	 */
	private $_orders = array();
	/**
	 * @var array
	 */
	private $_groups = array();
	/**
	 * @var Condition
	 */
	private $_having;
	/**
	 * @var int
	 */
	private $_limit;
	/**
	 * @var int
	 */
	private $_offset = 0;
	/**
	 * @var bool
	 */
	private $_distinct = false;

	/**
	 * Creates new instance of Query, parameters will be passed to the
	 * setTable() method.
	 * @return self
	 * @param $table_name Mixed[optional]
	 * @param $alias String[optional]
	 */
	function __construct($table_name = null, $alias = null) {
		$this->setWhere(new Condition);
		$this->setTable($table_name, $alias);
		return $this;
	}

	function __clone() {
		if ($this->_where instanceof Condition) {
			$this->_where = clone $this->_where;
		}
		if ($this->_having instanceof Condition) {
			$this->_having = clone $this->_having;
		}
		foreach ($this->_joins as $key => $join) {
			$this->_joins[$key] = clone $join;
		}
	}

	/**
	 * Returns new instance of self by passing arguments directly to constructor.
	 * @param mixed $table_name
	 * @param string $alias
	 * @return Query
	 */
	static function create($table_name = null, $alias = null) {
		return new self($table_name, $alias);
	}

	/**
	 * Specify whether to select only distinct rows
	 * @param Bool $bool
	 */
	function setDistinct($bool = true) {
		$this->_distinct = (bool) $bool;
	}

	/**
	 * Sets the action of the query.  Should be SELECT, DELETE, or COUNT.
	 * @return Query
	 * @param $action String
	 */
	function setAction($action) {
		$this->_action = $action;
		return $this;
	}

	/**
	 * Returns the action of the query.  Should be SELECT, DELETE, or COUNT.
	 * @return String
	 */
	function getAction() {
		return $this->_action;
	}

	/**
	 * Add a column to the list of columns to select.  If unused, defaults to *.
	 *
	 * {@example libraries/dabl/database/query/Query_addColumn.php}
	 *
	 * @param String $column_name
	 * @return Query
	 */
	function addColumn($column_name) {
		$this->_columns[$column_name] = $column_name;
		return $this;
	}

	/**
	 * Set array of strings of columns to be selected<commit_msg>column aliases<commit_after><?php

/**
 * Used to build query strings using OOP
 */
class Query {
	const ACTION_COUNT = 'COUNT';
	const ACTION_DELETE = 'DELETE';
	const ACTION_SELECT = 'SELECT';

	// Comparison types
	const EQUAL = '=';
	const NOT_EQUAL = '<>';
	const ALT_NOT_EQUAL = '!=';
	const GREATER_THAN = '>';
	const LESS_THAN = '<';
	const GREATER_EQUAL = '>=';
	const LESS_EQUAL = '<=';
	const LIKE = 'LIKE';
	const NOT_LIKE = 'NOT LIKE';
	const CUSTOM = 'CUSTOM';
	const DISTINCT = 'DISTINCT';
	const IN = 'IN';
	const NOT_IN = 'NOT IN';
	const ALL = 'ALL';
	const IS_NULL = 'IS NULL';
	const IS_NOT_NULL = 'IS NOT NULL';
	const BETWEEN = 'BETWEEN';

	// Comparison type for update
	const CUSTOM_EQUAL = 'CUSTOM_EQUAL';

	// PostgreSQL comparison types
	const ILIKE = 'ILIKE';
	const NOT_ILIKE = 'NOT ILIKE';

	// JOIN TYPES
	const JOIN = 'JOIN';
	const LEFT_JOIN = 'LEFT JOIN';
	const RIGHT_JOIN = 'RIGHT JOIN';
	const INNER_JOIN = 'INNER JOIN';
	const OUTER_JOIN = 'OUTER JOIN';

	// Binary AND
	const BINARY_AND = '&';

	// Binary OR
	const BINARY_OR = '|';

	// 'Order by' qualifiers
	const ASC = 'ASC';
	const DESC = 'DESC';

	private $_action = self::ACTION_SELECT;
	/**
	 * @var array
	 */
	private $_columns = array();
	/**
	 * @var mixed
	 */
	private $_table;
	/**
	 * @var string
	 */
	private $_tableAlias;
	/**
	 * @var array
	 */
	private $_extraTables = array();
	/**
	 * @var QueryJoin[]
	 */
	private $_joins = array();
	/**
	 * @var Condition
	 */
	private $_where;
	/**
	 * @var array
	 */
	private $_orders = array();
	/**
	 * @var array
	 */
	private $_groups = array();
	/**
	 * @var Condition
	 */
	private $_having;
	/**
	 * @var int
	 */
	private $_limit;
	/**
	 * @var int
	 */
	private $_offset = 0;
	/**
	 * @var bool
	 */
	private $_distinct = false;

	/**
	 * Creates new instance of Query, parameters will be passed to the
	 * setTable() method.
	 * @return self
	 * @param $table_name Mixed[optional]
	 * @param $alias String[optional]
	 */
	function __construct($table_name = null, $alias = null) {
		$this->setWhere(new Condition);
		$this->setTable($table_name, $alias);
		return $this;
	}

	function __clone() {
		if ($this->_where instanceof Condition) {
			$this->_where = clone $this->_where;
		}
		if ($this->_having instanceof Condition) {
			$this->_having = clone $this->_having;
		}
		foreach ($this->_joins as $key => $join) {
			$this->_joins[$key] = clone $join;
		}
	}

	/**
	 * Returns new instance of self by passing arguments directly to constructor.
	 * @param mixed $table_name
	 * @param string $alias
	 * @return Query
	 */
	static function create($table_name = null, $alias = null) {
		return new self($table_name, $alias);
	}

	/**
	 * Specify whether to select only distinct rows
	 * @param Bool $bool
	 */
	function setDistinct($bool = true) {
		$this->_distinct = (bool) $bool;
	}

	/**
	 * Sets the action of the query.  Should be SELECT, DELETE, or COUNT.
	 * @return Query
	 * @param $action String
	 */
	function setAction($action) {
		$this->_action = $action;
		return $this;
	}

	/**
	 * Returns the action of the query.  Should be SELECT, DELETE, or COUNT.
	 * @return String
	 */
	function getAction() {
		return $this->_action;
	}

	/**
	 * Add a column to the list of columns to select.  If unused, defaults to *.
	 *
	 * {@example libraries/dabl/database/query/Query_addColumn.php}
	 *
	 * @param String $column_name
	 * @return Query
	 */
	function addColumn($column_name, $alias = null) {
		if ($alias) {
			$column_name .= 'AS ' . $alias;
		}
		$this->_columns[$column_name] = $column_name;
		return $this;
	}

	/**
	 * Set array of strings of columns to be selected
{'fraction_non_alphanumeric': 0.15456933499239597, 'fraction_numerical': 0.00027651043826904464, 'mean_word_length': 3.152698048220436, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, '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': '1068943', 'n_tokens_mistral': 2714, 'n_tokens_neox': 2463, 'n_words': 729}