import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Query {
private Database database;
private String table;
private String query;
private boolean needsWhere = true;
private boolean where = false;
private boolean needsSet = false;
private boolean set = false;
private boolean needsValues = false;
private boolean values = false;
private boolean needsOn = false;
private boolean on = false;
Query(Database database, String table) {
this.database = database;
this.table = table;
query = "FROM " + "VaorraCore." + table;
}
public Query join(String tableName){
this.needsOn = true;
this.needsWhere = false;
query += " JOIN " + tableName + " ON ";
return this;
}
public Query on(String columnLeft, String comparator, String columnRight){
on = true;
query += " " + columnLeft + comparator + columnRight;
CheckForColumnSpecification(columnLeft);
CheckForColumnSpecification(columnRight);
return this;
}
public Query find(int id){
return where("id", "=", id);
}
public Query where(String column, String comparator, Object value){
if (where){
query += " AND";
}
query += " WHERE " + column + comparator + convertToSQLString(value);
where = true;
return this;
}
public Query set(String column, Object value){
if (set){
query += ",";
}
else{
query += " SET";
}
query += " " + column + "=" + convertToSQLString(value);
set = true;
return this;
}
public Query values(String key, Object value){
if (values){
String left = query.split(" VALUES ")[0];
String right = query.split(" VALUES ")[1];
left += ", " + key;
right += ", " + convertToSQLString(value);
query = left + " VALUES " + right;
}
else{
query += " (" + key +" VALUES (" + convertToSQLString(value);
}
values = true;
return this;
}
public ResultSet get(){
CheckForCondition();
query = "SELECT * " + query;
ResultSet resultSet = database.executeQuery(query);
try {
resultSet.next();
} catch (SQLException e) {
e.printStackTrace();
}
return resultSet;
}
public List