node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

fixed #476: Problem using execute and array parameters

Open Leask opened this issue 5 years ago • 9 comments

Fixed issue #476: https://github.com/sidorares/node-mysql2/issues/476#issuecomment-264342349

This is a confusing issue, and I know that the two-step execution can greatly improve performance. But in cases where the statement contains an IN (?) this will cause some unexpected code failures. Many known issues are related to this.

In my opinion, the correctness of code is more important than performance. I suggest that when the SQL command contains IN (?), the formatter should be used first to format the command. Although this will lead to additional preparation processes, this simple modification can ensure that the code execution meets the expectations of most engineers in most cases.

Thanks for your excellent work!

Leask avatar Jan 18 '20 21:01 Leask

It's now 2024, is there any update on this PR?

melroy89 avatar Apr 07 '24 17:04 melroy89

It's been a long time, but thanks @Leask 🤝

Regardless the performance, this PR needs a rebase to trigger all current tests. Also, it would be good to have additional tests covering these changes 🙋🏻‍♂️

In my opinion, the correctness of code is more important than performance.

About this, I believe that @sidorares can handle this discussion better.

wellwelwel avatar Apr 07 '24 20:04 wellwelwel

Hi all! It's cool to be mentioned. It's been a long time. But if you guys can fix this, it will be excellent.

Leask avatar Apr 07 '24 20:04 Leask

Based in https://github.com/sidorares/node-mysql2/issues/908#issuecomment-454168035, I suggest waiting for a conclusion from @sidorares before working on it 🙋🏻‍♂️


Notes

  • https://github.com/sidorares/node-mysql2/issues/796#issuecomment-397253582

  • https://github.com/sidorares/node-mysql2/issues/553#issuecomment-437221838

  • Screenshot 2024-04-07 at 17 21 24

wellwelwel avatar Apr 07 '24 20:04 wellwelwel

👌

Leask avatar Apr 07 '24 20:04 Leask

Also consider updating the PR title, I believe the title is not helping either :P

melroy89 avatar Apr 07 '24 21:04 melroy89

Also consider updating the PR title, I believe the title is not helping either :P

Done 🤝

Leask avatar Apr 07 '24 22:04 Leask

I'm open to discuss better DX here in general ( especially more helpful errors suggesting the fix ). However there is so many things that can potentially go wrong if we try to extract information from sql using a simple regex. Comments, strings, and many more scenarios can make the test incorrect.

Happy to continue discussion, but my vision in general:

  • if logic requires understanding of sql structure, this logic needs full sql parser and should probably live somewhere in a higher level library using this driver ( ORM / routers etc )
  • it's ok to have some code that tries to guess intention at an error handling level "did you mean field X" / "If the intention is to interpolate IN parameters, use this approach"

sidorares avatar Apr 08 '24 10:04 sidorares