<commit_before><?php
class Db_Core {

	public $debug = false;
	public $connected = false;

	protected $exception_depth = 0;
	protected $errors = [];

	private $database, $user, $pass;
	private $db;

	public function connect($user, $pass, $db, $host = "localhost") {
		try {
			$this->db = new PDO("mysql:host=".$host.";dbname=".$db.";charset=utf8", $user, $pass);
			$this->db->query("SET COLLATION_CONNECTION=UTF8_SWEDISH_CI");
		}
		catch (PDOException $e) {
			$this->errors[] = $e->getMessage();
			return false;
		}
		$this->db->query("SET NAMES UTF8");
		$this->db->query("SET COLLATION_CONNECTION=UTF8_SWEDISH_CI");
		$this->connected = true;
		return true;
	}
	
	public function dump($file, $database, $user, $pass) {
		exec("mysqldump ".$database." --password=".$pass." --user=".$user." --single-transaction > ".$file);
		return true;
	}

	public function getErrors() {
		return $this->errors;
	}
	
	private function where(&$sql, &$vars, $conditions = []) {
		if (!empty($conditions)) {
			$sql.= " WHERE ";
			$condarr = [];
			$n = 0;
			foreach ($conditions as $i => $cond) {
				$n++;
				if (is_array($cond) && is_int($i)) {
					$pred = (isset($cond[2]) ? $cond[2] : null);
					$key = $cond[0];
					$val = $cond[1];
				}
				else {
					$pred = "=";
					$key = $i;
					$val = $cond;
				}
				if (is_array($val)) {
					if (!$pred || $pred == "=")
						$pred = " IN ";
					if ($pred == "!=")
						$pred = " NOT IN ";
					$or = [];
					foreach ($val as $j => $v) {
						$varkey = ":".$key.$n."_".$j;
						$vars[$varkey] = $v;
						$or[] = $varkey;
					}
					$condarr[] = $key.$pred."(".implode(",", $or).")";
				}
				else {
					if (!$pred)
						$pred = "=";
					$varkey = ":".$key.$n;
					$vars[$varkey] = $val;
					$condarr[] = $key.$pred.$varkey;
				}
			}
			$sql.= implode(" && ", $condarr);
		}
	}
	
	public function query($sql, $param = []) {
		try  {<commit_msg>Db:where support for null values.<commit_after><?php
class Db_Core {

	public $debug = false;
	public $connected = false;

	protected $exception_depth = 0;
	protected $errors = [];

	private $database, $user, $pass;
	private $db;

	public function connect($user, $pass, $db, $host = "localhost") {
		try {
			$this->db = new PDO("mysql:host=".$host.";dbname=".$db.";charset=utf8", $user, $pass);
			$this->db->query("SET COLLATION_CONNECTION=UTF8_SWEDISH_CI");
		}
		catch (PDOException $e) {
			$this->errors[] = $e->getMessage();
			return false;
		}
		$this->db->query("SET NAMES UTF8");
		$this->db->query("SET COLLATION_CONNECTION=UTF8_SWEDISH_CI");
		$this->connected = true;
		return true;
	}
	
	public function dump($file, $database, $user, $pass) {
		exec("mysqldump ".$database." --password=".$pass." --user=".$user." --single-transaction > ".$file);
		return true;
	}

	public function getErrors() {
		return $this->errors;
	}
	
	private function where(&$sql, &$vars, $conditions = []) {
		if (!empty($conditions)) {
			$sql.= " WHERE ";
			$condarr = [];
			$n = 0;
			foreach ($conditions as $i => $cond) {
				$n++;
				if (is_array($cond) && is_int($i)) {
					$pred = (isset($cond[2]) ? $cond[2] : "=");
					$key = $cond[0];
					$val = $cond[1];
				}
				else {
					$pred = "=";
					$key = $i;
					$val = $cond;
				}
				if (is_array($val)) {
					if ($pred == "=")
						$pred = " IN ";
					if ($pred == "!=")
						$pred = " NOT IN ";
					$or = [];
					foreach ($val as $j => $v) {
						$varkey = ":".$key.$n."_".$j;
						$vars[$varkey] = $v;
						$or[] = $varkey;
					}
					$condarr[] = $key.$pred."(".implode(",", $or).")";
				}
				else {
					if ($val === null) {
						if ($pred == "=")
							$condarr[] = $key." IS NULL";
						else if ($pred == "!=")
							$condarr[] = $key." IS NOT NULL";
					}
					else {
						$varkey = ":".$key.$n;
						$vars[$varkey] = $val;
						$condarr[] = $key.$pred.$varkey;
					}
				}
			}
			$sql.= implode(" && ", $condarr);
		}
	}
	
	public function query($sql, $param = []) {
		try  {
{'fraction_non_alphanumeric': 0.23564954682779457, 'fraction_numerical': 0.005035246727089627, 'mean_word_length': 2.6316270566727606, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 31, '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': '2529395', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1508, 'n_words': 317}