HHH-7070 Fixed some SybaseASE15Dialect function definitions (dateadd, datediff, datepart, atn2)
(cherry picked from commit 7eebb0f73d
)
This commit is contained in:
parent
cbf255e4f0
commit
5adf730c42
|
@ -51,8 +51,8 @@ public class SybaseASE15Dialect extends SybaseDialect {
|
|||
)
|
||||
);
|
||||
|
||||
registerFunction( "atan2", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "atn2(?1, ?2" ) );
|
||||
registerFunction( "atn2", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "atn2(?1, ?2" ) );
|
||||
registerFunction( "atan2", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "atn2(?1, ?2)" ) );
|
||||
registerFunction( "atn2", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "atn2(?1, ?2)" ) );
|
||||
|
||||
registerFunction( "biginttohex", new SQLFunctionTemplate( StandardBasicTypes.STRING, "biginttohext(?1)" ) );
|
||||
registerFunction( "char_length", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "char_length(?1)" ) );
|
||||
|
@ -73,9 +73,9 @@ public class SybaseASE15Dialect extends SybaseDialect {
|
|||
"data_pages", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "data_pages(?1, ?2, ?3, ?4)" )
|
||||
);
|
||||
registerFunction( "datalength", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datalength(?1)" ) );
|
||||
registerFunction( "dateadd", new SQLFunctionTemplate( StandardBasicTypes.TIMESTAMP, "dateadd" ) );
|
||||
registerFunction( "datediff", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datediff" ) );
|
||||
registerFunction( "datepart", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datepart" ) );
|
||||
registerFunction( "dateadd", new SQLFunctionTemplate( StandardBasicTypes.TIMESTAMP, "dateadd(?1, ?2, ?3)" ) );
|
||||
registerFunction( "datediff", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datediff(?1, ?2, ?3)" ) );
|
||||
registerFunction( "datepart", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datepart(?1, ?2)" ) );
|
||||
registerFunction( "datetime", new SQLFunctionTemplate( StandardBasicTypes.TIMESTAMP, "datetime" ) );
|
||||
registerFunction( "db_id", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "db_id(?1)" ) );
|
||||
registerFunction( "difference", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "difference(?1,?2)" ) );
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
<property name="length" />
|
||||
<property name="weight" />
|
||||
<property name="price" />
|
||||
<property name="date" />
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.test.dialect.function;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -17,6 +18,7 @@ public class Product {
|
|||
private int length;
|
||||
private long weight;
|
||||
private BigDecimal price;
|
||||
private Date date;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
|
@ -50,4 +52,12 @@ public class Product {
|
|||
this.price = price;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.dialect.function;
|
||||
|
||||
import static java.util.Calendar.MONTH;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.dialect.SybaseASE15Dialect;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Richard H. Tingstad
|
||||
*/
|
||||
@RequiresDialect(value = { SybaseASE15Dialect.class })
|
||||
public class SybaseASE15FunctionTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
private Calendar calendar = Calendar.getInstance();
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "dialect/function/Product.hbm.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareTest() throws Exception {
|
||||
Product product = new Product();
|
||||
product.setPrice(new BigDecimal(0.5));
|
||||
product.setDate(calendar.getTime());
|
||||
openSession().save(product);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharLengthFunction() {
|
||||
Query query = session.createQuery("select char_length('123456') from Product");
|
||||
assertEquals(6, ((Number) query.uniqueResult()).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7070")
|
||||
public void testDateaddFunction() {
|
||||
Query query = session.createQuery("select dateadd(dd, 1, p.date) from Product p");
|
||||
assertTrue(calendar.getTime().before((Date) query.uniqueResult()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7070")
|
||||
public void testDatepartFunction() {
|
||||
Query query = session.createQuery("select datepart(month, p.date) from Product p");
|
||||
assertEquals(calendar.get(MONTH) + 1, ((Number) query.uniqueResult()).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7070")
|
||||
public void testDatediffFunction() {
|
||||
Query query = session.createQuery("SELECT DATEDIFF( DAY, '1999/07/19 00:00', '1999/07/23 23:59' ) from Product");
|
||||
assertEquals(4, ((Number) query.uniqueResult()).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7070")
|
||||
public void testAtn2Function() {
|
||||
Query query = session.createQuery("select atn2(p.price, .48) from Product p");
|
||||
assertEquals(0.805803, ((Number) query.uniqueResult()).doubleValue(), 0.000001);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue