Skip to content

port prepared statements support from node-mysql2 #616

Open
@sidorares

Description

@sidorares

This issue is to discuss public api and track progress of port of prepared statements (aka "binary protocol") implementation from https://github.com/sidorares/node-mysql2

See also: #274 and sidorares/node-mysql2#52

I'll start discussion in #274 again once there is something to try.

node-mysql2 api: exactly the same as query(), but it's execute()
Under the hood:

  • sql query is used as a key in internal statement id's hash. If there is id, it is used.
  • if there is no id in hash, COM_STMT_PREPARE command is executed and id saved.
  • COM_STMT_EXECUTE command with id and serialised parameters is sent if prepare is successful
  • no interpolation/escaping happens on the client. All parameters are sent individually using binary protocol.

Currently there is no separate public prepare and unprepare and I'm not sure if we need them (unprepare might be useful if you intend to create hundreds of statements, but most often than not this is sign of abusing the idea of prepared statements, for example trying to prepare query with already escaped parameter)

Both parameters and result values are sent "typed" (opposed to "text protocol" where they are serialised as text) so there might be slightly different semantics of typeCast.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions