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

Support MySql 5.7 delete queries #2703

Closed
mahe-ymc opened this issue Feb 13, 2023 · 4 comments
Closed

Support MySql 5.7 delete queries #2703

mahe-ymc opened this issue Feb 13, 2023 · 4 comments

Comments

@mahe-ymc
Copy link
Contributor

mahe-ymc commented Feb 13, 2023

Version: 4.6.0
Module: quill-jdbc
Database: mysql

Expected behavior

Delete queries should produce SQL accepted by MySql 5.7

Actual behavior

Delete queries use Table Aliases, which are unsupported by MySql 5.7.

Steps to reproduce the behavior

https://scastie.scala-lang.org/y4KUdZk3SLKtYkktHgJ3UA
Should be DELETE FROM person WHERE name = 'John'

Workaround

@plmuninn
Copy link

plmuninn commented Mar 4, 2023

I have same issue - is there is a way to workaround it using sql ?

@rider-yi
Copy link

me too. #2540 did not solve the problem.

@deterdw
Copy link
Contributor

deterdw commented Apr 21, 2023

I've hit this issue on MariaDB 10 too.

For those looking for a work-around, the following (snipped from SQLServerDialect) seems to do the trick:

import io.getquill._
import io.getquill.ast._
import io.getquill.idiom.StatementInterpolator._

trait MariaDBDialect extends MySQLDialect {
  override protected def actionTokenizer(insertEntityTokenizer: Tokenizer[Entity])(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy, idiomContext: IdiomContext): Tokenizer[ast.Action] =
    Tokenizer[ast.Action] {
      // Delete(Filter(...)) usually cause a table alias i.e. `DELETE FROM People <alias> WHERE ...`
      // since the alias is used in the WHERE clause. This functionality removes that because MariaDB (and MySQL 5.7) doesn't support aliasing in deletes.
      //case Update(Filter(table: Entity, x, where), assignments) =>
      //  stmt"UPDATE ${table.token} SET ${assignments.token} WHERE ${where.token}"
      case Delete(Filter(table: Entity, x, where)) =>
        stmt"DELETE FROM ${table.token} WHERE ${where.token}"
      case other => super.actionTokenizer(insertEntityTokenizer).token(other)
    }
}
object MariaDBDialect extends MariaDBDialect

Of course you'll have to copy & adapt your specific context too to use the new dialect.

@juliano
Copy link
Collaborator

juliano commented Jul 4, 2023

Solved in #2704

@juliano juliano closed this as completed Jul 4, 2023
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

No branches or pull requests

5 participants