Search in sources :

Example 1 with Response

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);
}
Also used : Response(com.amitshekhar.model.Response) UpdateRowResponse(com.amitshekhar.model.UpdateRowResponse) TableDataResponse(com.amitshekhar.model.TableDataResponse)

Example 2 with 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;
}
Also used : Response(com.amitshekhar.model.Response) UpdateRowResponse(com.amitshekhar.model.UpdateRowResponse) TableDataResponse(com.amitshekhar.model.TableDataResponse) TableDataResponse(com.amitshekhar.model.TableDataResponse) IOException(java.io.IOException)

Example 3 with Response

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);
}
Also used : Response(com.amitshekhar.model.Response) UpdateRowResponse(com.amitshekhar.model.UpdateRowResponse) TableDataResponse(com.amitshekhar.model.TableDataResponse) SupportSQLiteDatabase(android.arch.persistence.db.SupportSQLiteDatabase) HashMap(java.util.HashMap) Pair(android.util.Pair)

Example 4 with 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;
}
Also used : Response(com.amitshekhar.model.Response) UpdateRowResponse(com.amitshekhar.model.UpdateRowResponse) TableDataResponse(com.amitshekhar.model.TableDataResponse) Cursor(android.database.Cursor)

Example 5 with 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;
}
Also used : Response(com.amitshekhar.model.Response) UpdateRowResponse(com.amitshekhar.model.UpdateRowResponse) TableDataResponse(com.amitshekhar.model.TableDataResponse) Cursor(android.database.Cursor)

Aggregations

Response (com.amitshekhar.model.Response)6 TableDataResponse (com.amitshekhar.model.TableDataResponse)6 UpdateRowResponse (com.amitshekhar.model.UpdateRowResponse)6 Cursor (android.database.Cursor)2 SupportSQLiteDatabase (android.arch.persistence.db.SupportSQLiteDatabase)1 Pair (android.util.Pair)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1