-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuery.pde
More file actions
46 lines (37 loc) · 1.19 KB
/
Copy pathQuery.pde
File metadata and controls
46 lines (37 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Query{
boolean isDistinct = false;
ArrayList<String> columnsToDisplay = new ArrayList<String>();
String tableName = "flights";
boolean hasRowFilter = false;
String rowFilter;
String orderByCol;
boolean sortAscending = false;
int count;
Query(boolean distinct, ArrayList<String> columns, boolean hasRowFilter, String rowFilter, String orderBy, boolean sortAsc, int count){
this.isDistinct = distinct;
this.columnsToDisplay = columns;
this.hasRowFilter = hasRowFilter;
this.rowFilter = rowFilter;
this.orderByCol = orderBy;
this.sortAscending = sortAsc;
this.count = count;
}
String getSQLquery(){
String query = "SELECT ";
for(int i = 0; i < columnsToDisplay.size(); i++){
query += columnsToDisplay.get(i);
if(i != columnsToDisplay.size()-1){
query += ", ";
}
}
query += " FROM " + tableName;
if(hasRowFilter){
query += "WHERE " + rowFilter;
}
query += " ORDER BY " + orderByCol;
if(sortAscending) query += " ASC ";
else query += " DESC ";
if(count > 0) query += "LIMIT " + count;
return query;
}
}