-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
How to Replace String Values in JSQLParser version 5? #2148
Answered
by
manticore-projects
JevonCowell
asked this question in
Q&A
-
Tried following the example in the wikia and I'm not able to get the censored values
How should it be done in the new version?
Beta Was this translation helpful? Give feedback.
All reactions
Answered by
manticore-projects
Jan 18, 2025
Please see here
You are overriding the wrong methods. Instead use the methods with the generics.
Replies: 2 comments
-
The exact output of
class ReplaceColumnValues {
static class ReplaceColumnAndLongValues extends ExpressionDeParser {
@Override
public void visit(StringValue stringValue) {
this.getBuffer().append("?");
}
@Override
public void visit(LongValue longValue) {
this.getBuffer().append("?");
}
}
public static String cleanStatement(String sql) throws JSQLParserException {
StringBuilder buffer = new StringBuilder();
ExpressionDeParser expr = new ReplaceColumnAndLongValues();
SelectDeParser selectDeparser = new SelectDeParser(expr, buffer);
expr.setSelectVisitor(selectDeparser);
expr.setBuffer(buffer);
StatementDeParser stmtDeparser = new StatementDeParser(expr, selectDeparser, buffer);
Statement stmt = CCJSqlParserUtil.parse(sql);
stmt.accept(stmtDeparser);
return stmtDeparser.getBuffer().toString();
}
public static void main(String[] args) throws JSQLParserException {
System.out.println(cleanStatement("SELECT 'abc', 5 FROM mytable WHERE col='test'"));
System.out.println(cleanStatement("UPDATE table1 A SET A.columna = 'XXX' WHERE A.cod_table = 'YYY'"));
System.out.println(cleanStatement("INSERT INTO example (num, name, address, tel) VALUES (1, 'name', 'test ', '1234-1234')"));
System.out.println(cleanStatement("DELETE FROM table1 where col=5 and col2=4"));
}
}
is
SELECT 'abc', 5 FROM mytable WHERE col = 'test'
UPDATE table1 A SET A.columna = 'XXX' WHERE A.cod_table = 'YYY'
INSERT INTO example (num, name, address, tel) VALUES (1, 'name', 'test ', '1234-1234')
DELETE FROM table1 WHERE col = 5 AND col2 = 4
in com.github.jsqlparser:jsqlparser:5.1
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
-
Please see here
You are overriding the wrong methods. Instead use the methods with the generics.
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Answer selected by
JevonCowell
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment