<commit_before><?php

namespace FTB\core\db;
use DB;
use Exception;

abstract class DBQuery {

	protected static $debug = false;

	protected $table;
	protected $db;
	protected $allowed_operations = ['SELECT', 'UPDATE', 'INSERT', 'INSERT IGNORE', 'UPSERT', 'DELETE'];

	public function __construct($table, $db = '', array $allowed_ops = []) {
		$this->table = $table;
		$this->db = $db;
		$this->allowed_operations = $allowed_ops ?: $this->allowed_operations;
	}

	protected function set_operation($operation) {
		if ($this->allowed_operations && !in_array($operation, $this->allowed_operations)) {
			throw new Exception("$operation is not allowed");
		}
		$this->operation = $operation;
	}

	/**
	 * Set whether DBQuery should collect debug info for all queries.
	 * @param bool $debug
	 */
	public static function setDebug($debug) {
		static::$debug = (bool)$debug;
	}

	abstract public function execute();


	/*** SELECT ***/

	abstract public function select($select);
	abstract public function where(/* conditions */);
	abstract public function whereNot(/* conditions */);
	abstract public function group($group);
	abstract public function having($having);
	abstract public function order(array $order, $half_escape = false);
	abstract public function orderByValues($column, array $values);
	abstract public function offset($offset);
	abstract public function limit($limit);

	abstract public function showProcesslist();


	/*** UPDATE/INSERT/DELETE ***/

	abstract public function update(array $updates, $no_escape = false);
	abstract public function increment(array $updates, $coalesce_null_to_zero = true);
	abstract public function insert(array $row = []);
	abstract public function upsert(array $row = []);
	abstract public function insertGetID(array $row = []);
	abstract public function delayed();
	abstract public function delete(/* where condition */);
<commit_msg>DBQuery: fixed upsert function definition<commit_after><?php

namespace FTB\core\db;
use DB;
use Exception;

abstract class DBQuery {

	protected static $debug = false;

	protected $table;
	protected $db;
	protected $allowed_operations = ['SELECT', 'UPDATE', 'INSERT', 'INSERT IGNORE', 'UPSERT', 'DELETE'];

	public function __construct($table, $db = '', array $allowed_ops = []) {
		$this->table = $table;
		$this->db = $db;
		$this->allowed_operations = $allowed_ops ?: $this->allowed_operations;
	}

	protected function set_operation($operation) {
		if ($this->allowed_operations && !in_array($operation, $this->allowed_operations)) {
			throw new Exception("$operation is not allowed");
		}
		$this->operation = $operation;
	}

	/**
	 * Set whether DBQuery should collect debug info for all queries.
	 * @param bool $debug
	 */
	public static function setDebug($debug) {
		static::$debug = (bool)$debug;
	}

	abstract public function execute();


	/*** SELECT ***/

	abstract public function select($select);
	abstract public function where(/* conditions */);
	abstract public function whereNot(/* conditions */);
	abstract public function group($group);
	abstract public function having($having);
	abstract public function order(array $order, $half_escape = false);
	abstract public function orderByValues($column, array $values);
	abstract public function offset($offset);
	abstract public function limit($limit);

	abstract public function showProcesslist();


	/*** UPDATE/INSERT/DELETE ***/

	abstract public function update(array $updates, $no_escape = false);
	abstract public function increment(array $updates, $coalesce_null_to_zero = true);
	abstract public function insert(array $row = []);
	abstract public function upsert(array $data = [], array $skip_on_update = [], $no_escape = false);
	abstract public function insertGetID(array $row = []);
	abstract public function delayed();
	abstract public function delete(/* where condition */);

{'fraction_non_alphanumeric': 0.13324641460234682, 'fraction_numerical': 0.0, 'mean_word_length': 5.247557003257329, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3978838', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1044, 'n_words': 340}