<commit_before><?php

/**
 * File contains comon methods when working in db adin mode. 
 * @package coslib 
 */

/**
 * dbadmin 
 * @package
 */
class db_admin extends db {
    
    /**
     *  changes database we are working on
     * @param string $database
     */
    public static function changeDB ($database = null) {
        if (!$database) {
            $db_curr = db_admin::getDbInfo(); 
            $database = $db_curr['name'];  
        }
        $sql = "USE `$database`";
        self::rawQuery($sql);
    }
    
    /**
     * gets database info from cinfuguration
     * @return array $ary array ('name' => 'my_db, 'host' => 'localhost')
     */
    public static function getDbInfo() {
        $url = parse_url(config::$vars['coscms_main']['url']);
        $ary = explode (';', $url['path']);
        $db = explode ("=", $ary[0]);
        $database = array();
        $database['name'] = $db[1];
        $host = explode ("=", $ary[1]);
        $database['host'] = $host[1];
        return $database;
    }
    
    public static function dublicateTable ($source, $dest, $drop = true) {
        if ($drop) {
            $sql = "DROP TABLE IF EXISTS $dest";
            $res = self::rawQuery($sql);
            if (!$res) {
                return false;
            }
        }
        
        $sql = "CREATE TABLE $dest LIKE $source; INSERT $dest SELECT * FROM $source";
        return self::rawQuery($sql);
    }
    
    public static function generateIndex($table, $columns) {
        $sql = "ALTER TABLE $table ENGINE = MyISAM";
        $res = self::rawQuery($sql);
        if (!$res) {
            return false;
        }
        
        $cols = implode(',', $columns);
        
        $sql = "ALTER TABLE $table ADD FULLTEXT($cols)";
        return self::rawQuery($sql);
    }
    
    public static function tableExists($table) {
        $q = "SHOW TABLES LIKE '$table'";
        $rows = db::selectQueryOne($q);
        return $rows;
    }
}<commit_msg>query for key (indexes) exists on a table<commit_after><?php

/**
 * File contains comon methods when working in db adin mode. 
 * @package coslib 
 */

/**
 * dbadmin 
 * @package
 */
class db_admin extends db {
    
    /**
     *  changes database we are working on
     * @param string $database
     */
    public static function changeDB ($database = null) {
        if (!$database) {
            $db_curr = db_admin::getDbInfo(); 
            $database = $db_curr['name'];  
        }
        $sql = "USE `$database`";
        self::rawQuery($sql);
    }
    
    /**
     * gets database info from cinfuguration
     * @return array $ary array ('name' => 'my_db, 'host' => 'localhost')
     */
    public static function getDbInfo() {
        $url = parse_url(config::$vars['coscms_main']['url']);
        $ary = explode (';', $url['path']);
        $db = explode ("=", $ary[0]);
        $database = array();
        $database['name'] = $db[1];
        $host = explode ("=", $ary[1]);
        $database['host'] = $host[1];
        return $database;
    }
    
    public static function dublicateTable ($source, $dest, $drop = true) {
        if ($drop) {
            $sql = "DROP TABLE IF EXISTS $dest";
            $res = self::rawQuery($sql);
            if (!$res) {
                return false;
            }
        }
        
        $sql = "CREATE TABLE $dest LIKE $source; INSERT $dest SELECT * FROM $source";
        return self::rawQuery($sql);
    }
    
    /**
     * alter table to include a full text index
     * @param string $table
     * @param string $columns (e.g. firstname, lastname)
     * @return boolean $res result
     */
    public static function generateIndex($table, $columns) {
        $sql = "ALTER TABLE $table ENGINE = MyISAM";
        $res = self::rawQuery($sql);
        if (!$res) {
            return false;
        }
        
        $cols = implode(',', $columns);
        
        $sql = "ALTER TABLE $table ADD FULLTEXT($cols)";
        return self::rawQuery($sql);
    }
    
    /**
     * check if a table with specified name exists
     * @param string $table
     * @return array $rows
     */
    public static function tableExists($table) {
        $q = "SHOW TABLES LIKE '$table'";
        $rows = db::selectQueryOne($q);
        return $rows;
    }
    
    /**
     * get indexes on the table
     * @param string $table the table name
     * @return array $rows
     */
    public static function getKeys ($table) {
        $q = "SHOW KEYS FROM $table";
        $rows = db::selectQuery($q);
        return $rows;
    }
    
    /**
     * check if a specified key exists
     * 
     */
    public static function keyExists ($table, $key) {
        $q = "SHOW KEYS FROM $table WHERE Key_name='$key'";
        $rows = db::selectQueryOne($q);
        return $rows;
    }
}
{'fraction_non_alphanumeric': 0.15060240963855423, 'fraction_numerical': 0.0016618196925633569, 'mean_word_length': 1.8918918918918919, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2804949', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1444, 'n_words': 405}