You can write your own beautiful printer. In this case, it will not be difficult. Just replace things like:
"FROM" -> "\nFROM"
"WHERE" -> "\nWHERE"
"," -> ",\n\t"
"AND" -> "AND\n\t"
"OR" -> "OR\n\t"
and etc.
Edit: since you are not coding, here is a small version of this function.
#include <string>
using std::string;
string replace(string a, string b, string c) {
unsigned x;
for(x = a.find(b); x != string::npos;) {
a.erase(x, b.length());
a.insert(x, c);
}
return a;
}
string formatSQL(string sql) {
replace(sql, "FROM", "\nFROM");
replace(sql, "WHERE", "\nWHERE");
replace(sql, "," , ",\n\t");
replace(sql, "AND", "AND\n\t");
replace(sql, "OR", "OR\n\t");
}
Thus, the call formatSql("SELECT MEMB.NAME, MEMB.AGE, AGE.GROUP FROM MEMB, AGE WHERE MEMB.AGE = AGE.AGE")gives the desired result.
source
share