HHH-16048 Handle integer division emulation also for TiDB

This commit is contained in:
Christian Beikov 2024-02-19 14:38:04 +01:00
parent d7a46451ce
commit 7f14b2cbf8
1 changed files with 15 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
import org.hibernate.sql.ast.tree.MutationStatement; import org.hibernate.sql.ast.tree.MutationStatement;
import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.ast.tree.delete.DeleteStatement; 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.CastTarget;
import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.ColumnReference;
import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.Expression;
@ -54,6 +55,20 @@ public class TiDBSqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAs
this.dialect = (TiDBDialect) super.getDialect(); 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 @Override
protected void visitInsertSource(InsertSelectStatement statement) { protected void visitInsertSource(InsertSelectStatement statement) {
if ( statement.getSourceSelectStatement() != null ) { if ( statement.getSourceSelectStatement() != null ) {