Example usage for android.database.sqlite SQLiteDatabase query

List of usage examples for android.database.sqlite SQLiteDatabase query

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase query.

Prototype

public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy,
        String having, String orderBy, String limit) 

Source Link

Document

Query the given table, returning a Cursor over the result set.

Usage

From source file:com.rener.sea.DBHelper.java

private JSONArray getLocation_category() {

    JSONArray data;//from   w  w  w.  j  a v  a  2s.c om
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_LOCATION_CATEGORY,
            new String[] { DBSchema.LOCATION_CATEGORY_LOCATION_ID, DBSchema.LOCATION_CATEGORY_CATEGORY_ID },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.LOCATION_CATEGORY_LOCATION_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.LOCATION_CATEGORY_CATEGORY_ID, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getUsers_specialization() {

    JSONArray data;//from  w  w  w  .  java2s .co m
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_USERS_SPECIALIZATION,
            new String[] { DBSchema.USERS_SPECIALIZATION_USER_ID,
                    DBSchema.USERS_SPECIALIZATION_SPECIALIZATION_ID },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))//
                        map.put(DBSchema.USERS_SPECIALIZATION_USER_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))//
                        map.put(DBSchema.USERS_SPECIALIZATION_SPECIALIZATION_ID, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

public List<Item> getAllItems(long flowchartID) {
    SQLiteDatabase db = getReadableDatabase();
    long id = -1;
    Cursor cursor = db.query(DBSchema.TABLE_ITEM, new String[] { DBSchema.ITEM_ID },
            DBSchema.ITEM_FLOWCHART_ID + " =? ", new String[] { String.valueOf(flowchartID) }, null, null, null,
            null);/*from w w w.  j a v a  2 s  .c  o m*/
    ArrayList<Item> items = new ArrayList<>();
    if ((cursor != null) && (cursor.getCount() > 0)) {

        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            items.add(new Item(cursor.getLong(0), this));
        }

    }
    return items;
}

From source file:com.rener.sea.DBHelper.java

private JSONArray getPath() {

    JSONArray data;/*from www. ja v  a  2s  .  com*/
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_PATH,
            new String[] { DBSchema.PATH_REPORT_ID, DBSchema.PATH_OPTION_ID, DBSchema.PATH_DATA,
                    DBSchema.PATH_SEQUENCE },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.PATH_REPORT_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.PATH_OPTION_ID, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.PATH_DATA, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.PATH_SEQUENCE, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getItem() {

    JSONArray data;//  w w w . ja v  a  2s  .  co m
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_ITEM,
            new String[] { DBSchema.ITEM_ID, DBSchema.ITEM_FLOWCHART_ID, DBSchema.ITEM_LABEL,
                    DBSchema.ITEM_TYPE },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.ITEM_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.ITEM_FLOWCHART_ID, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.ITEM_LABEL, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.ITEM_TYPE, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getOption() {

    JSONArray data;//  ww  w .j  a v a  2 s  .c o  m
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_OPTION,
            new String[] { DBSchema.OPTION_ID, DBSchema.OPTION_PARENT_ID, DBSchema.OPTION_NEXT_ID,
                    DBSchema.OPTION_LABEL },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.OPTION_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.OPTION_PARENT_ID, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.OPTION_NEXT_ID, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.OPTION_LABEL, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getDevices() {

    JSONArray data;//from   www.  ja  va  2  s.  c  om
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_DEVICES,
            new String[] { DBSchema.DEVICE_ID, DBSchema.DEVICE_NAME, DBSchema.DEVICE_ID_NUMBER,
                    DBSchema.DEVICE_USER_ID, DBSchema.DEVICE_LATEST_SYNC },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.DEVICE_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.DEVICE_NAME, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.DEVICE_ID_NUMBER, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.DEVICE_USER_ID, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(4))
                        map.put(DBSchema.DEVICE_LATEST_SYNC, cursor.getString(4));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getAddress() {

    JSONArray data;/*  ww w  .  j a v a 2 s .  c  om*/
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_ADDRESS,
            new String[] { DBSchema.ADDRESS_ID, DBSchema.ADDRESS_LINE1, DBSchema.ADDRESS_CITY,
                    DBSchema.ADDRESS_ZIPCODE, DBSchema.ADDRESS_LINE2 },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.ADDRESS_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.ADDRESS_LINE1, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.ADDRESS_CITY, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.ADDRESS_ZIPCODE, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(4))
                        map.put(DBSchema.ADDRESS_LINE2, cursor.getString(4));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getUsers() {

    JSONArray data;/*from w  ww.j a  v a2s . c  om*/
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_USERS,
            new String[] { DBSchema.USER_ID, DBSchema.USER_USERNAME, DBSchema.USER_PASSHASH,
                    DBSchema.USER_PERSON_ID, DBSchema.USER_SALT },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.USER_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.USER_USERNAME, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.USER_PASSHASH, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.USER_PERSON_ID, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(4))
                        map.put(DBSchema.USER_SALT, cursor.getString(4));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getFlowchart() {

    JSONArray data;/*from w w w  . ja va2s . com*/
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_FLOWCHART,
            new String[] { DBSchema.FLOWCHART_ID, DBSchema.FLOWCHART_FIRST_ID, DBSchema.FLOWCHART_NAME,
                    DBSchema.FLOWCHART_END_ID, DBSchema.FLOWCHART_CREATOR_ID, DBSchema.FLOWCHART_VERSION },
            DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.FLOWCHART_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.FLOWCHART_FIRST_ID, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.FLOWCHART_NAME, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.FLOWCHART_END_ID, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(4))
                        map.put(DBSchema.FLOWCHART_CREATOR_ID, cursor.getString(4));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(5))
                        map.put(DBSchema.FLOWCHART_VERSION, cursor.getString(5));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}