<commit_before>/*jslint node: true*/
"use strict";
var sql = require('mssql');

// config for DB connections
var config = require('config');
var lastProcessed = config.App.lastProcessed;

function getAccount(recordset, processed) {
  // loop record sets to get account
  var async = require('async');
  async.map(recordset, function (record, callback) {
    var conn = new sql.Connection(config.DatabaseAccounts, function (err) {
      // check for error
      if (err) {
        console.error('DB connection failed: ' + err.stack);
        callback(err);
      } else {
        // get the data
        var request = new sql.Request(conn);
        request.query(config.App.accountCommand + '\'' + record.user.replace("'", "\'") + '\'', function (err, accountset) {
          if (err) {
            console.error('Error retrieving account information for ' + record.user + ': ' + err.stack);
            callback(err);
          } else {
            if (accountset.length > 0) {
              record.account = accountset[0].account;
            } else {
              record.account = 'System';
            }

            callback(err, record);
          }
        });
      }
    });
  }, function (err, result) {
    lastProcessed = recordset[recordset.length - 1].LogEntryId;
    if (err) {
      console.error("Account retrieval failed: " + err.stack);
    }
    processed(recordset, function (e) {
      if (e) {
        console.error('Update to Insights failed');
      } else {
        config.App.lastProcessed = lastProcessed;
      }
    });
  });
}

exports.getReports = function (insights) {
  // get where clause - using config file for the time being
  var dbWhere = 'where LogEntryId > ' + lastProcessed,
    conn = new sql.Connection(config.Database, function (err) {
      // check for error
      if (err) {
        console.error(err.stack);
      } else {
        // get the data
        var request = new sql.Request(conn);
        request.query('SELECT TOP 100 *, \'' + config.App.appName + '\' AS appName FROM dbo.InsightsExecutionLog ' + dbWhere, function (err, recordset) {
          // check for error
          if (err) {
            console.error(err.stack);
          } else {
            if (recordset.length > 0) {
              getAccount(recordset, insights.send);
            }
          }
        });
      }
    });
};
<commit_msg>fix replace quote in user name<commit_after>/*jslint node: true*/
"use strict";
var sql = require('mssql');

// config for DB connections
var config = require('config');
var lastProcessed = config.App.lastProcessed;

function getAccount(recordset, processed) {
  // loop record sets to get account
  var async = require('async');
  async.map(recordset, function (record, callback) {
    var conn = new sql.Connection(config.DatabaseAccounts, function (err) {
      // check for error
      if (err) {
        console.error('DB connection failed: ' + err.stack);
        callback(err);
      } else {
        // get the data
        var request = new sql.Request(conn);
        request.query(config.App.accountCommand + '\'' + record.user.replace("'", "''") + '\'', function (err, accountset) {
          if (err) {
            console.error('Error retrieving account information for ' + record.user + ': ' + err.stack);
            callback(err);
          } else {
            if (accountset.length > 0) {
              record.account = accountset[0].account;
            } else {
              record.account = 'System';
            }

            callback(err, record);
          }
        });
      }
    });
  }, function (err, result) {
    lastProcessed = recordset[recordset.length - 1].LogEntryId;
    if (err) {
      console.error("Account retrieval failed: " + err.stack);
    }
    processed(recordset, function (e) {
      if (e) {
        console.error('Update to Insights failed');
      } else {
        config.App.lastProcessed = lastProcessed;
      }
    });
  });
}

exports.getReports = function (insights) {
  // get where clause - using config file for the time being
  var dbWhere = 'where LogEntryId > ' + lastProcessed,
    conn = new sql.Connection(config.Database, function (err) {
      // check for error
      if (err) {
        console.error(err.stack);
      } else {
        // get the data
        var request = new sql.Request(conn);
        request.query('SELECT TOP 100 *, \'' + config.App.appName + '\' AS appName FROM dbo.InsightsExecutionLog ' + dbWhere, function (err, recordset) {
          // check for error
          if (err) {
            console.error(err.stack);
          } else {
            if (recordset.length > 0) {
              getAccount(recordset, insights.send);
            }
          }
        });
      }
    });
};
{'fraction_non_alphanumeric': 0.13406408094435077, 'fraction_numerical': 0.002951096121416526, 'mean_word_length': 2.022292993630573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1483452', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1348, 'n_words': 343}