<commit_before><?php

# Copyright (c) 2000-2002 dev/consulting GmbH
# Copyright (c) 2011 <NAME> <<EMAIL>>
#
# Licensed under the MIT, BSD and GPL licenses.


require_once PATH_TO_CAROSHI . '/dbi/sql.php';
require_once PATH_TO_CAROSHI . '/dbi/dbctrl.class.php';
require_once PATH_TO_CAROSHI . '/dbi/dbdepend.class.php';

/**
 * dbctrl extension (deprecated)
 *
 * @access public
 * @package Database interfaces
 */
class DBI extends DBCtrl {
    var $def;	# Database definitions.

    # <func name="DBI">
    #  <about>Use this constructor to pass db login information.</about>
    # </func>
    function DBI ($dbname, $host, $user, $passwd, $class_dbdef = 0)
    {
        !$class_dbdef ? $this->def = new DBDEPEND : $this->def = $class_dbdef;
        $this->DBCtrl ($dbname, $host, $user, $passwd);
    }


    #########################
    ### Column operations ###
    #########################

    # Return column of a row.
    # table:  Table name
    # id:     Row's primary key
    # column: Column name
    function column ($table, $column, $id)
    {
        if (!$pri = $this->def->primary ($table))
	    die_traced ("No primary key specified for table '$table'.");

        return $this->select ($column, $table, "$pri='$id'")->get ($column);
    }


    ######################
    ### Row operations ###
    ######################

    # Create an empty row in $table.
    function create_row ($table, $pre = 0)
    {
        $def =& $this->def;
        $pri = $def->primary ($table);

        $hash = $def->types ($table);
        if (!is_array ($hash))
	    die_traced ("No table '$table' defined.");

        # Check names of preset values.
        if (is_array ($pre)) {
            foreach ($hash as $f)
                $names[$f['n']] = true;
            foreach ($pre as $n => $tmp)
                if (!isset ($names[$n]))
                    die_traced ("No such field '$n' in table '$table'.");
        }

        $set = '';
        foreach ($hash as $v) {
            $n = $v['n'];
            if (!isset ($pre[$n]) || isset ($v['readonly']) || $n == $pri)
                continue;
	    $set = sql_append_assignment ($set, $n, $pre[$n]);
        }
        $this->insert ($table, $set);
    }


    ########################
    ### Table operations ###
    ########################

    # Note: This function needs a table definition (see define_table ()).
    function create_table ($table)
    {
        $t = (substr ($table, 0, 4) == '_wrk') ?
             substr ($table, 4, strlen ($table) - 4) :
             $table;
        $this->_create_table ($this->def, $table, $this->table_prefix ());
    }

    function drop_table ($name)
    {
        $this->query ("DROP TABLE $prefix$name");
    }<commit_msg>Cleanup.<commit_after><?php

# Copyright (c) 2000-2002 dev/consulting GmbH
# Copyright (c) 2011 <NAME> <<EMAIL>>
#
# Licensed under the MIT, BSD and GPL licenses.


require_once PATH_TO_CAROSHI . '/dbi/sql.php';
require_once PATH_TO_CAROSHI . '/dbi/dbctrl.class.php';
require_once PATH_TO_CAROSHI . '/dbi/dbdepend.class.php';

/**
 * dbctrl extension (deprecated)
 *
 * @access public
 * @package Database interfaces
 */
class DBI extends DBCtrl {
    var $def;	# Database definitions.

    # <func name="DBI">
    #  <about>Use this constructor to pass db login information.</about>
    # </func>
    function DBI ($dbname, $host, $user, $passwd, $class_dbdef = 0)
    {
        !$class_dbdef ? $this->def = new DBDEPEND : $this->def = $class_dbdef;
        $this->DBCtrl ($dbname, $host, $user, $passwd);
    }


    #########################
    ### Column operations ###
    #########################

    # Return column of a row.
    # table:  Table name
    # id:     Row's primary key
    # column: Column name
    function column ($table, $column, $id)
    {
        if (!$pri = $this->def->primary ($table))
	    die_traced ("No primary key specified for table '$table'.");

        return $this->select ($column, $table, "$pri='$id'")->get ($column);
    }


    ######################
    ### Row operations ###
    ######################

    # Create an empty row in $table.
    function create_row ($table, $preset_values = 0)
    {
        $def =& $this->def;
        $pri = $def->primary ($table);

        if (!$types = $def->types ($table))
	    die_traced ("No table '$table' defined.");

        # Check names of preset values.
        if ($preset_values) {
            $names = $def->field_names ($table);
            foreach ($preset_values as $n => $dummy)
                if (!array_search ($n, $names))
                    die_traced ("No such field '$n' in table '$table'.");
        }

        $this->insert ($table, sql_assignments ($preset_values));
    }


    ########################
    ### Table operations ###
    ########################

    # Note: This function needs a table definition (see define_table ()).
    function create_table ($table)
    {
        $t = (substr ($table, 0, 4) == '_wrk') ?
             substr ($table, 4, strlen ($table) - 4) :
             $table;
        $this->_create_table ($this->def, $table, $this->table_prefix ());
    }

    function drop_table ($name)
    {
        $this->query ("DROP TABLE $prefix$name");
    }
{'fraction_non_alphanumeric': 0.21014354066985647, 'fraction_numerical': 0.006889952153110048, 'mean_word_length': 2.4313854235062378, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 50, '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': '302469', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1601, 'n_words': 444}