From 7f14b2cbf82434bdbc9f0d2252268277daaedd4e Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Mon, 19 Feb 2024 14:38:04 +0100 Subject: [PATCH] HHH-16048 Handle integer division emulation also for TiDB --- .../hibernate/dialect/TiDBSqlAstTranslator.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/TiDBSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/TiDBSqlAstTranslator.java index fd53cf0521..0827d929ac 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/TiDBSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/TiDBSqlAstTranslator.java @@ -18,6 +18,7 @@ import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator; import org.hibernate.sql.ast.tree.MutationStatement; import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.ast.tree.delete.DeleteStatement; +import org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression; import org.hibernate.sql.ast.tree.expression.CastTarget; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.Expression; @@ -54,6 +55,20 @@ public class TiDBSqlAstTranslator extends AbstractSqlAs this.dialect = (TiDBDialect) super.getDialect(); } + @Override + public void visitBinaryArithmeticExpression(BinaryArithmeticExpression arithmeticExpression) { + if ( isIntegerDivisionEmulationRequired( arithmeticExpression ) ) { + appendSql( OPEN_PARENTHESIS ); + arithmeticExpression.getLeftHandOperand().accept( this ); + appendSql( " div " ); + arithmeticExpression.getRightHandOperand().accept( this ); + appendSql( CLOSE_PARENTHESIS ); + } + else { + super.visitBinaryArithmeticExpression(arithmeticExpression); + } + } + @Override protected void visitInsertSource(InsertSelectStatement statement) { if ( statement.getSourceSelectStatement() != null ) {