Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql stored procedures #109

Open
Myth06 opened this issue Apr 7, 2021 · 3 comments
Open

mysql stored procedures #109

Myth06 opened this issue Apr 7, 2021 · 3 comments
Labels
question Further information is requested

Comments

@Myth06
Copy link

Myth06 commented Apr 7, 2021

When I work with queries written on backend, it works fine. But when call stored procedures from 'client.query' and run using restClient, it first gives result set and at second run gives{affectedRows:0,lastInsetId:0} .What is the problem? Is there a specific way to call stored procedure different from nodejs?

@lideming
Copy link
Collaborator

lideming commented May 3, 2021

Hi, could you please put some code here that can reproduce the problem?

@lideming lideming added the question Further information is requested label May 3, 2021
@Ingrim4
Copy link

Ingrim4 commented Jan 12, 2022

Hey just encountered the same problem. The reason this happens is that a stored procedure can select rows as well as update rows at the same time so you need to read two packets because the server will return:

  1. the selected rows
  2. the affected rows

Here's a cheap and hacky work around util this is fixed:

query(query: string, params?: any[]): Promise<any> {
  return this.client.useConnection(async connection => {
    const result = await connection.query(query, params);
    if (query.toLowerCase().startsWith('call ')) {
      await (connection as any).nextPacket();
    }
    return result;
  });
}

@Ingrim4
Copy link

Ingrim4 commented Jan 19, 2022

From the official documentation:

As of MySQL 5.7.5, the resultset is followed by an OK_Packet, and this OK_Packet has the SERVER_MORE_RESULTS_EXISTS flag set to start processing the next resultset.

The client has to announce that it wants multi-resultsets by either setting the CLIENT_MULTI_RESULTS or CLIENT_PS_MULTI_RESULTS capability.

I would guess that multi-resultset aren't handled correctly since I didn't see any handling of the server status flags in received packets which would normaly indicate a trailing OK_Packet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants