Skip to content

Commit ae33e79

Browse files
author
Vinayaga Sundar
committed
Merge branch 'Development' of github.com:amitshekhariitbhu/Android-Debug-Database into Development
# Conflicts: # debug-db/src/main/assets/debugDbHome/js/app.js # debug-db/src/main/java/com/amitshekhar/utils/DatabaseHelper.java
2 parents 9955165 + eb3d2d0 commit ae33e79

7 files changed

Lines changed: 81 additions & 27 deletions

File tree

debug-db/src/main/assets/debugDbHome/css/custom.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,41 @@
1818
background: #dff0d8 !important;
1919
color: #3c763d !important;
2020
font-weight: bold;
21+
}
22+
23+
#snackbar {
24+
visibility: hidden;
25+
min-width: 250px;
26+
margin-left: -125px;
27+
background-color: #5cb85c;
28+
color: #fff;
29+
text-align: center;
30+
border-radius: 2px;
31+
padding: 16px;
32+
position: fixed;
33+
z-index: 1;
34+
left: 50%;
35+
bottom: 30px;
36+
font-size: 17px;
37+
}
38+
39+
#snackbar.show {
40+
visibility: visible;
41+
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
42+
animation: fadein 0.5s, fadeout 0.5s 2.5s;
43+
}
44+
45+
@-webkit-keyframes fadein {
46+
from {bottom: 0; opacity: 0;}
47+
to {bottom: 30px; opacity: 1;}
48+
}
49+
50+
@keyframes fadein {
51+
from {bottom: 0; opacity: 0;}
52+
to {bottom: 30px; opacity: 1;}
53+
}
54+
55+
@-webkit-keyframes fadeout {
56+
from {bottom: 30px; opacity: 1;}
57+
to {bottom: 0; opacity: 0;}
2158
}

debug-db/src/main/assets/debugDbHome/index.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@
118118
<label for="query">Query</label>
119119
<input class="form-control" id="query">
120120
</div>
121-
<button id="selected-db-info" type="button" onclick="downloadDb()" class="btn btn-info">Welcome</button>
122-
<button id="success-info" type="button" class="btn btn-success display-none">Query Executed</button>
123-
<button id="error-info" type="button" class="btn btn-danger display-none">Query Not Executed</button>
124-
<button id="run-query" type="submit" onclick="queryFunction()" class="btn btn-primary pull-right disabled">Run
121+
<button id="selected-db-info" type="button" onclick="downloadDb()" class="btn btn-info">
122+
Welcome
123+
</button>
124+
<button id="run-query" type="submit" onclick="queryFunction()"
125+
class="btn btn-primary pull-right disabled">Run
125126
Query
126127
</button>
127128
</div>
@@ -153,6 +154,8 @@
153154
</div>
154155
</div>
155156

157+
<div id="snackbar">Data Updated Successfully</div>
158+
156159
</div>
157160

158161
<script src="debugDbHome/js/app.js"></script>

