I can see it now. Everybody will say how the following bit of Java code that Shawn C. has sent in isn't actually a WTF and is, in fact, quite brilliant.
To a point, I agree - the code works, and leaves the door open for accomodating changes to the structure of the SQL queries themselves. Especially if, some day, in a far flung future when, from out of space, a runaway planet comes hurtling between the Earth and the Moon, unleashing cosmic destruction casting civilization into ruin, forcing mankind to re-invent the standard keywords used to retrieve information from databases.
This, dear readers, is what I would consider planning for the future, or at least one of them.
public class DBQueryString
{
protected String mstrSelect;
protected String mstrTable;
protected String mstrWhere;
protected String mstrOrder;
public static final String SELECT = "select ";
public static final String INSERT = "insert into ";
public static final String UPDATE = "update ";
public static final String DELETE = "delete ";
public static final String SET = " set ";
public static final String FROM = " from ";
public static final String WHERE = " where ";
public static final String AND = " and ";
public static final String VALUES = " values ";
public static final String ORDER = " order by ";
[other code snipped]
public String buildQuery()
{
String strQuery = "";
strQuery = SELECT + this.mstrSelect;
strQuery = strQuery + FROM + this.mstrTable;
if (this.mstrWhere != null)
{
strQuery = strQuery + WHERE + this.mstrWhere;
}
if (this.mstrOrder != null)
{
strQuery = strQuery + ORDER + this.mstrOrder;
}
LoggingSystem.getLogger().inform(3, strQuery);
return strQuery;
}
}