<commit_before>var mysql = require('mysql'),
    pool = mysql.createPool({
        host: process.env.host,
        user: process.env.user,
        password: <PASSWORD>,
        database: process.env.database
    });

function validate(string) {
    return pool.escape(string) || '';
}

function query(string, callback) {
   pool.getConnection(function (err, connection) {
        if(err) console.error(err);

        connection.query(string, function (error, results = [], fields = []) {
            connection.release();

            if (error) console.error(error);
            callback({
                error,
                results,
                fields
            });
        });
    });
}

function insertArray(table, array, duplicate) {
    // Validate Keys and Values.
    var keys = validate(Object.keys(array[0])),
        splitKeys = keys.split(/\s*'| |,\s*/).filter(Boolean),    
        values = array.map(value => validate(Object.keys(value).map(v => Array.isArray(value[v]) ? JSON.stringify(value[v]) : value[v])));
        //array.map(value => validate(Object.keys(value).map(v => value[v])));

    // Build request string.
    var request = [
        'INSERT INTO',
        table,
        '(',
        splitKeys,
        ') VALUES ',
        values.map(value => '(' + value + ')')
        // array.map(val => `( ${Object.values(val).map(v => v ? "'" + v + "'" : 'null').join(", ")})`)
    ];

    // Upsert.
    if (duplicate) {
        request.push('ON DUPLICATE KEY UPDATE',
            splitKeys.map((x, i) => x + '=VALUES(' + x + ')'))
    }

    return request.join(' ');
}

function location(lat, lng, radius, limit, type) {
    if (type) typeText = 'AND z.type = ' + type;
    return `SELECT *
            FROM (
               SELECT z.id,
                      z.formatted_address,
                      z.lat, z.lng,
                      z.date, z.json, z.type,
                      z.active, z.approved,
                      p.radius,
                      p.distance_unit
                          * DEGREES(ACOS(COS(RADIANS(p.latpoint))
                          * COS(RADIANS(z.lat))
                          * COS(RADIANS(p.longpoint - z.lng))
                          + SIN(RADIANS(p.latpoint))
                          * SIN(RADIANS(z.lat)))) AS distance
               FROM tb_events AS z
               JOIN (   
                     SELECT  ${lat} AS latpoint,  ${lng} AS longpoint,
                             ${radius} AS radius,  111.045 AS distance_unit
                 ) AS p ON 1=1
               WHERE z.lat
                  BETWEEN p.latpoint  - (p.radius / p.distance_unit)
                      AND p.latpoint  + (p.radius / p.distance_unit)
                 AND z.lng<commit_msg>FIX: undefined var<commit_after>var mysql = require('mysql'),
    pool = mysql.createPool({
        host: process.env.host,
        user: process.env.user,
        password: <PASSWORD>,
        database: process.env.database
    });

function validate(string) {
    return pool.escape(string) || '';
}

function query(string, callback) {
   pool.getConnection(function (err, connection) {
        if(err) console.error(err);

        connection.query(string, function (error, results = [], fields = []) {
            connection.release();

            if (error) console.error(error);
            callback({
                error,
                results,
                fields
            });
        });
    });
}

function insertArray(table, array, duplicate) {
    // Validate Keys and Values.
    var keys = validate(Object.keys(array[0])),
        splitKeys = keys.split(/\s*'| |,\s*/).filter(Boolean),    
        values = array.map(value => validate(Object.keys(value).map(v => Array.isArray(value[v]) ? JSON.stringify(value[v]) : value[v])));
        //array.map(value => validate(Object.keys(value).map(v => value[v])));

    // Build request string.
    var request = [
        'INSERT INTO',
        table,
        '(',
        splitKeys,
        ') VALUES ',
        values.map(value => '(' + value + ')')
        // array.map(val => `( ${Object.values(val).map(v => v ? "'" + v + "'" : 'null').join(", ")})`)
    ];

    // Upsert.
    if (duplicate) {
        request.push('ON DUPLICATE KEY UPDATE',
            splitKeys.map((x, i) => x + '=VALUES(' + x + ')'))
    }

    return request.join(' ');
}

function location(lat, lng, radius, limit, type) {
    if (type) var typeText = 'AND z.type = ' + type;
    return `SELECT *
            FROM (
               SELECT z.id,
                      z.formatted_address,
                      z.lat, z.lng,
                      z.date, z.json, z.type,
                      z.active, z.approved,
                      p.radius,
                      p.distance_unit
                          * DEGREES(ACOS(COS(RADIANS(p.latpoint))
                          * COS(RADIANS(z.lat))
                          * COS(RADIANS(p.longpoint - z.lng))
                          + SIN(RADIANS(p.latpoint))
                          * SIN(RADIANS(z.lat)))) AS distance
               FROM tb_events AS z
               JOIN (   
                     SELECT  ${lat} AS latpoint,  ${lng} AS longpoint,
                             ${radius} AS radius,  111.045 AS distance_unit
                 ) AS p ON 1=1
               WHERE z.lat
                  BETWEEN p.latpoint  - (p.radius / p.distance_unit)
                      AND p.latpoint  + (p.radius / p.distance_unit)
                 AND z.lng
{'fraction_non_alphanumeric': 0.14660353305408852, 'fraction_numerical': 0.003278091422327445, 'mean_word_length': 1.458370635631155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '7080464', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1602, 'n_words': 324}