Skip to content

Commit

Permalink
Add warnings count for non-DML/DLL queries like SELECT
Browse files Browse the repository at this point in the history
  • Loading branch information
KunZhou-at committed Sep 21, 2023
1 parent 001a183 commit 479fa03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 10 additions & 5 deletions lib/commands/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Query extends Command {
this._fieldCount = 0;
this._rowParser = null;
this._fields = [];
this._warningCounts = [];
this._rows = [];
this._receivedFieldsCount = 0;
this._resultIndex = 0;
Expand Down Expand Up @@ -73,21 +74,23 @@ class Query extends Command {
this.queryTimeout = null;
}
if (this.onResult) {
let rows, fields;
let rows, fields, warningCounts;
if (this._resultIndex === 0) {
rows = this._rows[0];
fields = this._fields[0];
warningCounts = this._warningCounts[0];
} else {
rows = this._rows;
fields = this._fields;
warningCounts = this._warningCounts
}
if (fields) {
process.nextTick(() => {
this.onResult(null, rows, fields);
this.onResult(null, rows, fields, warningCounts);
});
} else {
process.nextTick(() => {
this.onResult(null, rows);
this.onResult(null, rows, fields, warningCounts);
});
}
}
Expand Down Expand Up @@ -227,9 +230,11 @@ class Query extends Command {
}

/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
row(packet, _connection) {
row(packet, _connection) {
if (packet.isEOF()) {
const status = packet.eofStatusFlags();
this._warningCounts[this._resultIndex] = packet.eofWarningCount();

const moreResults = status & ServerStatus.SERVER_MORE_RESULTS_EXISTS;
if (moreResults) {
this._resultIndex++;
Expand Down Expand Up @@ -302,7 +307,7 @@ class Query extends Command {
Timers.clearTimeout(this.queryTimeout);
this.queryTimeout = null;
}

const err = new Error('Query inactivity timeout');
err.errorno = 'PROTOCOL_SEQUENCE_TIMEOUT';
err.code = 'PROTOCOL_SEQUENCE_TIMEOUT';
Expand Down
8 changes: 4 additions & 4 deletions typings/mysql/lib/protocol/sequences/QueryableBase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export declare function QueryableBase<T extends QueryableConstructor>(
>(
sql: string,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| ((err: QueryError | null, result: T, fields: FieldPacket[], warningCount: number | number[]) => any)
| undefined
): Query;
query<
Expand All @@ -44,7 +44,7 @@ export declare function QueryableBase<T extends QueryableConstructor>(
sql: string,
values: any,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| ((err: QueryError | null, result: T, fields: FieldPacket[], warningCount: number | number[]) => any)
| undefined
): Query;
query<
Expand All @@ -59,7 +59,7 @@ export declare function QueryableBase<T extends QueryableConstructor>(
>(
options: QueryOptions,
callback?:
| ((err: QueryError | null, result: T, fields?: FieldPacket[]) => any)
| ((err: QueryError | null, result: T, fields: FieldPacket[], warningCount: number | number[]) => any)
| undefined
): Query;
query<
Expand All @@ -75,7 +75,7 @@ export declare function QueryableBase<T extends QueryableConstructor>(
options: QueryOptions,
values: any,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| ((err: QueryError | null, result: T, fields: FieldPacket[], warningCount: number | number[]) => any)
| undefined
): Query;
};
Expand Down

0 comments on commit 479fa03

Please sign in to comment.