This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
node-task/node_modules/mysql2/lib/packets/resultset_header.js

41 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2014-09-24 17:56:53 -04:00
// TODO: rename to OK packet
var Packet = require('../packets/packet');
function ResultSetHeader(packet, bigNumberStrings)
{
if (packet.buffer[packet.offset] !== 0) {
this.fieldCount = packet.readLengthCodedNumber();
} else {
this.fieldCount = packet.readInt8(); // skip OK byte
this.affectedRows = packet.readLengthCodedNumber(bigNumberStrings);
this.insertId = packet.readLengthCodedNumber(bigNumberStrings);
this.serverStatus = packet.readInt16();
this.warningStatus = packet.readInt16();
}
// snippet from mysql-native:
// res.affected_rows = this.lcnum();
// res.insert_id = this.lcnum();
// res.server_status = this.num(2);
// res.warning_count = this.num(2);
// TODO: extra
}
// TODO: should be consistent instance member, but it's just easier here to have just function
ResultSetHeader.toPacket = function(fieldCount, insertId, sequenceId) {
var length = 4 + Packet.lengthCodedNumberLength(fieldCount);
if (typeof(insertId) != 'undefined')
length += Packet.lengthCodedNumberLength(insertId);
var buffer = new Buffer(length);
var packet = new Packet(0, buffer);
packet.offset = 4;
packet.writeLengthCodedNumber(fieldCount);
if (typeof(insertId) != 'undefined')
packet.writeLengthCodedNumber(insertId);
return packet;
};
module.exports = ResultSetHeader;