0

In many cases preparing the statement would be preferable, of course. But sometimes that can bring more harm than good.

See this question and the partial solution I've posted. In a nutshell, sometimes we need to create a big query with a mixture of static and dynamic parameters. The static parameters will obviously lead to different query strings each time, so preparing that big statement will be pointless as it will practically only be called once.

I am using the mysql crate and when I try to call an INSERT with more than 64K dynamic parameters, I get this error:

MySqlError { ERROR 1390 (HY000): Prepared statement contains too many placeholders }

I can do that easily with some other languages. For instance, with Python's mysql-connector-python lib I have no problem passing a lot more than 64K dynamic parameters.

Does Rust's MySQL crate have a way to simply run a query without the overhead and limitations of preparing the statement?

at54321
  • 8,726
  • 26
  • 46
  • Use a query where all parameters are combined into one single parameter (for a row or even for all rows to be inserted, use, for exampe, JSON), and parse this combined value back to separate values during insertion. – Akina Apr 22 '21 at 06:30
  • Have you tried not preparing the statement, and not using an execution method which *explicitly tells you it's going to prepare the statement*? – Masklinn Apr 22 '21 at 07:19
  • @Masklinn I used [`exec_drop()`](https://docs.rs/mysql/20.1.0/mysql/prelude/trait.Queryable.html#method.exec_drop) which does _not_ mention anything about preparing the statement: "Executes the given stmt and drops the result.". But apparently it does prepare the statement, as can be seen from my post. – at54321 Apr 22 '21 at 08:03

0 Answers0