<commit_before><?php

trait pudlSelect {


	public function select($col, $table, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function having($col, $table, $clause=false, $having=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_clause($having, 'HAVING');
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function group($col, $table, $clause=false, $group=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_group($group);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function groupHaving($col, $table, $clause=false, $group=false, $having=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_group($group);
		$query .= $this->_clause($having, 'HAVING');
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function orderGroup($col, $table, $clause=false, $group=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= '*, COUNT(*) FROM (SELECT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		if (is_array($limit)) $query .= $this->_limit($limit[0]);
		$query .= ') groupbyorderby';
		$query .= $this->_group($group);
		$query .= $this->_order($order);
		if (is_array($limit))  $query .= $this->_limit($limit[1], $offset);
		else $query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function orderGroupEx($col, $table, $clause=false, $inner_group=false, $outer_group=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= '*, COUNT(*) FROM (SELECT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_group($inner_group);
		$query .= $this->_order($order);
		if (is_array($limit)) $query .= $this->_limit($limit[0]);
		$query .= ') groupbyorderby';
		$query .= $this->_group($outer_group);
		$query .= $this->_order($order);
		if (is_array($limit))  $query .= $this->_limit($limit[1], $offset);
		else $query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function selectJoin($col, $table, $join_table, $join_clause, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_joinTable($join_table);
		$query .= $this->_clause($join_clause, 'ON');
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function distinct($col, $table, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= 'DISTINCT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function distinctGroup($col, $table, $clause=false, $group=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= 'DISTINCT * FROM (SELECT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= ') groupbyorderby';
		$query .= $this->_group($group);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function distinctJoin($col, $table, $join_table, $join_clause, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= 'DISTINCT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_joinTable($join_table);
		$query .= $this->_clause($join_clause, 'ON');
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function selectExplain($col, $table, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this->explain($query);
	}



	public function selex($params) {
		$query = 'SELECT ';
		$query .= $this->_cache();

		if (isset($params['group'])  &&  isset($params['order'])) {
			$query .= ' *, COUNT(*) FROM (SELECT ';
		}

		if (isset($params['limit']))	$query .= $this->_top(   $params['limit']);
		if (isset($params['column']))	$query .= $this->_column($params['column']);
		if (!isset($params['column']))	$query .= '*';
		if (isset($params['table']))	$query .= $this->_tables($params['table']);
		if (isset($params['clause']))	$query .= $this->_clause($params['clause']);

		if (isset($params['group'])  &&  isset($params['order'])) {
			$query .= $this->_order($params['order']);
			$query .= ') groupbyorderby ';
		}

		if (isset($params['group']))	$query .= $this->_group($params['group']);
		if (isset($params['having']))	$query .= $this->_clause($params['having'], 'HAVING');
		if (isset($params['order']))	$query .= $this->_order($params['order']);

		$limit	= isset($params['limit'])	? $params['limit']	: false;
		$offset	= isset($params['offset'])	? $params['offset']	: false;
		$query .= $this->_limit($limit, $offset);

		if (isset($params['lock'])) $query .= $this->_lock($params['lock']);

		return $this($query);
	}



	public function selectRow($col, $table, $clause=false, $order=false, $limit=1, $offset=false, $lock=false) {
		$result = $this->select($col, $table, $clause, $order, $limit, $offset, $lock);
		if ($result instanceof pudlStringResult) return $result;
		$return = $result->row();
		$result->free();
		return $return;
	}



	public function row($table, $clause=false, $order=false, $lock=false) {
		return $this->selectRow('*', $table, $clause, $order, 1, false, $lock);
	}



	public function rowEx($col, $table, $clause=false, $order=false, $lock=false) {
		return $this->selectRow($col, $table, $clause, $order, 1, false, $lock);
	}



	public function selectRows($col, $table, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$result = $this->select($col, $table, $clause, $order, $limit, $offset, $lock);
		if (is_array($this->union)) return true;
		if ($result instanceof pudlStringResult) return $result;
		return $result->complete();
	}



	public function rows($table, $clause=false, $order=false, $lock=false) {
		return $this->selectRows('*', $table, $clause, $order, false, false, $lock);
	}



	public function rowId($table, $column, $id, $lock=false) {
		return $this->row($table, $this->_clauseId($column,$id), false, $lock);
	}



	public function rowsId($table, $column, $id, $lock=false) {
		return $this->selectRows('*', $table, $this->_clauseId($column,$id), false, false, false, $lock);
	}



	public function cell($table, $col, $clause=false, $order=false) {
		$result = $this->select($col, $table, $clause, $order, 1);
		if ($result instanceof pudlStringResult) return $result;
		$return = $result->cell();
		$result->free();
		return $return;
	}



	public function cellId($table, $col, $column, $id) {
		return $this->cell($table, $col, $this->_clauseId($column,$id));
	}
}
<commit_msg>Possible to call $db->select() without tables. Eg: $db->select(pudl::now());<commit_after><?php

trait pudlSelect {


	public function select($col, $table=false, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function having($col, $table, $clause=false, $having=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_clause($having, 'HAVING');
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function group($col, $table, $clause=false, $group=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_group($group);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function groupHaving($col, $table, $clause=false, $group=false, $having=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_group($group);
		$query .= $this->_clause($having, 'HAVING');
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function orderGroup($col, $table, $clause=false, $group=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= '*, COUNT(*) FROM (SELECT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		if (is_array($limit)) $query .= $this->_limit($limit[0]);
		$query .= ') groupbyorderby';
		$query .= $this->_group($group);
		$query .= $this->_order($order);
		if (is_array($limit))  $query .= $this->_limit($limit[1], $offset);
		else $query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function orderGroupEx($col, $table, $clause=false, $inner_group=false, $outer_group=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= '*, COUNT(*) FROM (SELECT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_group($inner_group);
		$query .= $this->_order($order);
		if (is_array($limit)) $query .= $this->_limit($limit[0]);
		$query .= ') groupbyorderby';
		$query .= $this->_group($outer_group);
		$query .= $this->_order($order);
		if (is_array($limit))  $query .= $this->_limit($limit[1], $offset);
		else $query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function selectJoin($col, $table, $join_table, $join_clause, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_joinTable($join_table);
		$query .= $this->_clause($join_clause, 'ON');
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function distinct($col, $table, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= 'DISTINCT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function distinctGroup($col, $table, $clause=false, $group=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= 'DISTINCT * FROM (SELECT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= ') groupbyorderby';
		$query .= $this->_group($group);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function distinctJoin($col, $table, $join_table, $join_clause, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_cache();
		$query .= 'DISTINCT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_joinTable($join_table);
		$query .= $this->_clause($join_clause, 'ON');
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this($query);
	}



	public function selectExplain($col, $table, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$query  = 'SELECT ';
		$query .= $this->_top($limit);
		$query .= $this->_column($col);
		$query .= $this->_tables($table);
		$query .= $this->_clause($clause);
		$query .= $this->_order($order);
		$query .= $this->_limit($limit, $offset);
		$query .= $this->_lock($lock);
		return $this->explain($query);
	}



	public function selex($params) {
		$query = 'SELECT ';
		$query .= $this->_cache();

		if (isset($params['group'])  &&  isset($params['order'])) {
			$query .= ' *, COUNT(*) FROM (SELECT ';
		}

		if (isset($params['limit']))	$query .= $this->_top(   $params['limit']);
		if (isset($params['column']))	$query .= $this->_column($params['column']);
		if (!isset($params['column']))	$query .= '*';
		if (isset($params['table']))	$query .= $this->_tables($params['table']);
		if (isset($params['clause']))	$query .= $this->_clause($params['clause']);

		if (isset($params['group'])  &&  isset($params['order'])) {
			$query .= $this->_order($params['order']);
			$query .= ') groupbyorderby ';
		}

		if (isset($params['group']))	$query .= $this->_group($params['group']);
		if (isset($params['having']))	$query .= $this->_clause($params['having'], 'HAVING');
		if (isset($params['order']))	$query .= $this->_order($params['order']);

		$limit	= isset($params['limit'])	? $params['limit']	: false;
		$offset	= isset($params['offset'])	? $params['offset']	: false;
		$query .= $this->_limit($limit, $offset);

		if (isset($params['lock'])) $query .= $this->_lock($params['lock']);

		return $this($query);
	}



	public function selectRow($col, $table, $clause=false, $order=false, $limit=1, $offset=false, $lock=false) {
		$result = $this->select($col, $table, $clause, $order, $limit, $offset, $lock);
		if ($result instanceof pudlStringResult) return $result;
		$return = $result->row();
		$result->free();
		return $return;
	}



	public function row($table, $clause=false, $order=false, $lock=false) {
		return $this->selectRow('*', $table, $clause, $order, 1, false, $lock);
	}



	public function rowEx($col, $table, $clause=false, $order=false, $lock=false) {
		return $this->selectRow($col, $table, $clause, $order, 1, false, $lock);
	}



	public function selectRows($col, $table, $clause=false, $order=false, $limit=false, $offset=false, $lock=false) {
		$result = $this->select($col, $table, $clause, $order, $limit, $offset, $lock);
		if (is_array($this->union)) return true;
		if ($result instanceof pudlStringResult) return $result;
		return $result->complete();
	}



	public function rows($table, $clause=false, $order=false, $lock=false) {
		return $this->selectRows('*', $table, $clause, $order, false, false, $lock);
	}



	public function rowId($table, $column, $id, $lock=false) {
		return $this->row($table, $this->_clauseId($column,$id), false, $lock);
	}



	public function rowsId($table, $column, $id, $lock=false) {
		return $this->selectRows('*', $table, $this->_clauseId($column,$id), false, false, false, $lock);
	}



	public function cell($table, $col, $clause=false, $order=false) {
		$result = $this->select($col, $table, $clause, $order, 1);
		if ($result instanceof pudlStringResult) return $result;
		$return = $result->cell();
		$result->free();
		return $return;
	}



	public function cellId($table, $col, $column, $id) {
		return $this->cell($table, $col, $this->_clauseId($column,$id));
	}
}

{'fraction_non_alphanumeric': 0.2459795907463803, 'fraction_numerical': 0.0008548378479457178, 'mean_word_length': 4.715419847328245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 277, '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': '5124699', 'n_tokens_mistral': 7116, 'n_tokens_neox': 6580, 'n_words': 1303}