|
19 | 19 | import org.hibernate.dialect.PostgreSQLDialect;
|
20 | 20 | import org.hibernate.dialect.SybaseDialect;
|
21 | 21 | import org.hibernate.dialect.TiDBDialect;
|
| 22 | +import org.hibernate.query.sqm.produce.function.FunctionArgumentException; |
| 23 | + |
22 | 24 | import org.hibernate.testing.TestForIssue;
|
23 | 25 | import org.hibernate.testing.orm.domain.StandardDomainModel;
|
24 | 26 | import org.hibernate.testing.orm.domain.gambit.EntityOfBasics;
|
@@ -829,6 +831,52 @@ public void testTrimFunction(SessionFactoryScope scope) {
|
829 | 831 | }
|
830 | 832 | }
|
831 | 833 |
|
| 834 | + @Test |
| 835 | + @JiraKey( "HHH-17435" ) |
| 836 | + public void testTrimFunctionParameters(SessionFactoryScope scope) { |
| 837 | + scope.inTransaction( |
| 838 | + session -> { |
| 839 | + assertThat( session.createQuery( "select trim(:param)", String.class ) |
| 840 | + .setParameter( "param", " hello " ) |
| 841 | + .getSingleResult(), is( "hello" ) ); |
| 842 | + assertThat( session.createQuery( "select trim(' ' from :param)", String.class ) |
| 843 | + .setParameter( "param", " hello " ) |
| 844 | + .getSingleResult(), is( "hello" ) ); |
| 845 | + assertThat( session.createQuery( "select trim('''' from :param)", String.class ) |
| 846 | + .setParameter( "param", "''hello'''" ) |
| 847 | + .getSingleResult(), is( "hello" ) ); |
| 848 | + assertThat( session.createQuery( "select trim(:param from '-- hello it''s me ---')", String.class ) |
| 849 | + .setParameter( "param", '-' ) |
| 850 | + .getSingleResult(), is( " hello it's me " ) ); |
| 851 | + assertThat( session.createQuery( "select trim(:param from '--- hello it''s me -- ')", String.class ) |
| 852 | + .setParameter( "param", '-' ) |
| 853 | + .getSingleResult(), is( " hello it's me -- " ) ); |
| 854 | + assertThat( session.createQuery( "select trim(leading ?1 from ' hello it''s me ')", String.class ) |
| 855 | + .setParameter( 1, ' ' ) |
| 856 | + .getSingleResult(), is( "hello it's me " ) ); |
| 857 | + assertThat( session.createQuery( "select trim(trailing ?1 from ' hello it''s me ')", String.class ) |
| 858 | + .setParameter( 1, ' ' ) |
| 859 | + .getSingleResult(), is( " hello it's me" ) ); |
| 860 | + assertThat( session.createQuery( "select trim(?1 from ?2)", String.class ) |
| 861 | + .setParameter( 1, ' ' ) |
| 862 | + .setParameter( 2, " hello it's me " ) |
| 863 | + .getSingleResult(), is( "hello it's me" ) ); |
| 864 | + } |
| 865 | + ); |
| 866 | + |
| 867 | + try { |
| 868 | + scope.inTransaction( |
| 869 | + session -> session.createQuery( "select trim(:param from 'hello')", String.class ) |
| 870 | + .setParameter( "param", 1 ) |
| 871 | + .getResultList() |
| 872 | + ); |
| 873 | + fail(); |
| 874 | + } |
| 875 | + catch (IllegalArgumentException e) { |
| 876 | + assertThat( e.getCause(), is( instanceOf( FunctionArgumentException.class ) ) ); |
| 877 | + } |
| 878 | + } |
| 879 | + |
832 | 880 | @Test
|
833 | 881 | @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsPadWithChar.class)
|
834 | 882 | public void testPadFunction(SessionFactoryScope scope) {
|
|
0 commit comments