<commit_before><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package     Koowa_Database
 * @subpackage  Adapter
 * @copyright	Copyright (C) 2007 - 2010 <NAME>. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link     	http://www.nooku.org
 */

/**
 * Abstract Database Adapter
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Database
 * @subpackage  Adapter
 * @uses 		KPatternCommandChain
 */
abstract class KDatabaseAdapterAbstract extends KObject implements KDatabaseAdapterInterface, KObjectIdentifiable
{
	/**
	 * Active state of the connection
	 *
	 * @var boolean
	 */
	protected $_active = null;

	/**
	 * The database connection resource
	 *
	 * @var mixed
	 */
	protected $_connection = null;

	/**
	 * Last auto-generated insert_id
	 *
	 * @var integer
	 */
	protected $_insert_id;

	/**
	 * The affected row count
	 *
	 * @var int
	 */
	protected $_affected_rows;

	/**
	 * Schema cache
	 *
	 * @var array
	 */
	protected $_table_schema = null;

	/**
	 * The table prefix
	 *
	 * @var string
	 */
	protected $_table_prefix = '';

	/**
	 * Quote for named objects
	 *
	 * @var string
	 */
	protected $_name_quote = '`';
	
	/**
	 * The connection options
	 *
	 * @var KConfig
	 */
	protected $_options = null;

	/**
	 * Constructor.
	 *
	 * @param 	object 	An optional KConfig object with configuration options.
	 * Recognized key values include 'command_chain', 'charset', 'table_prefix',
	 * (this list is not meant to be comprehensive).
	 */
	public function __construct( KConfig $config = null )
	{
		//If no config is passed create it
		if(!isset($config)) $config = new KConfig();
		
		// Initialize the options
        parent::__construct($config);
        
        // Set the connection
        if(is_resource($config->connection)) {
        	$this->setConnection($config->connection);
        }

		// Set the default charset. http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html
		if (!empty($config->charset)) {
			//$this->setCharset($config->charset);
		}

		// Set the table prefix
		$this->_table_prefix = $config->table_prefix;
		
		// Set the connection options
		$this->_options = $config->options;
		
		// Mixin a command chain
        $this->mixin(new KMixinCommandchain($config->append(array('mixer' => $this))));
	}

	/**
	 * Destructor
	 *
	 * Free any resources that are open.
	 */
	public function __destruct()
	{
		$this->disconnect();
	}

  	/**
     * Initializes the options for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param 	object 	An optional KConfig object with configuration options.
     * @return  void
     */
    protected function _initialize(KConfig $config)
    {
    	$config->append(array(
    		'options'			=> array(),
    		'charset'			=> 'UTF-8',
       	 	'table_prefix'  	=> 'jos_',
    		'command_chain' 	=>  new KCommandChain(),
    		'dispatch_events'   => true,
    		'enable_callbacks' 	=> false,
    		'connection'		=> null,
        ));
        
        parent::_initialize($config);
    }
    
	/**
	 * Get the object identifier
	 * 
	 * @return	KIdentifier	
	 * @see 	KObjectIdentifiable
	 */
	public function getIdentifier()
	{
		return $this->_identifier;
	}

	/**
	 * Get a database query object
	 *
	 * @return KDatabaseQuery
	 */
	public function getQuery(KConfig $config = null)
	{
		if(!isset($config)) {
			$config = new KConfig(array('adapter' => $this));
		}
		
		return new KDatabaseQuery($config);
	}

	/**
	 * Reconnect to the db
	 * 
	 * @return  KDatabaseAdapterAbstract
	 */
	public function reconnect()
	{
		$this->disconnect();
		$this->connect();
		
		return $this;
	}

	/**
	 * Disconnect from db
	 * 
	 * @return  KDatabaseAdapterAbstract
	 */
	public function disconnect()
	{
		$this->_connection = null;
		$this->_active = false;
		
		return $this;
	}

	/**
	 * Get the connection
	 *
	 * Provides access to the underlying database connection. Useful for when
	 * you need to call a proprietary method such as postgresql's lo_* methods
	 *
	 * @return resource
	 */
	public function getConnection()
	{
		return $this->_connection;
	}

