<commit_before><?php namespace Nymph\Drivers;

use Nymph\Exceptions;

/**
 * MySQL based Nymph driver.
 *
 * @package Nymph
 * @license https://www.apache.org/licenses/LICENSE-2.0
 * @author <NAME> <<EMAIL>>
 * @copyright SciActive.com
 * @link http://nymph.io/
 */
class MySQLDriver implements DriverInterface {
  use DriverTrait {
    DriverTrait::__construct as private __traitConstruct;
  }
  /**
   * The MySQL link identifier for this instance.
   *
   * @access private
   * @var mixed
   */
  private $link = null;
  private $prefix;

  public function __construct($NymphConfig) {
    $this->__traitConstruct($NymphConfig);
    $this->prefix = $this->config['MySQL']['prefix'];
  }

  /**
   * Disconnect from the database on destruction.
   */
  public function __destruct() {
    $this->disconnect();
  }

  /**
   * Connect to the MySQL database.
   *
   * @return bool Whether this instance is connected to a MySQL database after
   *              the method has run.
   */
  public function connect() {
    // Check that the MySQLi extension is installed.
    if (!is_callable('mysqli_connect')) {
      throw new Exceptions\UnableToConnectException(
          'MySQLi PHP extension is not available. It probably has not been ' .
          'installed. Please install and configure it in order to use MySQL.'
      );
    }
    $host = $this->config['MySQL']['host'];
    $user = $this->config['MySQL']['user'];
    $password = $this->config['MySQL']['password'];
    $database = $this->config['MySQL']['database'];
    $port = $this->config['MySQL']['port'];
    // Connecting, selecting database
    if (!$this->connected) {
      if ($this->link =
          mysqli_connect(
              $host,
              $user,
              $password,
              $database,
              $port
          )) {
        $this->connected = true;
      } else {
        $this->connected = false;
        if ($host == 'localhost'
            && $user == 'nymph'
            && $password == 'password'
            && $database == 'nymph') {
          throw new Exceptions\NotConfiguredException();
        } else {
          throw new Exceptions\UnableToConnectException(
              'Could not connect: ' .
                  mysqli_error($this->link)
          );
        }
      }
    }
    return $this->connected;
  }

  /**
   * Disconnect from the MySQL database.
   *
   * @return bool Whether this instance is connected to a MySQL database after
   *              the method has run.
   */
  public function disconnect() {
    if ($this->connected) {
      if (is_a($this->link, 'mysqli')) {
        unset($this->link);
      }
      $this->link = null;
      $this->connected = false;
    }
    return $this->connected;
  }

