<commit_before><?php
/**
 * Lithium: the most rad php framework
 *
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\data\source\database\adapter;

use \Exception;

class MySQLi extends \lithium\data\source\Database {

	/**
	 * MySQLi column type definitions.
	 *
	 * @var array
	 */
	protected $_columns = array(
		'primary_key'	=> array('name' => 'NOT NULL AUTO_INCREMENT'),
		'string' 		=> array('name' => 'varchar', 'length' => 255),
		'text' 			=> array('name' => 'text'),
		'integer' 		=> array('name' => 'int', 'length' => 11, 'formatter' => 'intval'),
		'float' 		=> array('name' => 'float', 'formatter' => 'floatval'),
		'datetime' 		=> array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
		'timestamp' 	=> array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'
		),
		'time' => array('name' => 'time', 'format' => 'H:i:s', 'formatter' => 'date'),
		'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'),
		'binary' => array('name' => 'blob'),
		'boolean' => array('name' => 'tinyint', 'length' => 1)
	);

	/**
	 * MySQLi-specific value denoting whether or not table aliases should be used in DELETE and
	 * UPDATE queries.
	 *
	 * @var boolean
	 */
	protected $_useAlias = true;


	/**
	 * Constructs the MySQLi adapter and default the port to 3306.
	 *
	 * @param array $config Configuration options for this class. For additional configuration,
	 *        see `lithium\data\source\Database` and `lithium\data\Source`. Available options
	 *        defined by this class:
	 *
	 *	- `'port'`: Accepts a port number or Unix socket name to use when connecting to the
	 *     database.  Defaults to `'3306'`.
	 */
	public function __construct($config = array()) {
		$defaults = array('port' => '3306');
		parent::__construct((array)$config + $defaults);
	}

	/**
	 * In cases where the query is a raw string (as opposed to a `Query` object), to database must
	 * determine the correct column names from the result resource.
	 *
	 * @param mixed $query
	 * @param resource $resource
	 * @param object $context
	 * @return array
	 */
	public function columns($query, $resource = null, $context = null) {
	}

	/**
	 * Connects to the database using options provided to the class constructor.
	 *
	 * @return boolean True if the database could be connected, else false
	 */
	public function connect() {
		$config = $this->_config;
		$this->_isConnected = false;

		$host = $config['persistent'] ? 'p:' : '';
		$host .= $config['host'];

		$this->_connection = new mysqli($host, $config['login'], $config['password'], $config['database'], $config['port']);
		if ($this->_connection !== false) {
			$this->_isConnected = true;

			$this->_encoding($config['encoding']);

			$this->_useAlias = (bool)version_compare(
				$this->_connection->server_info(), "4.1", ">="
			);
		}
<commit_msg>Adding columns method to adapter.<commit_after><?php
/**
 * Lithium: the most rad php framework
 *
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\data\source\database\adapter;

use \Exception;

class MySQLi extends \lithium\data\source\Database {

	/**
	 * MySQLi column type definitions.
	 *
	 * @var array
	 */
	protected $_columns = array(
		'primary_key'	=> array('name' => 'NOT NULL AUTO_INCREMENT'),
		'string' 		=> array('name' => 'varchar', 'length' => 255),
		'text' 			=> array('name' => 'text'),
		'integer' 		=> array('name' => 'int', 'length' => 11, 'formatter' => 'intval'),
		'float' 		=> array('name' => 'float', 'formatter' => 'floatval'),
		'datetime' 		=> array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
		'timestamp' 	=> array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'
		),
		'time' => array('name' => 'time', 'format' => 'H:i:s', 'formatter' => 'date'),
		'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'),
		'binary' => array('name' => 'blob'),
		'boolean' => array('name' => 'tinyint', 'length' => 1)
	);

	/**
	 * MySQLi-specific value denoting whether or not table aliases should be used in DELETE and
	 * UPDATE queries.
	 *
	 * @var boolean
	 */
	protected $_useAlias = true;


	/**
	 * Constructs the MySQLi adapter and default the port to 3306.
	 *
	 * @param array $config Configuration options for this class. For additional configuration,
	 *        see `lithium\data\source\Database` and `lithium\data\Source`. Available options
	 *        defined by this class:
	 *
	 *	- `'port'`: Accepts a port number or Unix socket name to use when connecting to the
	 *     database.  Defaults to `'3306'`.
	 */
	public function __construct($config = array()) {
		$defaults = array('port' => '3306');
		parent::__construct((array)$config + $defaults);
	}

	/**
	 * In cases where the query is a raw string (as opposed to a `Query` object), the database must
	 * determine the correct column names from the result resource.
	 *
	 * @param mixed $query
	 * @param mysqli_result object $mysqliResult
	 * @param object $context
	 * @return array Field names
	 */
	public function columns($query, $mysqliResult = null, $context = null) {
		if (is_object($query)) {
			return parent::columns($query, $mysqliResult, $context);
		}

		$result = array();
		while ($fieldInfo = $mysqliResult->fetch_field()) {
			$result[] = $finfo->name;
		}
		return $result;
	}

	/**
	 * Connects to the database and sets the connection encoding,
	 * using options provided to the class constructor.
	 *
	 * @return boolean True if the database could be connected, else false
	 */
	public function connect() {
		$config = $this->_config;
		$this->_isConnected = false;

		$host = $config['persistent'] ? 'p:' : '';
		$host .= $config['host'];

		$this->_connection = new mysqli($host, $config['login'], $config['password'], $config['database'], $config['port']);
		if ($this->_connection !== false) {
			$this->_isConnected = true;

			$this->_encoding($config['encoding']);

			$this->_useAlias = (bool)version_compare(
				$this->_connection->server_info(), "4.1", ">="
			);
		}

{'fraction_non_alphanumeric': 0.18394921048347712, 'fraction_numerical': 0.006511476477291226, 'mean_word_length': 3.71889400921659, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 97, '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': '6644317', 'n_tokens_mistral': 2155, 'n_tokens_neox': 1926, 'n_words': 563}