Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-551 [SQL Server] Update from join with limit throws syntax exception #2244

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

bog-walk
Copy link
Member

Description

Summary of the change:
Join.update(limit = ?) now uses correct syntax with SQL Server and fails early for MySQL. These were not caught because there was no test for this operation.

Detailed description:

  • Why:

Attempting to perform an update from a join, with a provided limit, throws a syntax exception for SQL Server:

com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'LIMIT'.

because generated SQL uses both TOP and LIMIT clauses, when only TOP syntax should be used.

An exception is also thrown for MySQL:

java.sql.SQLException: Incorrect usage of UPDATE and LIMIT

because LIMIT clause is being added even though the database does not support it for multiple-table syntax. Attempting to do so with this database should instead cause an early failure.

  • What:
    • SQL Server now uses TOP syntax alone if limit is not null.
    • MySQL throws UnsupportedByDialectException if limit is not null.

Type of Change

Please mark the relevant options with an "X":

  • Bug fix

Affected databases:

  • Mysql5
  • Mysql8
  • SqlServer

Checklist

  • Unit tests are in place
  • The build is green (including the Detekt check)

Related Issues

EXPOSED-551

…ax exception

Attempting to perform an update from a join, with a provided limit, throws a syntax
exception if either SQL Server or MySQL is used. The former because of an error in
generated SQL and the latter because it is not allowed (when it should fail early).
…ax exception

- Rebase from main
- Clean up tests to use local properties
@bog-walk bog-walk force-pushed the bog-walk/fix-join-update-limit branch from 8de51ad to 327a742 Compare September 19, 2024 18:53
@bog-walk bog-walk merged commit d3c60f2 into main Sep 19, 2024
5 checks passed
@bog-walk bog-walk deleted the bog-walk/fix-join-update-limit branch September 19, 2024 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants