Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(function):The function does not display properly if the return value type is year #4093

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ public static Object getValueFromStatement(CallableStatement statement, int inde

public static Object getValueFromResultSet(ResultSet resultSet, int index, String type)
throws SQLException {
// YEAR type is used to represent the year in 4-digit format. The range is 1901 to 2155, and 0000
zijiacj marked this conversation as resolved.
Show resolved Hide resolved
if ("year".equalsIgnoreCase(type)) {
Short yearValue = resultSet.getShort(index);
if (yearValue == 0) {
return "0000";
}
return yearValue;
}
JDBCType jdbcType = parseDataType(type);
switch (jdbcType) {
case BIT:
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,45 @@ public void doInConnection_unusualParam_callSucceed() {
Assert.assertEquals(expect, actual);
}

@Test
public void doInConnection_returnTypeIsYear_callSucceed() {
testCallFunctionWhenReturnIsYear("2024", "2024");
testCallFunctionWhenReturnIsYear("0000", "0000");
testCallFunctionWhenReturnIsYear("0", "2000");
testCallFunctionWhenReturnIsYear("1", "2001");
testCallFunctionWhenReturnIsYear("99", "1999");
}

private static void testCallFunctionWhenReturnIsYear(String input, String expectOutput) {
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(input);
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(expectOutput);
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;
$$
Loading