fix + test handling of chr() on Oracle, Derby, MySQL

- Derby simply doesn't have it
- in MySQL it's necessary to specify the character set
- add ascii() and chr() to OracleDialect
This commit is contained in:
Gavin King 2022-09-16 08:44:49 +02:00
parent 3ddfa3f47c
commit cf51b92aeb
5 changed files with 12 additions and 4 deletions

View File

@ -256,7 +256,6 @@ public class DerbyDialect extends Dialect {
functionFactory.concat_pipeOperator();
functionFactory.cot();
functionFactory.chr_char();
functionFactory.degrees();
functionFactory.radians();
functionFactory.log10();

View File

@ -29,7 +29,6 @@ import java.time.temporal.TemporalAccessor;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

View File

@ -54,6 +54,7 @@ import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMu
import org.hibernate.dialect.temptable.TemporaryTableKind;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.query.sqm.produce.function.FunctionParameterType;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
@ -470,7 +471,6 @@ public class MySQLDialect extends Dialect {
functionFactory.bitLength();
functionFactory.octetLength();
functionFactory.ascii();
functionFactory.chr_char();
functionFactory.instr();
functionFactory.substr();
//also natively supports ANSI-style substring()
@ -503,6 +503,12 @@ public class MySQLDialect extends Dialect {
.setArgumentListSignature("")
.register();
queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "chr", "char(?1 using ascii)" )
.setInvariantType(basicTypeRegistry.resolve( StandardBasicTypes.CHARACTER ))
.setExactArgumentCount(1)
.setParameterTypes(FunctionParameterType.INTEGER)
.register();
// MySQL timestamp type defaults to precision 0 (seconds) but
// we want the standard default precision of 6 (microseconds)
functionFactory.sysdateExplicitMicros();

View File

@ -15,7 +15,6 @@ import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.hibernate.HibernateException;
import org.hibernate.LockOptions;
import org.hibernate.QueryTimeoutException;
import org.hibernate.boot.model.TypeContributions;
@ -141,6 +140,8 @@ public class OracleDialect extends Dialect {
final TypeConfiguration typeConfiguration = queryEngine.getTypeConfiguration();
CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine);
functionFactory.ascii();
functionFactory.char_chr();
functionFactory.cosh();
functionFactory.sinh();
functionFactory.tanh();

View File

@ -331,6 +331,9 @@ public class FunctionTests {
.list();
session.createQuery("from EntityOfBasics e where chr(120) = 'z'")
.list();
assertThat( session.createQuery("select chr(65)").getSingleResult(), is('A') );
assertThat( session.createQuery("select ascii('A')").getSingleResult(), is(65) );
}
);
}