ErrorPacket.js 1007 B

1234567891011121314151617181920212223242526272829303132333435
  1. module.exports = ErrorPacket;
  2. function ErrorPacket(options) {
  3. options = options || {};
  4. this.fieldCount = options.fieldCount;
  5. this.errno = options.errno;
  6. this.sqlStateMarker = options.sqlStateMarker;
  7. this.sqlState = options.sqlState;
  8. this.message = options.message;
  9. }
  10. ErrorPacket.prototype.parse = function(parser) {
  11. this.fieldCount = parser.parseUnsignedNumber(1);
  12. this.errno = parser.parseUnsignedNumber(2);
  13. // sqlStateMarker ('#' = 0x23) indicates error packet format
  14. if (parser.peak() === 0x23) {
  15. this.sqlStateMarker = parser.parseString(1);
  16. this.sqlState = parser.parseString(5);
  17. }
  18. this.message = parser.parsePacketTerminatedString();
  19. };
  20. ErrorPacket.prototype.write = function(writer) {
  21. writer.writeUnsignedNumber(1, 0xff);
  22. writer.writeUnsignedNumber(2, this.errno);
  23. if (this.sqlStateMarker) {
  24. writer.writeString(this.sqlStateMarker);
  25. writer.writeString(this.sqlState);
  26. }
  27. writer.writeString(this.message);
  28. };