提交 61873c88 authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

The function IFNULL did not always return the result in the right data type.

上级 cca8464f
...@@ -54,6 +54,8 @@ table with an LOB column. ...@@ -54,6 +54,8 @@ table with an LOB column.
</li> </li>
<li>improve performance of queries that use LIKE 'foo%' - 10x in the case of one of my queries <li>improve performance of queries that use LIKE 'foo%' - 10x in the case of one of my queries
</li> </li>
<li>The function IFNULL did not always return the result in the right data type.
</li>
<li>Issue #231: Possible infinite loop when initializing the ObjectDataType class <li>Issue #231: Possible infinite loop when initializing the ObjectDataType class
when concurrently writing into MVStore. when concurrently writing into MVStore.
</li> </li>
...@@ -61,6 +63,8 @@ table with an LOB column. ...@@ -61,6 +63,8 @@ table with an LOB column.
<h2>Version 1.4.191 Beta (2016-01-21)</h2> <h2>Version 1.4.191 Beta (2016-01-21)</h2>
<ul> <ul>
<li>TO_DATE and TO_TIMESTAMP functions. Thanks a lot to Sam Blume for the patch!
</li>
<li>Issue #229: DATEDIFF does not work for 'WEEK'. <li>Issue #229: DATEDIFF does not work for 'WEEK'.
</li> </li>
<li>Issue #156: Add support for getGeneratedKeys() when executing commands via PreparedStatement#executeBatch. <li>Issue #156: Add support for getGeneratedKeys() when executing commands via PreparedStatement#executeBatch.
......
...@@ -965,6 +965,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -965,6 +965,7 @@ public class Function extends Expression implements FunctionCall {
if (v0 == ValueNull.INSTANCE) { if (v0 == ValueNull.INSTANCE) {
result = getNullOrValue(session, args, values, 1); result = getNullOrValue(session, args, values, 1);
} }
result = convertResult(result);
break; break;
} }
case CASEWHEN: { case CASEWHEN: {
...@@ -1129,6 +1130,10 @@ public class Function extends Expression implements FunctionCall { ...@@ -1129,6 +1130,10 @@ public class Function extends Expression implements FunctionCall {
return result; return result;
} }
private Value convertResult(Value v) {
return v.convertTo(dataType);
}
private static boolean cancelStatement(Session session, int targetSessionId) { private static boolean cancelStatement(Session session, int targetSessionId) {
session.getUser().checkAdmin(); session.getUser().checkAdmin();
Session[] sessions = session.getDatabase().getSessions(false); Session[] sessions = session.getDatabase().getSessions(false);
......
...@@ -76,6 +76,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -76,6 +76,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
deleteDb("functions"); deleteDb("functions");
testIfNull();
testToDate(); testToDate();
testToDateException(); testToDateException();
testAddMonths(); testAddMonths();
...@@ -1658,6 +1659,21 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1658,6 +1659,21 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn.close(); conn.close();
} }
private void testIfNull() throws SQLException {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stat.execute("CREATE TABLE T(f1 double)");
stat.executeUpdate("INSERT INTO T VALUES( 1.2 )");
stat.executeUpdate("INSERT INTO T VALUES( null )");
ResultSet rs = stat.executeQuery("SELECT IFNULL(f1, 0.0) FROM T");
ResultSetMetaData metaData = rs.getMetaData();
assertEquals("java.lang.Double", metaData.getColumnClassName(1));
rs.next();
assertEquals("java.lang.Double", rs.getObject(1).getClass().getName());
rs.next();
assertEquals("java.lang.Double", rs.getObject(1).getClass().getName());
conn.close();
}
private void testToCharFromNumber() throws SQLException { private void testToCharFromNumber() throws SQLException {
deleteDb("functions"); deleteDb("functions");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论