提交 d6938e50 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved Oracle compatibility: support for NVL2. Thanks to litailang for the patch!

上级 37dcf23e
......@@ -23,9 +23,8 @@ import java.sql.Types;
import java.util.ArrayList;
import java.util.Properties;
import java.util.UUID;
import org.h2.api.AggregateFunction;
import org.h2.jdbc.JdbcSQLException;
import org.h2.constant.ErrorCode;
import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
import org.h2.util.IOUtils;
......@@ -76,15 +75,15 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
String createSQL = "CREATE TABLE testNvl2 (id BIGINT,txt1 varchar,txt2 varchar,num number(9,0));";
String createSQL = "CREATE TABLE testNvl2(id BIGINT, txt1 varchar, txt2 varchar, num number(9, 0));";
stat.execute(createSQL);
stat.execute("insert into testNvl2(id,txt1,txt2,num) values (1,'test1','test2',null)");
stat.execute("insert into testNvl2(id,txt1,txt2,num) values (2,null,'test4',null)");
stat.execute("insert into testNvl2(id,txt1,txt2,num) values (3,'test5',null,null)");
stat.execute("insert into testNvl2(id,txt1,txt2,num) values (4,null,null,null)");
stat.execute("insert into testNvl2(id,txt1,txt2,num) values (5,'2',null,1)");
stat.execute("insert into testNvl2(id,txt1,txt2,num) values (6,'2',null,null)");
stat.execute("insert into testNvl2(id,txt1,txt2,num) values (7,'test2',null,null)");
stat.execute("insert into testNvl2(id, txt1, txt2, num) values(1, 'test1', 'test2', null)");
stat.execute("insert into testNvl2(id, txt1, txt2, num) values(2, null, 'test4', null)");
stat.execute("insert into testNvl2(id, txt1, txt2, num) values(3, 'test5', null, null)");
stat.execute("insert into testNvl2(id, txt1, txt2, num) values(4, null, null, null)");
stat.execute("insert into testNvl2(id, txt1, txt2, num) values(5, '2', null, 1)");
stat.execute("insert into testNvl2(id, txt1, txt2, num) values(6, '2', null, null)");
stat.execute("insert into testNvl2(id, txt1, txt2, num) values(7, 'test2', null, null)");
String query = "SELECT NVL2(txt1, txt1, txt2), txt1 FROM testNvl2 order by id asc";
ResultSet rs = stat.executeQuery(query);
......@@ -103,19 +102,14 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals(rs.getMetaData().getColumnType(2), rs.getMetaData().getColumnType(1));
rs.close();
rs = stat.executeQuery("SELECT NVL2(num, num, txt1), num FROM testNvl2 where id in (5,6) order by id asc");
rs = stat.executeQuery("SELECT NVL2(num, num, txt1), num FROM testNvl2 where id in(5, 6) order by id asc");
rs.next();
assertEquals(rs.getMetaData().getColumnType(2), rs.getMetaData().getColumnType(1));
try {
rs = stat.executeQuery("SELECT NVL2(num, num, txt1), num FROM testNvl2 where id = 7 order by id asc");
} catch (JdbcSQLException e) {
Throwable t = e.getCause();
if (t instanceof NumberFormatException) {
//
} else {
throw e;
}
} catch (SQLException e) {
assertEquals(ErrorCode.DATA_CONVERSION_ERROR_1, e.getErrorCode());
}
conn.close();
......@@ -583,7 +577,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
}
stat.execute("CREATE ALIAS SIMPLE FOR \"" + getClass().getName() + ".simpleResultSet\"");
rs = stat.executeQuery("CALL SIMPLE(2, 1,1,1,1,1,1,1)");
rs = stat.executeQuery("CALL SIMPLE(2, 1, 1, 1, 1, 1, 1, 1)");
assertEquals(2, rs.getMetaData().getColumnCount());
rs.next();
assertEquals(0, rs.getInt(1));
......@@ -593,7 +587,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals("World", rs.getString(2));
assertFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM SIMPLE(1, 1,1,1,1,1,1,1)");
rs = stat.executeQuery("SELECT * FROM SIMPLE(1, 1, 1, 1, 1, 1, 1, 1)");
assertEquals(2, rs.getMetaData().getColumnCount());
rs.next();
assertEquals(0, rs.getInt(1));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论