-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
#3007 (released in 0.7.4) deprecates execute_many() and fetch_many() in the query*() family of functions. These functions were meant to allow executing a single query string containing multiple SQL statements while still using bind parameters. These will be removed in 0.8.0.
This is because only SQLite ever supported this feature, due to the idiosyncrasy of its prepared statement interface being the primary way to execute SQL against a database. All other databases forbid multiple statements in one string when using prepared statements as a defense against SQL injection. Thus, it's extremely confusing to have such methods as part of a database-agnostic API. And, it was never supported by the query*!() macros because it was unclear what they should return when processing a query string with multiple statements.
To support multiple queries in one prepared statement for arbitrary database backends would require parsing the string to find ; delimiters, prepare it as multiple statements, and then execute them in an implicit transaction. Doing this much behind the scenes would be antithetical to the design of SQLx. The SQLite driver had to implement this to support migrations in line with the other drivers, but sqlite3_prepare() in the C API is explicitly designed to incrementally parse a single query string into multiple statements for this exact reason, so we at least don't have to parse SQL ourselves.
The raw_sql API added in #3007 includes the ability to execute multiple statements in one query string, with the caveat that bind parameters cannot be used (as they require the prepared statement interface).
If anyone needs to be able to execute multiple query statements in one string, with bind parameters, using the SQLite driver, this issue is open to discuss what that API should look like. Supporting this in other drivers that have similar support in their prepared statement interfaces is an option, but supporting for databases like Postgres which don't is out of scope. Be prepared to explain why you cannot work around this by explicitly executing multiple statements in a transaction.
This issue will be closed at the conclusion of the next release cycle (0.8.x) if no one responds to it by then, under the assumption that no one had a problem with the deprecation and removal of the aforementioned APIs.