backported some code from lang_de branch
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -91,6 +91,7 @@ public class Database {
|
||||
*/
|
||||
public class Request{
|
||||
|
||||
private String groupBy = null;
|
||||
private final StringBuilder sql; // buffer the sql to be built
|
||||
private final HashMap<String, List<Object>> where = new HashMap<>(); // buffer condition statements for select
|
||||
private final HashMap<String,Object> values = new HashMap<>(); // buffer values for insert/update statements
|
||||
@@ -128,6 +129,10 @@ public class Database {
|
||||
}
|
||||
}
|
||||
|
||||
private void applyGrouping(){
|
||||
if (groupBy != null && !groupBy.isBlank()) sql.append(" GROUP BY ").append(groupBy.trim());
|
||||
}
|
||||
|
||||
private void applySorting(){
|
||||
if (!sortFields.isEmpty()) sql.append(" ORDER BY ").append(String.join(", ",sortFields));
|
||||
}
|
||||
@@ -148,6 +153,7 @@ public class Database {
|
||||
var args = new ArrayList<>();
|
||||
applyValues(args);
|
||||
applyConditions(args);
|
||||
applyGrouping();
|
||||
applySorting();
|
||||
if (additionalArgs != null) {
|
||||
for (Object arg : additionalArgs) args.add(arg);
|
||||
@@ -187,6 +193,10 @@ public class Database {
|
||||
}
|
||||
}
|
||||
|
||||
public Request groupBy(String column) {
|
||||
groupBy = column;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void run() throws SQLException {
|
||||
compile().run();
|
||||
|
||||
Reference in New Issue
Block a user