我想知道是否可以使用 jsqlparser 向 sql 查询添加表达式。例如,我想在 sql 语句中添加一个列和一个值:
原始查询:“INSERT INTO frontend
( in_reply_to
) VALUES ( email
);”
修改后的查询:“INSERT INTO frontend
( in_reply_to
, user_id
) VALUES ( email
, 123)”
我设法修改了一个列名,但没有添加一个。
这是我拥有的代码:
ExtendedItemsListVisitor visitor = new ExtendedItemsListVisitor() {
private List expressions = null;
public List getExpressions() {
return this.expressions;
}
public void setExpressions(ExpressionList expressionList) {
this.expressions = expressionList.getExpressions();
}
public void visit(SubSelect subSelect) {
}
public void visit(ExpressionList expressionList) {
this.expressions = expressionList.getExpressions();
}
};
ItemsList itemsList = ((Insert)statement).getItemsList();
itemsList.accept(visitor);
ExpressionList expressions = (ExpressionList)visitor1.getExpressions();
Expression expression = new StringValue(newValue);
ExpressionVisitor visitor = new SetValueExpressionVisitor(newValue);