<commit_before><?php
include "config.php";

$table = str_replace('*','%',preg_replace('/[^a-zA-Z0-9\-_*]/','',isset($_GET["table"])?$_GET["table"]:'*'));
$callback = preg_replace('/[^a-zA-Z0-9\-_]/','',isset($_GET["callback"])?$_GET["callback"]:false);

$mysqli = new mysqli($config["hostname"], $config["username"], $config["password"], $config["database"]);

if ($mysqli->connect_errno) die('Connect failed: '.$mysqli->connect_error);

$tables = array();

if ($result = $mysqli->query("SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME` LIKE '$table' AND `TABLE_SCHEMA` = '$config[database]'")) {
    while ($row = $result->fetch_row()) $tables[] = $row[0];
    $result->close();
}

if ($config["whitelist"]) $tables = array_intersect($tables, $config["whitelist"]);
if ($config["blacklist"]) $tables = array_diff($tables, $config["blacklist"]);

if (empty($tables)) {
    die(header("Content-Type:",true,404));
} if ($callback) {
    header("Content-Type: application/javascript");
    echo $callback.'({';
} else {
    header("Content-Type: application/json");
    echo '{';
}

$first = true;
foreach ($tables as $table) {
    if ($first) $first = false;
    else echo ',';
    echo '"'.$table.'":[';
    if ($result = $mysqli->query("SELECT * FROM `$table`")) {
        $fields = array();
        foreach ($result->fetch_fields() as $field) $fields[] = $field->name;
        echo json_encode($fields);
        while ($row = $result->fetch_row()) echo ','.json_encode($row);
        $result->close();
    }
    echo ']';
}

if ($callback) {
    echo '});';<commit_msg>improvement<commit_after><?php
include "config.php";

$table = str_replace('*','%',preg_replace('/[^a-zA-Z0-9\-_*]/','',isset($_GET["table"])?$_GET["table"]:'*'));
$callback = preg_replace('/[^a-zA-Z0-9\-_]/','',isset($_GET["callback"])?$_GET["callback"]:false);

$mysqli = new mysqli($config["hostname"], $config["username"], $config["password"], $config["database"]);

if ($mysqli->connect_errno) die('Connect failed: '.$mysqli->connect_error);

$tables = array();

if ($result = $mysqli->query("SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME` LIKE '$table' AND `TABLE_SCHEMA` = '$config[database]'")) {
    while ($row = $result->fetch_row()) $tables[] = $row[0];
    $result->close();
}

if ($config["whitelist"]) $tables = array_intersect($tables, $config["whitelist"]);
if ($config["blacklist"]) $tables = array_diff($tables, $config["blacklist"]);

if (empty($tables)) {
    die(header("Content-Type:",true,404));
} if ($callback) {
    header("Content-Type: application/javascript");
    echo $callback.'({';
} else {
    header("Content-Type: application/json");
    echo '{';
}

$first_table = true;
foreach ($tables as $table) {
    if ($first_table) $first_table = false;
    else echo ',';
    echo '"'.$table.'":{"columns":';
    if ($result = $mysqli->query("SELECT * FROM `$table`")) {
        $fields = array();
        foreach ($result->fetch_fields() as $field) $fields[] = $field->name;
        echo json_encode($fields);
        echo ',"records":';
        $first_row = true;
        while ($row = $result->fetch_row()) {
            if ($first_row) $first_row = false;
            else echo ',';
            echo json_encode($row);
        }
        $result->close();
    }
    echo '}';
}

if ($callback) {
    echo '});';
{'fraction_non_alphanumeric': 0.24212715389185976, 'fraction_numerical': 0.004753416518122401, 'mean_word_length': 4.3872, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 23, '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': '5113343', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1134, 'n_words': 212}