<commit_before>var CursorType   = require('../constants/cursor');
var CommandCodes = require('../constants/commands');
var Types        = require('../constants/types');
var Packet       = require('../packets/packet');

function Execute(id, parameters)
{
  this.id = id;
  this.parameters = parameters;
}

Execute.prototype.toPacket = function()
{

  // TODO: don't try to calculate packet length in advance, allocate some big buffer in advance (header + 256 bytes?)
  // and copy + reallocate if not enough

  var i;
  // 0 + 4 - length, seqId
  // 4 + 1 - COM_EXECUTE
  // 5 + 4 - stmtId
  // 9 + 1 - flags
  // 10 + 4 - iteration-count (always 1)
  var length = 14;
  if (this.parameters && this.parameters.length > 0)
  {
    length += Math.floor((this.parameters.length + 7) / 8);
    length += 1; // new-params-bound-flag
    length += 2*this.parameters.length;  // type byte for each parameter if new-params-bound-flag is set
    for (i=0; i < this.parameters.length; i++)
    {
      if (this.parameters[i] !== null) {
        if (Buffer.isBuffer(this.parameters[i])) {
          length += Packet.lengthCodedNumberLength(this.parameters[i].length);<commit_msg>send Date parameter in the format mysql expect #14<commit_after>var CursorType   = require('../constants/cursor');
var CommandCodes = require('../constants/commands');
var Types        = require('../constants/types');
var Packet       = require('../packets/packet');

function Execute(id, parameters)
{
  this.id = id;
  this.parameters = parameters;
}

Execute.prototype.toPacket = function()
{

  // TODO: don't try to calculate packet length in advance, allocate some big buffer in advance (header + 256 bytes?)
  // and copy + reallocate if not enough

  var i;
  // 0 + 4 - length, seqId
  // 4 + 1 - COM_EXECUTE
  // 5 + 4 - stmtId
  // 9 + 1 - flags
  // 10 + 4 - iteration-count (always 1)
  var length = 14;
  if (this.parameters && this.parameters.length > 0)
  {
    length += Math.floor((this.parameters.length + 7) / 8);
    length += 1; // new-params-bound-flag
    length += 2*this.parameters.length;  // type byte for each parameter if new-params-bound-flag is set
    for (i=0; i < this.parameters.length; i++)
    {
      if (this.parameters[i] !== null) {
        if (this.parameters[i].constructor === Date) {
          var d = this.parameters[i];
          this.parameters[i] = [d.getFullYear(), d.getMonth() + 1, d.getDay()].join('-') +
            ' ' + [d.getHours(), d.getMinutes(), d.getSeconds()].join(':');
        }
        if (Buffer.isBuffer(this.parameters[i])) {
          length += Packet.lengthCodedNumberLength(this.parameters[i].length);
{'fraction_non_alphanumeric': 0.15940931465354033, 'fraction_numerical': 0.018553578190079516, 'mean_word_length': 2.7635327635327633, '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': '3269829', 'n_tokens_mistral': 874, 'n_tokens_neox': 823, 'n_words': 225}