aboutsummaryrefslogtreecommitdiff
path: root/node_modules/mysql2/lib/packets/resultset_header.js
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.h.kronqvist@gmail.com>2022-03-05 19:02:27 +0200
committerJoel Kronqvist <joel.h.kronqvist@gmail.com>2022-03-05 19:02:27 +0200
commit5d309ff52cd399a6b71968a6b9a70c8ac0b98981 (patch)
tree360f7eb50f956e2367ef38fa1fc6ac7ac5258042 /node_modules/mysql2/lib/packets/resultset_header.js
parentb500a50f1b97d93c98b36ed9a980f8188d648147 (diff)
downloadLYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.tar.gz
LYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.zip
Added node_modules for the updating to work properly.
Diffstat (limited to 'node_modules/mysql2/lib/packets/resultset_header.js')
-rw-r--r--node_modules/mysql2/lib/packets/resultset_header.js110
1 files changed, 110 insertions, 0 deletions
diff --git a/node_modules/mysql2/lib/packets/resultset_header.js b/node_modules/mysql2/lib/packets/resultset_header.js
new file mode 100644
index 0000000..e6a8cd4
--- /dev/null
+++ b/node_modules/mysql2/lib/packets/resultset_header.js
@@ -0,0 +1,110 @@
+'use strict';
+
+// TODO: rename to OK packet
+// https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html
+
+const Packet = require('./packet.js');
+const ClientConstants = require('../constants/client.js');
+const ServerSatusFlags = require('../constants/server_status.js');
+
+const EncodingToCharset = require('../constants/encoding_charset.js');
+const sessionInfoTypes = require('../constants/session_track.js');
+
+class ResultSetHeader {
+ constructor(packet, connection) {
+ const bigNumberStrings = connection.config.bigNumberStrings;
+ const encoding = connection.serverEncoding;
+ const flags = connection._handshakePacket.capabilityFlags;
+ const isSet = function(flag) {
+ return flags & ClientConstants[flag];
+ };
+ if (packet.buffer[packet.offset] !== 0) {
+ this.fieldCount = packet.readLengthCodedNumber();
+ if (this.fieldCount === null) {
+ this.infileName = packet.readString(undefined, encoding);
+ }
+ return;
+ }
+ this.fieldCount = packet.readInt8(); // skip OK byte
+ this.affectedRows = packet.readLengthCodedNumber(bigNumberStrings);
+ this.insertId = packet.readLengthCodedNumberSigned(bigNumberStrings);
+ this.info = '';
+ if (isSet('PROTOCOL_41')) {
+ this.serverStatus = packet.readInt16();
+ this.warningStatus = packet.readInt16();
+ } else if (isSet('TRANSACTIONS')) {
+ this.serverStatus = packet.readInt16();
+ }
+ let stateChanges = null;
+ if (isSet('SESSION_TRACK') && packet.offset < packet.end) {
+ this.info = packet.readLengthCodedString(encoding);
+
+ if (this.serverStatus && ServerSatusFlags.SERVER_SESSION_STATE_CHANGED) {
+ // session change info record - see
+ // https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html#cs-sect-packet-ok-sessioninfo
+ let len =
+ packet.offset < packet.end ? packet.readLengthCodedNumber() : 0;
+ const end = packet.offset + len;
+ let type, key, stateEnd;
+ if (len > 0) {
+ stateChanges = {
+ systemVariables: {},
+ schema: null,
+ trackStateChange: null
+ };
+ }
+ while (packet.offset < end) {
+ type = packet.readInt8();
+ len = packet.readLengthCodedNumber();
+ stateEnd = packet.offset + len;
+ if (type === sessionInfoTypes.SYSTEM_VARIABLES) {
+ key = packet.readLengthCodedString(encoding);
+ const val = packet.readLengthCodedString(encoding);
+ stateChanges.systemVariables[key] = val;
+ if (key === 'character_set_client') {
+ const charsetNumber = EncodingToCharset[val];
+ connection.config.charsetNumber = charsetNumber;
+ }
+ } else if (type === sessionInfoTypes.SCHEMA) {
+ key = packet.readLengthCodedString(encoding);
+ stateChanges.schema = key;
+ } else if (type === sessionInfoTypes.STATE_CHANGE) {
+ stateChanges.trackStateChange = packet.readLengthCodedString(
+ encoding
+ );
+ } else {
+ // unsupported session track type. For now just ignore
+ }
+ packet.offset = stateEnd;
+ }
+ }
+ } else {
+ this.info = packet.readString(undefined, encoding);
+ }
+ if (stateChanges) {
+ this.stateChanges = stateChanges;
+ }
+ const m = this.info.match(/\schanged:\s*(\d+)/i);
+ if (m !== null) {
+ this.changedRows = parseInt(m[1], 10);
+ }
+ }
+
+ // TODO: should be consistent instance member, but it's just easier here to have just function
+ static toPacket(fieldCount, insertId) {
+ let length = 4 + Packet.lengthCodedNumberLength(fieldCount);
+ if (typeof insertId !== 'undefined') {
+ length += Packet.lengthCodedNumberLength(insertId);
+ }
+ const buffer = Buffer.allocUnsafe(length);
+ const packet = new Packet(0, buffer, 0, length);
+ packet.offset = 4;
+ packet.writeLengthCodedNumber(fieldCount);
+ if (typeof insertId !== 'undefined') {
+ packet.writeLengthCodedNumber(insertId);
+ }
+ return packet;
+ }
+}
+
+module.exports = ResultSetHeader;