<commit_before>"use strict";

var mysql             = require("mysql");
var logger            = require("../libs/utils.js").logger;
var csv               = require("fast-csv");
var loadSQLFile       = require("../libs/utils.js").loadSQLFile;
var replaceWith       = require("../libs/utils.js").replaceWith;

module.exports.exec = function exec(process){

  function executeQuery(process, configValues){

    return new Promise(function(resolve, reject) {

      process.execute_arg = process.args

      var connection = mysql.createConnection({
        host: configValues.host,
        user: configValues.user,
        password: <PASSWORD>,
        database: configValues.database,
        socketPath: configValues.socketPath,
        port: configValues.port,
        ssl: configValues.ssl,
        queryFormat: function (query, values) {
          if (!values) return query.replace(/(\:\/)/g, ':');
          else {
            var _query = query.replace(/\:(\w+)/g, function (txt, key) {
              return values && key && values.hasOwnProperty(key)
                ? this.escape(replaceWith(values[key], process.values()))
                : null;
            }.bind(this)).replace(/(\:\/)/g, ':');
          }
          return _query;
        }
      });

      connection.connect(function (err) {
        if (err) {
          logger.log('error', 'Error connecting Mysql: ' + err)
          process.execute_return = '';
          process.execute_err_return = 'Error connecting Mysql: ' + err;
          process.retries_count = process.retries_count +1 || 1;
          reject(err);
        } else {

          var command = replaceWith(process.exec.command, process.values());
          connection.query(command, process.execute_arg, function (err, results) {
            if (err) {
              logger.log('error', `executeMysql query ${command}: ${err}`);
              process.execute_err_return = `executeMysql query ${command}: ${err}`;
              reject(err);
            } else {

              if (results instanceof Array) {

                process.execute_db_results = JSON.stringify(results);
                csv.writeToString(results, {headers: true}, function (err, data) {
                  if (err) {
                    logger.log('error', `Generating csv output for execute_db_results_csv. id: ${process.id}: ${err}. Results: ${results}`);
                  } else {
                    process.execute_db_results_csv = data;
                  }
                  resolve();
                });

              } else {

                if (results instanceof Object) {
                  process.execute_db_results = '';
                  process.execute_db_results_csv = '';
                  process.execute_db_fieldCount = results.fieldCount;
                  process.execute_db_affectedRows = results.affectedRows;<commit_msg>Fix Iters into Iters<commit_after>"use strict";

var mysql             = require("mysql");
var logger            = require("../libs/utils.js").logger;
var csv               = require("fast-csv");
var loadSQLFile       = require("../libs/utils.js").loadSQLFile;
var replaceWith       = require("../libs/utils.js").replaceWith;

module.exports.exec = function exec(process){

  function executeQuery(process, configValues){

    return new Promise(function(resolve, reject) {

      process.execute_arg = process.args

      var connection = mysql.createConnection({
        host: configValues.host,
        user: configValues.user,
        password: <PASSWORD>,
        database: configValues.database,
        socketPath: configValues.socketPath,
        port: configValues.port,
        ssl: configValues.ssl,
        queryFormat: function (query, values) {
          if (!values) return query.replace(/(\:\/)/g, ':');
          else {
            var _query = query.replace(/\:(\w+)/g, function (txt, key) {
              return values && key && values.hasOwnProperty(key)
                ? replaceWith(values[key], process.values())
                : null;
            }.bind(this));
          }
          return _query;
        }
      });

      connection.connect(function (err) {
        if (err) {
          logger.log('error', 'Error connecting Mysql: ' + err)
          process.execute_return = '';
          process.execute_err_return = 'Error connecting Mysql: ' + err;
          process.retries_count = process.retries_count +1 || 1;
          reject(err);
        } else {
          var command = replaceWith(process.exec.command, process.values());
          connection.query(command, process.execute_arg, function (err, results) {
            if (err) {
              logger.log('error', `executeMysql query ${command}: ${err}`);
              process.execute_err_return = `executeMysql query ${command}: ${err}`;
              reject(err);
            } else {

              if (results instanceof Array) {

                process.execute_db_results = JSON.stringify(results);
                csv.writeToString(results, {headers: true}, function (err, data) {
                  if (err) {
                    logger.log('error', `Generating csv output for execute_db_results_csv. id: ${process.id}: ${err}. Results: ${results}`);
                  } else {
                    process.execute_db_results_csv = data;
                  }
                  resolve();
                });

              } else {

                if (results instanceof Object) {
                  process.execute_db_results = '';
                  process.execute_db_results_csv = '';
                  process.execute_db_fieldCount = results.fieldCount;
                  process.execute_db_affectedRows = results.affectedRows;
{'fraction_non_alphanumeric': 0.12594547053649957, 'fraction_numerical': 0.0007036059806508355, 'mean_word_length': 1.873168266801415, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5286014', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1446, 'n_words': 312}