Skip to content

Commit 44b7384

Browse files
committed
Support for execute of multiple sql statement separated by ';'
1 parent 27c633f commit 44b7384

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

debug-db/src/main/java/com/amitshekhar/server/RequestHandler.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,25 @@ private String executeQueryAndGetResponse(String route) {
236236
}
237237

238238
if (query != null) {
239-
first = query.split(" ")[0].toLowerCase();
240-
if (first.equals("select") || first.equals("pragma")) {
241-
TableDataResponse response = DatabaseHelper.getTableData(mDatabase, query, null);
242-
data = mGson.toJson(response);
243-
} else {
244-
TableDataResponse response = DatabaseHelper.exec(mDatabase, query);
245-
data = mGson.toJson(response);
239+
String[] statements = query.split(";");
240+
241+
for (int i=0; i<statements.length; i++) {
242+
243+
String aQuery = statements[i].trim();
244+
first = aQuery.split(" ")[0].toLowerCase();
245+
if (first.equals("select") || first.equals("pragma")) {
246+
TableDataResponse response = DatabaseHelper.getTableData(mDatabase, aQuery, null);
247+
data = mGson.toJson(response);
248+
if (!response.isSuccessful) {
249+
break;
250+
}
251+
} else {
252+
TableDataResponse response = DatabaseHelper.exec(mDatabase, aQuery);
253+
data = mGson.toJson(response);
254+
if (!response.isSuccessful) {
255+
break;
256+
}
257+
}
246258
}
247259
}
248260
} catch (Exception e) {

0 commit comments

Comments
 (0)