Skip to content

Commit

Permalink
Add YEAR support in OBMysqlCallFunctionCallBackTest and JdbcDataTypeUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiacj committed Dec 26, 2024
1 parent ea5fa04 commit d946ff9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ public static JDBCType parseDataType(String dataType) {
dataType = "date";
} else if ("sys_refcursor".equalsIgnoreCase(dataType)) {
dataType = "ref";
} else if ("year".equalsIgnoreCase(dataType)) {
dataType = "SMALLINT";
}

JDBCType type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@

public class OBMysqlCallFunctionCallBackTest {

public static final String TEST_CASE_1 = "func_test";
public static final String TEST_CASE_2 = "func_test_1";
public static final String TEST_CASE_3 = "func_test_2";
public static final String TEST_CASE_1 = "TEST_CASE_1";
public static final String TEST_CASE_2 = "TEST_CASE_2";
public static final String TEST_CASE_3 = "TEST_CASE_3";
public static final String TEST_CASE_4 = "func_test_4";


@BeforeClass
public static void setUp() throws IOException {
Expand All @@ -58,6 +60,7 @@ public static void clear() {
mysql.execute("DROP FUNCTION " + TEST_CASE_1);
mysql.execute("DROP FUNCTION " + TEST_CASE_2);
mysql.execute("DROP FUNCTION " + TEST_CASE_3);
mysql.execute("DROP FUNCTION " + TEST_CASE_4);
}

@Test
Expand Down Expand Up @@ -220,6 +223,37 @@ public void doInConnection_unusualParam_callSucceed() {
Assert.assertEquals(expect, actual);
}

@Test
public void doInConnection_returnTypeIsYear_callSucceed() {
CallFunctionReq callFunctionReq = new CallFunctionReq();
DBFunction function = new DBFunction();
function.setFunName(TEST_CASE_4);
List<DBPLParam> list = new ArrayList<>();
DBPLParam param = new DBPLParam();
param.setParamName("p1");
param.setDefaultValue("2024");
param.setDataType("year");
param.setParamMode(DBPLParamMode.IN);
list.add(param);
function.setParams(list);
function.setReturnType("year");
callFunctionReq.setFunction(function);

ConnectionCallback<CallFunctionResp> callback = new OBMysqlCallFunctionCallBack(callFunctionReq, -1);
JdbcTemplate jdbcTemplate =
new JdbcTemplate(TestDBConfigurations.getInstance().getTestOBMysqlConfiguration().getDataSource());
CallFunctionResp actual = jdbcTemplate.execute(callback);

CallFunctionResp expect = new CallFunctionResp();
PLOutParam plOutParam = new PLOutParam();
plOutParam.setParamName(TEST_CASE_4);
plOutParam.setDataType("year");
plOutParam.setValue("2024");
expect.setReturnValue(plOutParam);
expect.setOutParams(null);
Assert.assertEquals(expect, actual);
}

private static List<String> getContent() throws IOException {
String delimiter = "\\$\\$\\s*";
try (InputStream input = OBMysqlCallFunctionCallBackTest.class.getClassLoader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ create function ${const:com.oceanbase.odc.service.db.util.OBMysqlCallFunctionCal
begin
return p0;
end;
$$

create function ${const:com.oceanbase.odc.service.db.util.OBMysqlCallFunctionCallBackTest.TEST_CASE_4} (
p1 year) returns year
begin
return p1;
end;
$$

0 comments on commit d946ff9

Please sign in to comment.