dolthub / vitess

Vitess is a database clustering system for horizontal scaling of MySQL.
http://vitess.io
Apache License 2.0
22 stars 20 forks source link

fix detection of multi-statements in `ComPrepare` #359

Closed jycor closed 2 months ago

jycor commented 2 months ago

Currently, preparing multi-statements is not supported; so we can't prepare a query like select ?; select ?;. However, the check for this condition just looked for any characters after the first ;, which meant that queries like select ?; \n would incorrectly throw an error.

This was made apparent using the Prisma ORM, which runs the query:

SELECT TABLE_NAME AS view_name, VIEW_DEFINITION AS view_sql
FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA = ?;

The above query ends in a newline character.

The fix is to use SplitStatementToPieces(), which trims these white space characters, and check if there's exactly one piece; this was taken from the vitessio repo: https://github.com/vitessio/vitess/blob/main/go/mysql/conn.go#L1204

fixes https://github.com/dolthub/dolt/issues/8157