• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mysqljs / mysql / 3954445999

pending completion
3954445999

push

github

Douglas Christopher Wilson
build: ubuntu@20.04

869 of 1014 branches covered (85.7%)

5111 of 5264 relevant lines covered (97.09%)

687.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.29
/lib/protocol/packets/FieldPacket.js
1
module.exports = FieldPacket;
396✔
2
function FieldPacket(options) {
3
  options = options || {};
2,840!
4

5
  this.catalog    = options.catalog;
2,840✔
6
  this.db         = options.db;
2,840✔
7
  this.table      = options.table;
2,840✔
8
  this.orgTable   = options.orgTable;
2,840✔
9
  this.name       = options.name;
2,840✔
10
  this.orgName    = options.orgName;
2,840✔
11
  this.charsetNr  = options.charsetNr;
2,840✔
12
  this.length     = options.length;
2,840✔
13
  this.type       = options.type;
2,840✔
14
  this.flags      = options.flags;
2,840✔
15
  this.decimals   = options.decimals;
2,840✔
16
  this.default    = options.default;
2,840✔
17
  this.zeroFill   = options.zeroFill;
2,840✔
18
  this.protocol41 = options.protocol41;
2,840✔
19
}
20

21
FieldPacket.prototype.parse = function(parser) {
396✔
22
  if (this.protocol41) {
2,716!
23
    this.catalog     = parser.parseLengthCodedString();
2,716✔
24
    this.db          = parser.parseLengthCodedString();
2,716✔
25
    this.table       = parser.parseLengthCodedString();
2,712✔
26
    this.orgTable    = parser.parseLengthCodedString();
2,712✔
27
    this.name        = parser.parseLengthCodedString();
2,712✔
28
    this.orgName     = parser.parseLengthCodedString();
2,712✔
29

30
    if (parser.parseLengthCodedNumber() !== 0x0c) {
2,712!
31
      var err  = new TypeError('Received invalid field length');
×
32
      err.code = 'PARSER_INVALID_FIELD_LENGTH';
×
33
      throw err;
×
34
    }
35

36
    this.charsetNr   = parser.parseUnsignedNumber(2);
2,712✔
37
    this.length      = parser.parseUnsignedNumber(4);
2,712✔
38
    this.type        = parser.parseUnsignedNumber(1);
2,712✔
39
    this.flags       = parser.parseUnsignedNumber(2);
2,712✔
40
    this.decimals    = parser.parseUnsignedNumber(1);
2,712✔
41

42
    var filler       = parser.parseBuffer(2);
2,712✔
43
    if (filler[0] !== 0x0 || filler[1] !== 0x0) {
2,712!
44
      var err  = new TypeError('Received invalid filler');
×
45
      err.code = 'PARSER_INVALID_FILLER';
×
46
      throw err;
×
47
    }
48

49
    // parsed flags
50
    this.zeroFill    = (this.flags & 0x0040 ? true : false);
2,712✔
51

52
    if (parser.reachedPacketEnd()) {
2,712✔
53
      return;
2,668✔
54
    }
55

56
    this.default     = parser.parseLengthCodedString();
44✔
57
  } else {
58
    this.table       = parser.parseLengthCodedString();
×
59
    this.name        = parser.parseLengthCodedString();
×
60
    this.length      = parser.parseUnsignedNumber(parser.parseUnsignedNumber(1));
×
61
    this.type        = parser.parseUnsignedNumber(parser.parseUnsignedNumber(1));
×
62
  }
63
};
64

65
FieldPacket.prototype.write = function(writer) {
396✔
66
  if (this.protocol41) {
124!
67
    writer.writeLengthCodedString(this.catalog);
124✔
68
    writer.writeLengthCodedString(this.db);
124✔
69
    writer.writeLengthCodedString(this.table);
124✔
70
    writer.writeLengthCodedString(this.orgTable);
124✔
71
    writer.writeLengthCodedString(this.name);
124✔
72
    writer.writeLengthCodedString(this.orgName);
124✔
73

74
    writer.writeLengthCodedNumber(0x0c);
124✔
75
    writer.writeUnsignedNumber(2, this.charsetNr || 0);
124!
76
    writer.writeUnsignedNumber(4, this.length || 0);
124✔
77
    writer.writeUnsignedNumber(1, this.type || 0);
124!
78
    writer.writeUnsignedNumber(2, this.flags || 0);
124✔
79
    writer.writeUnsignedNumber(1, this.decimals || 0);
124✔
80
    writer.writeFiller(2);
124✔
81

82
    if (this.default !== undefined) {
124✔
83
      writer.writeLengthCodedString(this.default);
44✔
84
    }
85
  } else {
86
    writer.writeLengthCodedString(this.table);
×
87
    writer.writeLengthCodedString(this.name);
×
88
    writer.writeUnsignedNumber(1, 0x01);
×
89
    writer.writeUnsignedNumber(1, this.length);
×
90
    writer.writeUnsignedNumber(1, 0x01);
×
91
    writer.writeUnsignedNumber(1, this.type);
×
92
  }
93
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc