<commit_before><?php
namespace LazyRecord;
use PDO;
use PDOException;
use Exception;
use Iterator;
use ArrayAccess;

use SQLBuilder\QueryBuilder;
use LazyRecord\OperationResult\OperationSuccess;
use LazyRecord\OperationResult\OperationError;
use LazyRecord\ConnectionManager;
use LazyRecord\Schema\SchemaLoader;


/**
 * base collection class
 */
class BaseCollection
    implements Iterator, ArrayAccess, ExporterInterface
{

    protected $_lastSql;

    protected $_vars;

    /**
     * @var SQLBuilder\QueryBuilder
     */
    protected $_currentQuery;

    /**
     * @var PDOStatement handle
     */
    protected $handle;


    /**
     * handle data for items
     *
     * @var array
     */ 
    protected $_itemData = null;



    /**
     * preset vars for creating
     */
    protected $_presetVars = array();



    /**
     * postCreate hook
     */
    protected $_postCreate;


    /**
     * current data item cursor position
     *
     * @var integer
     */
    protected $_itemCursor = null;



    /**
     * operation result object
     */
    protected $_result;




    public function __construct() {
        // init a query
    }


    public function __get( $key ) 
    {
        /**
         * lazy attributes
         */
        if( $key == '_schema' ) {
            return SchemaLoader::load( static::schema_proxy_class );
        }
        elseif( $key == '_handle' ) {
            return $this->handle ?: $this->prepareData();
        }
        elseif( $key == '_query' ) {
            return $this->_currentQuery ?: $this->createQuery();
        }
        elseif( $key == '_items' ) {
            return $this->_itemData ?: $this->_readRows();
        }
    }

    public function free()
    {
        $this->_itemData = null;
        return $this;
    }

    public function __call($m,$a)
    {
        $q = $this->_query;
        if( method_exists($q,$m) ) {
            return call_user_func_array(array($q,$m),$a);
        }
    }

    public function getAlias()
    {
        return 'm';
    }

    public function createQuery()
    {
        $q = new QueryBuilder;
        $q->driver = $this->getCurrentQueryDriver();
        $q->table( $this->_schema->table );
        // $q->select('*');
        $q->select( $this->getExplicitColumnSelect($q->driver) );
        $q->alias( $this->getAlias() ); // main table alias
        return $this->_currentQuery = $q;
    }


    // xxx: this might be used in other join statements.
    public function getExplicitColumnSelect($driver)
    {<commit_msg>Add _alias member and setter<commit_after><?php
namespace LazyRecord;
use PDO;
use PDOException;
use Exception;
use Iterator;
use ArrayAccess;

use SQLBuilder\QueryBuilder;
use LazyRecord\OperationResult\OperationSuccess;
use LazyRecord\OperationResult\OperationError;
use LazyRecord\ConnectionManager;
use LazyRecord\Schema\SchemaLoader;


/**
 * base collection class
 */
class BaseCollection
    implements Iterator, ArrayAccess, ExporterInterface
{

    protected $_lastSql;

    protected $_vars;

    /**
     * @var SQLBuilder\QueryBuilder
     */
    protected $_currentQuery;

    /**
     * @var PDOStatement handle
     */
    protected $handle;


    /**
     * handle data for items
     *
     * @var array
     */ 
    protected $_itemData = null;



    /**
     * preset vars for creating
     */
    protected $_presetVars = array();



    /**
     * postCreate hook
     */
    protected $_postCreate;


    /**
     * current data item cursor position
     *
     * @var integer
     */
    protected $_itemCursor = null;



    /**
     * operation result object
     */
    protected $_result;


    protected $_alias = 'm';


    public function __construct() {
        // init a query
    }


    public function __get( $key ) 
    {
        /**
         * lazy attributes
         */
        if( $key == '_schema' ) {
            return SchemaLoader::load( static::schema_proxy_class );
        }
        elseif( $key == '_handle' ) {
            return $this->handle ?: $this->prepareData();
        }
        elseif( $key == '_query' ) {
            return $this->_currentQuery ?: $this->createQuery();
        }
        elseif( $key == '_items' ) {
            return $this->_itemData ?: $this->_readRows();
        }
    }

    public function free()
    {
        $this->_itemData = null;
        return $this;
    }

    public function __call($m,$a)
    {
        $q = $this->_query;
        if( method_exists($q,$m) ) {
            return call_user_func_array(array($q,$m),$a);
        }
    }

    public function getAlias()
    {
        return $this->_alias;
    }

    public function setAlias($alias)
    {
        $this->_alias = $alias;
        return $this;
    }

    public function createQuery()
    {
        $q = new QueryBuilder;
        $q->driver = $this->getCurrentQueryDriver();
        $q->table( $this->_schema->table );
        // $q->select('*');
        $q->select( $this->getExplicitColumnSelect($q->driver) );
        $q->alias( $this->getAlias() ); // main table alias
        return $this->_currentQuery = $q;
    }


    // xxx: this might be used in other join statements.
    public function getExplicitColumnSelect($driver)
    {
{'fraction_non_alphanumeric': 0.12982791586998088, 'fraction_numerical': 0.0, 'mean_word_length': 1.999426605504587, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '502515', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1500, 'n_words': 354}