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

ER_MAX_PREPARED_STMT_COUNT_REACHED #963

Open
okbrown opened this issue May 9, 2019 · 2 comments
Open

ER_MAX_PREPARED_STMT_COUNT_REACHED #963

okbrown opened this issue May 9, 2019 · 2 comments
Labels

Comments

@okbrown
Copy link

okbrown commented May 9, 2019

Hi,
Can someone please explain why I get this error ER_MAX_PREPARED_STMT_COUNT_REACHED when I am following this documentation

Here is my code:

export const getById = (id) => {
  return db().then(async (connection) => {
    const sql = await connection.format(`
      SELECT * FROM ${baseTables} 
      WHERE ${baseWhere} 
      AND status = 'ACTIVE' 
      AND id = ?`,
      [ id ]
    );
    const resultSet = await connection.execute(sql);
    const row = get(resultSet, "[0].[0]");
    if (row) {
      const rowItem = t.buildRow(row);
      connection.unprepare(sql);
      connection.release();

      return rowItem;
    }
  });
};

Yet every couple months I get this error: ER_MAX_PREPARED_STMT_COUNT_REACHED
I have read:
#158
#393
#702

Should I do the manual version, and do it like this instead?

export const getById = (id) => {
  return db().then(async (connection) => {
    
     const sql = await connection.prepare(`
      SELECT * FROM ${baseTables} 
      WHERE ${baseWhere} 
      AND status = 'ACTIVE' 
      AND id = ?`,
      [ id ]
    );

    const resultSet = await connection.execute(sql);
    const row = get(resultSet, "[0].[0]");
    if (row) {
      const rowItem = t.buildRow(row);
      connection.close();

      return rowItem;
    }
  });
};

Thanks.

@afwn90cj93201nixr2e1re
Copy link
Contributor

afwn90cj93201nixr2e1re commented May 9, 2019

Release connection and unprepare before if condition. Coz row can be empty.

@sidorares
Copy link
Owner

@okbrown you are formatting sql interpolatining parameters on the client and then send it to server to prepare ( each time parameter is different it's a new prepared statement because sql text is different )

Should I do the manual version, and do it like this instead?

main problem is that "format" is client-side interpolation while "prepare" is server-side

Your second example can be still automatic, just send constant query separate from variable parameters with .execute() or .prepare()

export const getById = async (id, connection) => {  
    const resultSet = await connection.execute((`
      SELECT * FROM ${baseTables} 
      WHERE ${baseWhere} 
      AND status = 'ACTIVE' 
      AND id = ?`,
      [ id ]
    );
    const row = get(resultSet, "[0].[0]");
    if (row) {
      const rowItem = t.buildRow(row);
      return rowItem;
    }
  return null;
};

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

No branches or pull requests

3 participants