#2115 add flag to pointed out whether the variable has word 'session' above

This commit is contained in:
sunzhengfang
2017-11-17 14:25:50 +08:00
parent 920a2f150d
commit 4396cee23b
6 changed files with 192 additions and 1 deletions
@@ -28,6 +28,8 @@ public class SQLVariantRefExpr extends SQLExprImpl {
private boolean global = false;
private boolean hasSessionBefore = false;
private int index = -1;
public SQLVariantRefExpr(String name){
@@ -39,6 +41,12 @@ public class SQLVariantRefExpr extends SQLExprImpl {
this.global = global;
}
public SQLVariantRefExpr(String name, boolean global,boolean hasSessionBefore){
this.name = name;
this.global = global;
this.hasSessionBefore = hasSessionBefore;
}
public SQLVariantRefExpr(){
}
@@ -63,6 +71,15 @@ public class SQLVariantRefExpr extends SQLExprImpl {
buf.append(this.name);
}
public boolean isHasSessionBefore() {
return hasSessionBefore;
}
public void setHasSessionBefore(boolean hasSessionBefore) {
this.hasSessionBefore = hasSessionBefore;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
visitor.visit(this);
@@ -29,6 +29,17 @@ public class MySqlSetTransactionStatement extends MySqlStatementImpl {
private String accessModel;
private Boolean hasSessionBefore;
public Boolean getHasSessionBefore() {
return hasSessionBefore;
}
public void setHasSessionBefore(Boolean hasSessionBefore) {
this.hasSessionBefore = hasSessionBefore;
}
public void accept0(MySqlASTVisitor visitor) {
visitor.visit(this);
visitor.endVisit(this);
@@ -596,7 +596,7 @@ public class MySqlExprParser extends SQLExprParser {
} else if (identHash == FnvHash.Constants.SESSION) {
ident = lexer.stringVal();
lexer.nextToken();
var = new SQLVariantRefExpr(ident, false);
var = new SQLVariantRefExpr(ident, false, true);
} else {
var = new SQLVariantRefExpr(ident);
}
@@ -2609,17 +2609,20 @@ public class MySqlStatementParser extends SQLStatementParser {
}
Boolean global = null;
Boolean sessionBefore = null;
if (lexer.identifierEquals(GLOBAL)) {
global = Boolean.TRUE;
lexer.nextToken();
} else if (lexer.identifierEquals(SESSION)) {
global = Boolean.FALSE;
sessionBefore = Boolean.TRUE;
lexer.nextToken();
}
if (lexer.identifierEquals("TRANSACTION")) {
MySqlSetTransactionStatement stmt = new MySqlSetTransactionStatement();
stmt.setGlobal(global);
stmt.setHasSessionBefore(sessionBefore);
lexer.nextToken();
if (lexer.identifierEquals("ISOLATION")) {
@@ -2724,6 +2727,11 @@ public class MySqlStatementParser extends SQLStatementParser {
varRef.setGlobal(true);
}
if(sessionBefore != null && sessionBefore.booleanValue()){
SQLVariantRefExpr varRef = (SQLVariantRefExpr) stmt.getItems().get(0).getTarget();
varRef.setHasSessionBefore(true);
}
if (lexer.token() == Token.HINT) {
stmt.setHints(this.exprParser.parseHints());
}
@@ -655,6 +655,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
if (x.isGlobal()) {
print0("@@global.");
}else if(x.isHasSessionBefore()){
print0("@@session.");
}
String varName = x.getName();