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 getAppointments() {

    JSONArray data;/* w ww. ja v a 2s  . com*/
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_APPOINTMENTS,
            new String[] { DBSchema.APPOINTMENT_ID, DBSchema.APPOINTMENT_DATE, DBSchema.APPOINTMENT_TIME,
                    DBSchema.APPOINTMENT_REPORT_ID, DBSchema.APPOINTMENT_PURPOSE,
                    DBSchema.APPOINTMENT_MAKER_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.APPOINTMENT_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.APPOINTMENT_DATE, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.APPOINTMENT_TIME, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.APPOINTMENT_REPORT_ID, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(4))
                        map.put(DBSchema.APPOINTMENT_PURPOSE, cursor.getString(4));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(5))
                        map.put(DBSchema.APPOINTMENT_MAKER_ID, cursor.getString(5));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

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

}

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

private JSONArray getLocation() {

    JSONArray data;//from   ww w . j  av  a 2s.co m
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_LOCATION,
            new String[] { DBSchema.LOCATION_ID, DBSchema.LOCATION_NAME, DBSchema.LOCATION_ADDRESS_ID,
                    DBSchema.LOCATION_OWNER_ID, DBSchema.LOCATION_MANAGER_ID, DBSchema.LOCATION_LICENSE,
                    DBSchema.LOCATION_AGENT_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_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.LOCATION_NAME, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.LOCATION_ADDRESS_ID, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.LOCATION_OWNER_ID, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(4))
                        map.put(DBSchema.LOCATION_MANAGER_ID, cursor.getString(4));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(5))
                        map.put(DBSchema.LOCATION_LICENSE, cursor.getString(5));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(6))
                        map.put(DBSchema.LOCATION_AGENT_ID, cursor.getString(6));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

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

}

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

private JSONArray getPerson() {

    JSONArray data;//from  w  w  w . ja  v a  2s .  co  m
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_PERSON,
            new String[] { DBSchema.PERSON_ID, DBSchema.PERSON_LAST_NAME1, DBSchema.PERSON_FIRST_NAME,
                    DBSchema.PERSON_EMAIL,
                    //                        DBSchema.PERSON_SPEC_ID,
                    DBSchema.PERSON_LAST_NAME2, DBSchema.PERSON_MIDDLE_INITIAL, DBSchema.PERSON_PHONE_NUMBER },
            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.PERSON_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.PERSON_LAST_NAME1, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.PERSON_FIRST_NAME, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.PERSON_EMAIL, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                //                    try {
                //                        if (!cursor.isNull(4))
                //                            map.put(DBSchema.PERSON_SPEC_ID, cursor.getString(4));
                //                    } catch (JSONException e) {
                //                        e.printStackTrace();
                //                    }
                try {
                    if (!cursor.isNull(4))
                        map.put(DBSchema.PERSON_LAST_NAME2, cursor.getString(4));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(5))
                        map.put(DBSchema.PERSON_MIDDLE_INITIAL, cursor.getString(5));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(6))
                        map.put(DBSchema.PERSON_PHONE_NUMBER, cursor.getString(6));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

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

}

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

private JSONArray getReport() {

    JSONArray data;//  ww  w .j a v  a2 s .  c  o  m
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_REPORT,
            new String[] { DBSchema.REPORT_ID, DBSchema.REPORT_CREATOR_ID, DBSchema.REPORT_LOCATION_ID,
                    //                        DBSchema.REPORT_SUBJECT_ID,
                    DBSchema.REPORT_FLOWCHART_ID, DBSchema.REPORT_NOTE, DBSchema.REPORT_DATE_FILED,
                    DBSchema.REPORT_NAME, DBSchema.REPORT_STATUS },
            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.REPORT_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.REPORT_CREATOR_ID, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(2))
                        map.put(DBSchema.REPORT_LOCATION_ID, cursor.getString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                //                    try {
                //                        if (!cursor.isNull(3))
                //                            map.put(DBSchema.REPORT_SUBJECT_ID, cursor.getString(3));
                //                    } catch (JSONException e) {
                //                        e.printStackTrace();
                //                    }
                try {
                    if (!cursor.isNull(3))
                        map.put(DBSchema.REPORT_FLOWCHART_ID, cursor.getString(3));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(4))
                        map.put(DBSchema.REPORT_NOTE, cursor.getString(4));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(5))
                        map.put(DBSchema.REPORT_DATE_FILED, cursor.getString(5));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(6))
                        map.put(DBSchema.REPORT_NAME, cursor.getString(6));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(7))
                        map.put(DBSchema.REPORT_STATUS, cursor.getString(7));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

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

}