Skip to content

Commit 6415f28

Browse files
committed
Added support for "count" keyword in the list() method in the WebService class
1 parent c0e7c2c commit 6415f28

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/javaxt/express/WebService.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,7 @@ private ServiceResponse list(Class c, ServiceRequest request, Database database)
469469

470470

471471
//Get output format
472-
String format = request.getParameter("format").toString();
473-
if (format==null) format = ""; else format = format.toLowerCase();
472+
String format = request.getFormat();
474473

475474

476475
//Excute query and generate response
@@ -621,12 +620,25 @@ else if (format.equals("json")){
621620
json.append("]");
622621

623622

623+
//Append columns
624624
json.append(",\"cols\":");
625625
json.append(cols.toString());
626+
627+
628+
//Append count as needed
629+
if (request.getCount()){
630+
rs.close();
631+
Record r = conn.getRecord("select count(id) from " +
632+
tableName + (where==null ? "" : " where " + where));
633+
if (r!=null){
634+
json.append(",\"count\":");
635+
json.append(r.get(0).toLong());
636+
}
637+
}
638+
626639
json.append("}");
627640
response = new ServiceResponse(json.toString());
628641
response.setContentType("application/json");
629-
630642
}
631643

632644
return response;

0 commit comments

Comments
 (0)