<commit_before><?php
require_once(dirname(__FILE__).'/settings.php');

class Connection{
	public $db = null;
	public $dbs = array();
	public $latest_schema = 21;
	
	public function __construct($dbc = null,$dbname = null) {
	    global $globalDBdriver;
	    if ($dbc === null) {
		if ($this->db === null && $dbname === null) {
		    $this->createDBConnection();
		} else {
		    $this->createDBConnection($dbname);
		}
	    } elseif ($dbname === null || $dbname === 'default') {
		$this->db = $dbc;
		if ($this->connectionExists() === false) {
			/*
			echo 'Restart Connection !!!'."\n";
			$e = new \Exception;
			var_dump($e->getTraceAsString());
			*/
			$this->createDBConnection();
		}
	    } else {
		//$this->connectionExists();
		$this->dbs[$dbname] = $dbc;
	    }
	}


	/**
	* Creates the database connection
	*
	* @return Boolean of the database connection
	*
	*/

	public function createDBConnection($DBname = null)
	{
		global $globalDBdriver, $globalDBhost, $globalDBuser, $globalDBpass, $globalDBname, $globalDebug, $globalDB, $globalDBport, $globalDBTimeOut, $globalDBretry, $globalDBPersistent;
		if ($DBname === null) {
			$DBname = 'default';
			$globalDBSdriver = $globalDBdriver;
			$globalDBShost = $globalDBhost;
			$globalDBSname = $globalDBname;
			$globalDBSuser = $globalDBuser;
			$globalDBSpass = $globalDBpass;
			if (!isset($globalDBport) || $globalDBport == NULL) $globalDBSport = 3306;
			else $globalDBSport = $globalDBport;
		} else {
			$globalDBSdriver = $globalDB[$DBname]['driver'];
			$globalDBShost = $globalDB[$DBname]['host'];
			$globalDBSname = $globalDB[$DBname]['name'];
			$globalDBSuser = $globalDB[$DBname]['user'];
			$globalDBSpass = $globalDB[$DBname]['pass'];
			if (isset($globalDB[$DBname]['port'])) $globalDBSport = $globalDB[$DBname]['port'];
			else $globalDBSport = 3306;
		}
		// Set number of try to connect to DB
		if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry == null) $globalDBretry = 5;
		$i = 0;
		while (true) {
			try {
				$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser,  $globalDBSpass);
				$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
				$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
				if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
				else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
				if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
				else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
				$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
				$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
				break;
			} catch(PDOException $e) {<commit_msg>Workaround against only_full_group_by<commit_after><?php
require_once(dirname(__FILE__).'/settings.php');

class Connection{
	public $db = null;
	public $dbs = array();
	public $latest_schema = 21;
	
	public function __construct($dbc = null,$dbname = null) {
	    global $globalDBdriver;
	    if ($dbc === null) {
		if ($this->db === null && $dbname === null) {
		    $this->createDBConnection();
		} else {
		    $this->createDBConnection($dbname);
		}
	    } elseif ($dbname === null || $dbname === 'default') {
		$this->db = $dbc;
		if ($this->connectionExists() === false) {
			/*
			echo 'Restart Connection !!!'."\n";
			$e = new \Exception;
			var_dump($e->getTraceAsString());
			*/
			$this->createDBConnection();
		}
	    } else {
		//$this->connectionExists();
		$this->dbs[$dbname] = $dbc;
	    }
	}


	/**
	* Creates the database connection
	*
	* @return Boolean of the database connection
	*
	*/

	public function createDBConnection($DBname = null)
	{
		global $globalDBdriver, $globalDBhost, $globalDBuser, $globalDBpass, $globalDBname, $globalDebug, $globalDB, $globalDBport, $globalDBTimeOut, $globalDBretry, $globalDBPersistent;
		if ($DBname === null) {
			$DBname = 'default';
			$globalDBSdriver = $globalDBdriver;
			$globalDBShost = $globalDBhost;
			$globalDBSname = $globalDBname;
			$globalDBSuser = $globalDBuser;
			$globalDBSpass = $globalDBpass;
			if (!isset($globalDBport) || $globalDBport == NULL) $globalDBSport = 3306;
			else $globalDBSport = $globalDBport;
		} else {
			$globalDBSdriver = $globalDB[$DBname]['driver'];
			$globalDBShost = $globalDB[$DBname]['host'];
			$globalDBSname = $globalDB[$DBname]['name'];
			$globalDBSuser = $globalDB[$DBname]['user'];
			$globalDBSpass = $globalDB[$DBname]['pass'];
			if (isset($globalDB[$DBname]['port'])) $globalDBSport = $globalDB[$DBname]['port'];
			else $globalDBSport = 3306;
		}
		// Set number of try to connect to DB
		if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry == null) $globalDBretry = 5;
		$i = 0;
		while (true) {
			try {
				$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser,  $globalDBSpass);
				$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
				$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
				if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
				else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
				if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
				else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
				$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
				$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
				// FIXME : Workaround against "ONLY_FULL_GROUP_BY" mode
				$this->dbs[$DBname]->exec('SET sql_mode = "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE"');
				break;
			} catch(PDOException $e) {
{'fraction_non_alphanumeric': 0.1791786974655117, 'fraction_numerical': 0.005453962143086301, 'mean_word_length': 5.210159362549801, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '1181096', 'n_tokens_mistral': 2446, 'n_tokens_neox': 2237, 'n_words': 352}