  /**
   * Create entity tables in the database.
   *
   * @param string $etype The entity type to create a table for. If this is
   *                      blank, the default tables are created.
   * @return bool True on success, false on failure.
   */
  private function createTables($etype = null) {
    $this->query('SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";');
    if (isset($etype)) {
      $etype = '_'.mysqli_real_escape_string($this->link, $etype);
      // Create the entity table.
      $this->query("CREATE TABLE IF NOT EXISTS `{$this->prefix}entities{$etype}` (`guid` bigint(20) unsigned NOT NULL, `tags` text, `varlist` text, `cdate` decimal(18,6) NOT NULL, `mdate` decimal(18,6) NOT NULL, PRIMARY KEY (`guid`), FULLTEXT `id_tags` (`tags`), FULLTEXT `id_varlist` (`varlist`)) ENGINE ".$this->config['MySQL']['engine']." CHARACTER SET utf8 COLLATE utf8_bin;");
      // Create the data table.
      $this->query("CREATE TABLE IF NOT EXISTS `{$this->prefix}data{$etype}` (`guid` bigint(20) unsigned NOT NULL, `name` text NOT NULL, `value` longtext NOT NULL, `references` longtext, `compare_true` boolean, `compare_one` boolean, `compare_zero` boolean, `compare_negone` boolean, `compare_emptyarray` boolean, `compare_string` longtext, PRIMARY KEY (`guid`,`name`(255)), FULLTEXT `id_references` (`references`)) ENGINE ".$this->config['MySQL']['engine']." CHARACTER SET utf8 COLLATE utf8_bin;");<commit_msg>Simple string change cause editors suck at syntax highlighting.<commit_after><?php namespace Nymph\Drivers;

use Nymph\Exceptions;

/**
 * MySQL based Nymph driver.
 *
 * @package Nymph
 * @license https://www.apache.org/licenses/LICENSE-2.0
 * @author <NAME> <<EMAIL>>
 * @copyright SciActive.com
 * @link http://nymph.io/
 */
class MySQLDriver implements DriverInterface {
  use DriverTrait {
    DriverTrait::__construct as private __traitConstruct;
  }
  /**
   * The MySQL link identifier for this instance.
   *
   * @access private
   * @var mixed
   */
  private $link = null;
  private $prefix;

  public function __construct($NymphConfig) {
    $this->__traitConstruct($NymphConfig);
    $this->prefix = $this->config['MySQL']['prefix'];
  }

  /**
   * Disconnect from the database on destruction.
   */
  public function __destruct() {
    $this->disconnect();
  }

  /**
   * Connect to the MySQL database.
   *
   * @return bool Whether this instance is connected to a MySQL database after
   *              the method has run.
   */
  public function connect() {
    // Check that the MySQLi extension is installed.
    if (!is_callable('mysqli_connect')) {
      throw new Exceptions\UnableToConnectException(
          'MySQLi PHP extension is not available. It probably has not been ' .
          'installed. Please install and configure it in order to use MySQL.'
      );
    }
    $host = $this->config['MySQL']['host'];
    $user = $this->config['MySQL']['user'];
    $password = $this->config['MySQL']['password'];
    $database = $this->config['MySQL']['database'];
    $port = $this->config['MySQL']['port'];
    // Connecting, selecting database
    if (!$this->connected) {
      if ($this->link =
          mysqli_connect(
              $host,
              $user,
              $password,
              $database,
              $port
          )) {
        $this->connected = true;
      } else {
        $this->connected = false;
        if ($host == 'localhost'
            && $user == 'nymph'
            && $password == 'password'
            && $database == 'nymph') {
          throw new Exceptions\NotConfiguredException();
        } else {
          throw new Exceptions\UnableToConnectException(
              'Could not connect: ' .
                  mysqli_error($this->link)
          );
        }
      }
    }
    return $this->connected;
  }

  /**
   * Disconnect from the MySQL database.
   *
   * @return bool Whether this instance is connected to a MySQL database after
   *              the method has run.
   */
  public function disconnect() {
    if ($this->connected) {
      if (is_a($this->link, 'mysqli')) {
        unset($this->link);
      }
      $this->link = null;
      $this->connected = false;
    }
    return $this->connected;
  }

  /**
   * Create entity tables in the database.
   *
   * @param string $etype The entity type to create a table for. If this is
   *                      blank, the default tables are created.
   * @return bool True on success, false on failure.
   */
  private function createTables($etype = null) {
    $this->query('SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";');
    if (isset($etype)) {
      $etype = '_'.mysqli_real_escape_string($this->link, $etype);
      // Create the entity table.
      $this->query("CREATE TABLE IF NOT EXISTS `{$this->prefix}entities{$etype}` (`guid` bigint(20) unsigned NOT NULL, `tags` text, `varlist` text, `cdate` decimal(18,6) NOT NULL, `mdate` decimal(18,6) NOT NULL, PRIMARY KEY (`guid`), FULLTEXT `id_tags` (`tags`), FULLTEXT `id_varlist` (`varlist`)) ENGINE {$this->config['MySQL']['engine']} CHARACTER SET utf8 COLLATE utf8_bin;");
      // Create the data table.
      $this->query("CREATE TABLE IF NOT EXISTS `{$this->prefix}data{$etype}` (`guid` bigint(20) unsigned NOT NULL, `name` text NOT NULL, `value` longtext NOT NULL, `references` longtext, `compare_true` boolean, `compare_one` boolean, `compare_zero` boolean, `compare_negone` boolean, `compare_emptyarray` boolean, `compare_string` longtext, PRIMARY KEY (`guid`,`name`(255)), FULLTEXT `id_references` (`references`)) ENGINE {$this->config['MySQL']['engine']} CHARACTER SET utf8 COLLATE utf8_bin;");
{'fraction_non_alphanumeric': 0.14297698945349951, 'fraction_numerical': 0.004554170661553212, 'mean_word_length': 2.705595026642984, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 67, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2616384', 'n_tokens_mistral': 2551, 'n_tokens_neox': 2458, 'n_words': 695}