use of com.amitshekhar.model.Response in project Android-Debug-Database by amitshekhariitbhu.
the class RequestHandler method getTableListResponse.
private String getTableListResponse(String route) {
String database = null;
if (route.contains("?database=")) {
database = route.substring(route.indexOf("=") + 1, route.length());
}
Response response;
if (Constants.APP_SHARED_PREFERENCES.equals(database)) {
response = PrefHelper.getAllPrefTableName(mContext);
closeDatabase();
mSelectedDatabase = Constants.APP_SHARED_PREFERENCES;
} else {
openDatabase(database);
response = DatabaseHelper.getAllTableName(sqLiteDB);
mSelectedDatabase = database;
}
return mGson.toJson(response);
}
use of com.amitshekhar.model.Response in project Android-Debug-Database by amitshekhariitbhu.
the class RequestHandler method executeQueryAndGetResponse.
private String executeQueryAndGetResponse(String route) {
String query = null;
String data = null;
String first;
try {
if (route.contains("?query=")) {
query = route.substring(route.indexOf("=") + 1, route.length());
}
try {
query = URLDecoder.decode(query, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
if (query != null) {
String[] statements = query.split(";");
for (int i = 0; i < statements.length; i++) {
String aQuery = statements[i].trim();
first = aQuery.split(" ")[0].toLowerCase();
if (first.equals("select") || first.equals("pragma")) {
TableDataResponse response = DatabaseHelper.getTableData(sqLiteDB, aQuery, null);
data = mGson.toJson(response);
if (!response.isSuccessful) {
break;
}
} else {
TableDataResponse response = DatabaseHelper.exec(sqLiteDB, aQuery);
data = mGson.toJson(response);
if (!response.isSuccessful) {
break;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (data == null) {
Response response = new Response();
response.isSuccessful = false;
data = mGson.toJson(response);
}
return data;
}
use of com.amitshekhar.model.Response in project Android-Debug-Database by amitshekhariitbhu.
the class RequestHandler method getDBListResponse.
private String getDBListResponse() {
mDatabaseFiles = DatabaseFileProvider.getDatabaseFiles(mContext);
if (mCustomDatabaseFiles != null) {
mDatabaseFiles.putAll(mCustomDatabaseFiles);
}
Response response = new Response();
if (mDatabaseFiles != null) {
for (HashMap.Entry<String, Pair<File, String>> entry : mDatabaseFiles.entrySet()) {
String[] dbEntry = { entry.getKey(), !entry.getValue().second.equals("") ? "true" : "false", "true" };
response.rows.add(dbEntry);
}
}
if (mRoomInMemoryDatabases != null) {
for (HashMap.Entry<String, SupportSQLiteDatabase> entry : mRoomInMemoryDatabases.entrySet()) {
String[] dbEntry = { entry.getKey(), "false", "false" };
response.rows.add(dbEntry);
}
}
response.rows.add(new String[] { Constants.APP_SHARED_PREFERENCES, "false", "false" });
response.isSuccessful = true;
return mGson.toJson(response);
}
use of com.amitshekhar.model.Response in project Android-Debug-Database by amitshekhariitbhu.
the class DatabaseHelper method getAllTableName.
public static Response getAllTableName(SQLiteDatabase database) {
Response response = new Response();
Cursor c = database.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
if (c.moveToFirst()) {
while (!c.isAfterLast()) {
response.rows.add(c.getString(0));
c.moveToNext();
}
}
c.close();
response.isSuccessful = true;
try {
response.dbVersion = database.getVersion();
} catch (Exception ignore) {
}
return response;
}
use of com.amitshekhar.model.Response in project Android-Debug-Database by amitshekhariitbhu.
the class DatabaseHelper method getAllTableName.
public static Response getAllTableName(SQLiteDB database) {
Response response = new Response();
Cursor c = database.rawQuery("SELECT name FROM sqlite_master WHERE type='table' OR type='view' ORDER BY name COLLATE NOCASE", null);
if (c.moveToFirst()) {
while (!c.isAfterLast()) {
response.rows.add(c.getString(0));
c.moveToNext();
}
}
c.close();
response.isSuccessful = true;
try {
response.dbVersion = database.getVersion();
} catch (Exception ignore) {
}
return response;
}
Aggregations