OkPacket.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. module.exports = OkPacket;
  2. function OkPacket() {
  3. this.fieldCount = undefined;
  4. this.affectedRows = undefined;
  5. this.insertId = undefined;
  6. this.serverStatus = undefined;
  7. this.warningCount = undefined;
  8. this.message = undefined;
  9. }
  10. OkPacket.prototype.parse = function(parser) {
  11. this.fieldCount = parser.parseUnsignedNumber(1);
  12. this.affectedRows = parser.parseLengthCodedNumber();
  13. this.insertId = parser.parseLengthCodedNumber();
  14. this.serverStatus = parser.parseUnsignedNumber(2);
  15. this.warningCount = parser.parseUnsignedNumber(2);
  16. this.message = parser.parsePacketTerminatedString();
  17. this.changedRows = 0;
  18. var m = this.message.match(/\schanged:\s*(\d+)/i);
  19. if (m !== null) {
  20. this.changedRows = parseInt(m[1], 10);
  21. }
  22. };
  23. OkPacket.prototype.write = function(writer) {
  24. writer.writeUnsignedNumber(1, 0x00);
  25. writer.writeLengthCodedNumber(this.affectedRows || 0);
  26. writer.writeLengthCodedNumber(this.insertId || 0);
  27. writer.writeUnsignedNumber(2, this.serverStatus || 0);
  28. writer.writeUnsignedNumber(2, this.warningCount || 0);
  29. writer.writeString(this.message);
  30. };