debug-db/src/main/assets/debugDbHome/js/app.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ function openDatabaseAndGetTableList(db) {
121121
function inflateData(result){
122122

123123
if(result.isSuccessful){
124-
showSuccessInfo();
124+
125+
if(!result.isSelectQuery){
126+
showSuccessInfo("Query Executed Successfully");
127+
return;
128+
}
129+
125130
var columnHeader = result.tableInfos;
126131

127132
// set function to return cell data for different usages like set, display, filter, search etc..
@@ -208,7 +213,11 @@ function inflateData(result){
208213
$(".dataTables_scrollHeadInner").css({"width":"100%"});
209214
$(".table ").css({"width":"100%"});
210215
}else{
211-
showErrorInfo();
216+
if(!result.isSelectQuery){
217+
showSuccessInfo("Query Execution Failed");
218+
}else {
219+
showErrorInfo("Some Error Occurred");
220+
}
212221
}
213222

214223
}
@@ -242,6 +251,7 @@ function updateTableData(updatedData, callback) {
242251
if(response.isSuccessful){
243252
console.log("Data updated successfully");
244253
callback(true);
254+
showSuccessInfo("Data Updated Successfully");
245255
} else {
246256
console.log("Data updated failed");
247257
callback(false);
@@ -289,17 +299,18 @@ function deleteTableData(deleteData, callback) {
289299
})
290300
}
291301

292-
function showSuccessInfo(){
293-
$("#success-info").show();
294-
$("#error-info").hide();
302+
function showSuccessInfo(message){
303+
var snackbar = document.getElementById("snackbar")
304+
snackbar.className = "show";
305+
snackbar.style.backgroundColor = "#5cb85c";
306+
snackbar.innerHTML = message;
307+
setTimeout(function(){ snackbar.className = snackbar.className.replace("show", ""); }, 2000);
295308
}
296309

297-
function showErrorInfo(){
298-
$("#success-info").hide();
299-
$("#error-info").show();
310+
function showErrorInfo(message){
311+
var snackbar = document.getElementById("snackbar")
312+
snackbar.className = "show";
313+
snackbar.style.backgroundColor = "#d9534f";
314+
snackbar.innerHTML = message;
315+
setTimeout(function(){ snackbar.className = snackbar.className.replace("show", ""); }, 2000);
300316
}
301-
302-
function hideBothInfo(){
303-
$("#success-info").hide();
304-
$("#error-info").hide();
305-
}

debug-db/src/main/java/com/amitshekhar/model/TableDataResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class TableDataResponse {
3232
public List<Object> rows;
3333
public String errorMessage;
3434
public boolean isEditable;
35+
public boolean isSelectQuery;
3536

3637
public static class TableInfo {
3738
public String title;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ private String executeQueryAndGetResponse(String route) {
222222
TableDataResponse response = DatabaseHelper.getTableData(mDatabase, query, null);
223223
data = mGson.toJson(response);
224224
} else {
225-
Response response = DatabaseHelper.exec(mDatabase, query);
225+
TableDataResponse response = DatabaseHelper.exec(mDatabase, query);
226226
data = mGson.toJson(response);
227227
}
228228
}

debug-db/src/main/java/com/amitshekhar/utils/DatabaseHelper.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static Response getAllTableName(SQLiteDatabase database) {
6363
public static TableDataResponse getTableData(SQLiteDatabase db, String selectQuery, String tableName) {
6464

6565
TableDataResponse tableData = new TableDataResponse();
66-
66+
tableData.isSelectQuery = true;
6767
if (tableName == null) {
6868
tableName = getTableName(selectQuery);
6969
}
@@ -240,7 +240,6 @@ public static UpdateRowResponse updateRow(SQLiteDatabase db, String tableName, L
240240
}
241241

242242

243-
244243
public static UpdateRowResponse deleteRow(SQLiteDatabase db, String tableName, List<RowDataRequest> rowDataRequests) {
245244

246245
UpdateRowResponse updateRowResponse = new UpdateRowResponse();
@@ -282,18 +281,20 @@ public static UpdateRowResponse deleteRow(SQLiteDatabase db, String tableName, L
282281
}
283282

284283

285-
public static Response exec(SQLiteDatabase database, String sql) {
286-
Response response = new Response();
284+
285+
public static TableDataResponse exec(SQLiteDatabase database, String sql) {
286+
TableDataResponse tableDataResponse = new TableDataResponse();
287+
tableDataResponse.isSelectQuery = false;
287288
try {
288289
database.execSQL(sql);
289290
} catch (Exception e) {
290291
e.printStackTrace();
291-
response.isSuccessful = false;
292-
response.error = e.getMessage();
293-
return response;
292+
tableDataResponse.isSuccessful = false;
293+
tableDataResponse.errorMessage = e.getMessage();
294+
return tableDataResponse;
294295
}
295-
response.isSuccessful = true;
296-
return response;
296+
tableDataResponse.isSuccessful = true;
297+
return tableDataResponse;
297298
}
298299

299300
private static String getTableName(String selectQuery) {

debug-db/src/main/java/com/amitshekhar/utils/PrefHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public static TableDataResponse getAllPrefData(Context context, String tag) {
8888

8989
TableDataResponse response = new TableDataResponse();
9090
response.isSuccessful = true;
91+
response.isSelectQuery = true;
9192

9293
TableDataResponse.TableInfo keyInfo = new TableDataResponse.TableInfo();
9394
keyInfo.isPrimary = true;

0 commit comments

Comments
 (0)