	/**
	 * Set the connection
	 *
	 * @param 	resource 	The connection resource
	 * @return  KDatabaseAdapterAbstract
	 */
	public function setConnection($resource)
	{
		$this->_connection = $resource;
		return $this;<commit_msg>Don't check if the connection is a valid resource. Connection can also be an object.<commit_after><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package     Koowa_Database
 * @subpackage  Adapter
 * @copyright	Copyright (C) 2007 - 2010 <NAME>. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link     	http://www.nooku.org
 */

/**
 * Abstract Database Adapter
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package     Koowa_Database
 * @subpackage  Adapter
 * @uses 		KPatternCommandChain
 */
abstract class KDatabaseAdapterAbstract extends KObject implements KDatabaseAdapterInterface, KObjectIdentifiable
{
	/**
	 * Active state of the connection
	 *
	 * @var boolean
	 */
	protected $_active = null;

	/**
	 * The database connection resource
	 *
	 * @var mixed
	 */
	protected $_connection = null;

	/**
	 * Last auto-generated insert_id
	 *
	 * @var integer
	 */
	protected $_insert_id;

	/**
	 * The affected row count
	 *
	 * @var int
	 */
	protected $_affected_rows;

	/**
	 * Schema cache
	 *
	 * @var array
	 */
	protected $_table_schema = null;

	/**
	 * The table prefix
	 *
	 * @var string
	 */
	protected $_table_prefix = '';

	/**
	 * Quote for named objects
	 *
	 * @var string
	 */
	protected $_name_quote = '`';
	
	/**
	 * The connection options
	 *
	 * @var KConfig
	 */
	protected $_options = null;

	/**
	 * Constructor.
	 *
	 * @param 	object 	An optional KConfig object with configuration options.
	 * Recognized key values include 'command_chain', 'charset', 'table_prefix',
	 * (this list is not meant to be comprehensive).
	 */
	public function __construct( KConfig $config = null )
	{
		//If no config is passed create it
		if(!isset($config)) $config = new KConfig();
		
		// Initialize the options
        parent::__construct($config);
         
        // Set the connection
        $this->setConnection($config->connection);
       
		// Set the default charset. http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html
		if (!empty($config->charset)) {
			//$this->setCharset($config->charset);
		}

		// Set the table prefix
		$this->_table_prefix = $config->table_prefix;
		
		// Set the connection options
		$this->_options = $config->options;
		
		// Mixin a command chain
        $this->mixin(new KMixinCommandchain($config->append(array('mixer' => $this))));
	}

	/**
	 * Destructor
	 *
	 * Free any resources that are open.
	 */
	public function __destruct()
	{
		$this->disconnect();
	}

  	/**
     * Initializes the options for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param 	object 	An optional KConfig object with configuration options.
     * @return  void
     */
    protected function _initialize(KConfig $config)
    {
    	$config->append(array(
    		'options'			=> array(),
    		'charset'			=> 'UTF-8',
       	 	'table_prefix'  	=> 'jos_',
    		'command_chain' 	=>  new KCommandChain(),
    		'dispatch_events'   => true,
    		'enable_callbacks' 	=> false,
    		'connection'		=> null,
        ));
         
        parent::_initialize($config);
    }
    
	/**
	 * Get the object identifier
	 * 
	 * @return	KIdentifier	
	 * @see 	KObjectIdentifiable
	 */
	public function getIdentifier()
	{
		return $this->_identifier;
	}

	/**
	 * Get a database query object
	 *
	 * @return KDatabaseQuery
	 */
	public function getQuery(KConfig $config = null)
	{
		if(!isset($config)) {
			$config = new KConfig(array('adapter' => $this));
		}
		
		return new KDatabaseQuery($config);
	}

	/**
	 * Reconnect to the db
	 * 
	 * @return  KDatabaseAdapterAbstract
	 */
	public function reconnect()
	{
		$this->disconnect();
		$this->connect();
		
		return $this;
	}

	/**
	 * Disconnect from db
	 * 
	 * @return  KDatabaseAdapterAbstract
	 */
	public function disconnect()
	{
		$this->_connection = null;
		$this->_active = false;
		
		return $this;
	}

	/**
	 * Get the connection
	 *
	 * Provides access to the underlying database connection. Useful for when
	 * you need to call a proprietary method such as postgresql's lo_* methods
	 *
	 * @return resource
	 */
	public function getConnection()
	{
		return $this->_connection;
	}

	/**
	 * Set the connection
	 *
	 * @param 	resource 	The connection resource
	 * @return  KDatabaseAdapterAbstract
	 */
	public function setConnection($resource)
	{
	    $this->_connection = $resource;
		return $this;
{'fraction_non_alphanumeric': 0.1310992867655383, 'fraction_numerical': 0.002717083663534473, 'mean_word_length': 2.7527612574341545, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4549057', 'n_tokens_mistral': 3012, 'n_tokens_neox': 2682, 'n_words': 726}