<commit_before><?php

namespace Cactus\Adapter;

/**
 * A Database adapter for PDO.
 *
 * @see        http://us3.php.net/manual/en/class.pdo.php
 *
 * @package    Cactus
 * @author     <NAME> <<EMAIL>>
 */
class PDO implements \Cactus\Adapter
{
	/**
	 * @var \PDO  The PDO connection object
	 */
	private $pdo;
	
	/**
	 * Run a SELECT query.
	 *
	 * @param  string $query      The query to run
	 * @param  string $as_object  Return the result as an object?
	 * @return mixed              The complete database result set
	 */
	public function select($query, $as_object = null)
	{
		$statement = $this->execute($query);

		$result = ($as_object !== null) ?
			$statement->fetchAll(\PDO::FETCH_CLASS, $as_object) :
			$statement->fetchAll();

		return $result;
	}

	/**
	 * Run an INSERT query.
	 *
	 * @param  string $query  The SQL query
	 * @return array          array($insert_id, $number) 
	 */
	public function insert($query)
	{		
		$statement = $this->execute($query);
		return array($this->pdo->lastInsertId() , $statement->rowCount());
	}

	/**
	 * Run an UPDATE query.
	 *
	 * @param  string $query  The SQL query
	 * @return int            Affected rows
	 */
	public function update($query)
	{
		$statement = $this->execute($query);
		return $statement->rowCount();
	}

	/**
	 * Run a DELETE query.
	 *
	 * @param  string $query  The SQL query to run
	 * @return int            The number of deleted rows 
	 */
	public function delete($query)
	{
		$statement = $this->execute($query);
		return $statement->rowCount();
	}

	/**
	 * Executes a pre-built query. Throws a \Cactus\Exception if something goes
	 * wrong with the query.
	 *
	 * @throws \Cactus\Exception
	 *
	 * @param  string $query  SQL query
	 * @return \PDOStatement
	 */
	private function execute($query)
	{
		try{
			$statement = $this->pdo->query($query);
		} catch(\PDOException $e) {
			throw new \Cactus\Exception($e->getMessage());
		}

		return $statement;
	}

	/**
	 * Gets the connection object.
	 *
	 * @param  mixed $db  The database connection object used internally
	 * @return mixed      [get] The connection object OR [set] $this
	 */
	public function connection($db = null)
	{
		if ($db === null)
		{
			return $this->pdo;
		}

		$this->pdo = $db;
		return $this;
	}<commit_msg>Updating the PDO Adapter.<commit_after><?php

namespace Cactus\Adapter;

/**
 * A Database adapter for PDO.
 *
 * @see        http://us3.php.net/manual/en/class.pdo.php
 *
 * @package    Cactus
 * @author     <NAME> <<EMAIL>>
 */
class PDO implements \Cactus\Adapter
{
	/**
	 * @var \PDO  The PDO connection object
	 */
	private $pdo;

	/**
	 * Run a SELECT query.
	 *
	 * @param  string $query      The query to run
	 * @param  string $as_object  Return the result as an object?
	 * @return mixed              The complete database result set
	 */
	public function select($query, $as_object = null)
	{
		$statement = $this->execute($query);

		$result = ($as_object !== null) ?
			$statement->fetchAll(\PDO::FETCH_CLASS, $as_object) :
			$statement->fetchAll();

		return $result;
	}

	/**
	 * Run an INSERT query.
	 *
	 * @param  string $query  The SQL query
	 * @return array          array($insert_id, $number) 
	 */
	public function insert($query)
	{		
		$statement = $this->execute($query);
		return array($this->pdo->lastInsertId() , $statement->rowCount());
	}

	/**
	 * Run an UPDATE query.
	 *
	 * @param  string $query  The SQL query
	 * @return int            Affected rows
	 */
	public function update($query)
	{
		$statement = $this->execute($query);
		return $statement->rowCount();
	}

	/**
	 * Run a DELETE query.
	 *
	 * @param  string $query  The SQL query to run
	 * @return int            The number of deleted rows 
	 */
	public function delete($query)
	{
		$statement = $this->execute($query);
		return $statement->rowCount();
	}

	/**
	 * Executes a pre-built query. Throws a \Cactus\Exception if something goes
	 * wrong with the query.
	 *
	 * @throws \Cactus\Exception
	 *
	 * @param  string $query  SQL query
	 * @return \PDOStatement
	 */
	private function execute($query)
	{
		try{
			$statement = $this->pdo->query($query);
		} catch(\PDOException $e) {
			throw new \Cactus\Exception($e->getMessage());
		}

		return $statement;
	}

	/**
	 * The database connection object.
	 *
	 * @return \PDO  The pdo connection object
	 */
	public function get_connection()
	{
		return $this->pdo;
	}

	/**
	 * Sets the connection object used to connect to the database.
	 *
	 * @param  \PDO $db  The database connection object.
	 * @return \Cactus\Adapter
	 */
	public function set_connection($db)
	{
		$this->pdo = $db;
		return $this;
	}
{'fraction_non_alphanumeric': 0.14437000216122758, 'fraction_numerical': 0.0004322455154527772, 'mean_word_length': 2.732258064516129, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '3196737', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1493, 'n_words': 427}