question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prepared statement does not work for Symbol operators

See original GitHub issue

What are you doing?

class User extends Model {}
User.init({
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  email: { type: DataTypes.STRING },
  failed_logins: { type: DataTypes.INTEGER }
}, {
  sequelize,
  tableName: 'users'
});

What do you expect to happen?

await User.update({
  failed_logins: 0
}, {
  where: {
    id: 1,
    failed_logins: { [Op.eq]: 4 }
  }
});

Mysql general_log shows

# Actual
Prepare | UPDATE `users` SET `failed_logins`=? WHERE `id` = ? AND `failed_logins` = 4

But it is expected that failed_logins = ?

# Expected
Prepare | UPDATE `users` SET `failed_logins`=? WHERE `id` = ? AND `failed_logins` = ?

Environment

Dialect:

  • mysql
  • postgres
  • sqlite
  • mssql
  • any Dialect mysql2 version: 1.6.5 Database version: 8.0.14 Sequelize version: 5.8.6 Node Version: v10.15.0 OS: Win10

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ephyscommented, May 2, 2022

That issue about prepared statements not being cleared is being tracked here: https://github.com/sequelize/sequelize/issues/10832, I’ll post a status update over there

2reactions
katreniakcommented, May 2, 2022

The substituted parameter values inside prepared statements cause prepared statements to leak inside db. To release them, the db connection has to be closed.

The db connections are typically closed on connection options.pool.idle timeout. But when the workload is able to keep all options.pool.max connections busy for long enough time, eventually the (in case of mysql) sysvar_max_prepared_stmt_count limit is reached and all subsequent db requests are denied with Can't create more than max_prepared_stmt_count statements.

Is there a way to prevent this problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot run prepared statement/function in postgres
you don't execute prepared statement when you select EXECUTE(get_account("A200")); - you execute your function. Here's example of how to run ...
Read more >
Db2 12 - Db2 SQL - PREPARE - IBM
The PREPARE statement creates an executable SQL statement from a string form of the statement. The character-string form is called a statement string....
Read more >
PREPARE | Pivotal Greenplum Docs
Description. PREPARE creates a prepared statement. A prepared statement is a server-side object that can be used to optimize performance.
Read more >
MySQL 8.0 Reference Manual :: 13.5 Prepared Statements
SQL syntax for prepared statements can be used within stored procedures, but not in stored functions or triggers. However, a cursor cannot be...
Read more >
Prepared statements and stored procedures - Manual - PHP
it is a good practice not using double quotes in sql strings. This way you can ensure that no variable is injected in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found