Skip to content

Commit

Permalink
fix(sql-execute): nls_format invalidation
Browse files Browse the repository at this point in the history
* fix nls format invalidation

* format code
  • Loading branch information
LuckyPickleZZ authored Feb 13, 2025
1 parent f029964 commit bdd4f6b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ public void afterCompletion_commentWithSetVar_setSucceed() throws Exception {
Assert.assertEquals(expect, ConnectionSessionUtil.getNlsDateFormat(session));
}

@Test
public void afterCompletion_commentWithSetVar_withoutScope_setSucceed() throws Exception {
ConnectionSession session = getConnectionSession(ConnectType.OB_ORACLE);
NlsFormatInterceptor interceptor = new NlsFormatInterceptor();
String expect = "DD-MON-RR";
SqlExecuteResult r = getResponse("-- comment\nset nls_date_format='" + expect + "';",
SqlExecuteStatus.SUCCESS);
interceptor.afterCompletion(r, session, getContext());
Assert.assertEquals(expect, ConnectionSessionUtil.getNlsDateFormat(session));
}

@Test
public void afterCompletion_multiCommentsWithSetVar_setSucceed() throws Exception {
ConnectionSession session = getConnectionSession(ConnectType.OB_ORACLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,28 @@ private static class NlsFormatVariableVisitor extends OBParserBaseVisitor<Variab

@Override
public VariableAssign visitVar_and_val(Var_and_valContext ctx) {
if (ctx.scope_or_scope_alias() == null) {
return null;
}
Expression value = null;
if (ctx.set_expr_or_default().bit_expr() != null) {
value = new OracleExpressionFactory(ctx.set_expr_or_default().bit_expr()).generate();
String name;
if (ctx.sys_var_and_val() != null) {
if (ctx.sys_var_and_val().set_expr_or_default().bit_expr() != null) {
value = new OracleExpressionFactory(ctx.sys_var_and_val().set_expr_or_default().bit_expr())
.generate();
}
name = ctx.sys_var_and_val().obj_access_ref_normal().getText();
} else if (ctx.set_expr_or_default() != null) {
if (ctx.set_expr_or_default().bit_expr() != null) {
value = new OracleExpressionFactory(ctx.set_expr_or_default().bit_expr()).generate();
}
name = ctx.column_name().getText();
} else {
return null;
}
VariableAssign assign = new VariableAssign(ctx.column_name().getText(), value);
VariableAssign assign = new VariableAssign(name, value);
Scope_or_scope_aliasContext scope = ctx.scope_or_scope_alias();
if (scope == null) {
assign.setSession(true);
return assign;
}
if (scope.GLOBAL() != null || scope.GLOBAL_ALIAS() != null) {
assign.setGlobal(true);
} else if (scope.SESSION() != null || scope.SESSION_ALIAS() != null) {
Expand Down

0 comments on commit bdd4f6b

Please # to comment.