Menu

#22 De-parsing removes a space on joins

open
nobody
None
5
2012-12-07
2012-08-01
Luigi
No

The following code

import java.io.StringReader;

import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.util.deparser.StatementDeParser;

public class SelectDeparserTest {
public static void main(String[] args) throws JSQLParserException {
String originalSQL = "SELECT * FROM BOB B RIGHT JOIN FRED F ON (B.C=F.C)";
System.out.println(originalSQL);
Statement parsed = new CCJSqlParserManager().parse(new StringReader(
originalSQL));
StringBuffer stringBuffer = new StringBuffer();
parsed.accept(new StatementDeParser(stringBuffer));
System.out.println(stringBuffer);
}
}

when run has the following output

SELECT * FROM BOB B RIGHT JOIN FRED F ON (B.C=F.C)
SELECT * FROM BOB AS BRIGHT JOIN FRED AS F ON (B.C = F.C)

notice that the de-parsed query (the second one) lacks a white space between the alias for BOB, i.e.: B and the keyword RIGHT. The same happens for LEFT, INNER, OUTER, FULL, and simply JOIN

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.