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:Main.java

@Nullable
static Cursor getRegionRanges(@NonNull SQLiteDatabase db, int regionCode) {
    return db.query(TABLE_RANGE,
            new String[] { COLUMN_RANGE_START, COLUMN_RANGE_CAPACITY, COLUMN_OPERATOR, COLUMN_REGION },
            COLUMN_REGION_CODE + "=?", new String[] { String.valueOf(regionCode) }, null, null, null, null);
}

From source file:Main.java

static ImmutableSet<String> getColumns(SQLiteDatabase db, String table) {
    Cursor cursor = db.query(table, null, null, null, null, null, null, "0");
    if (cursor != null) {
        try {//from  w  ww.  jav  a2 s .c o m
            return ImmutableSet.copyOf(cursor.getColumnNames());
        } finally {
            cursor.close();
        }
    }
    return ImmutableSet.of();
}

From source file:Main.java

/** Returns true if there in the supplied database exists a row in the table 'tableName' where 'columnName'='columnValueWanted'.
 *
 * @param db A readable SQLiteDatabase object.
 * @param tableName The name of the table to scan. "FROM tableName"
 * @param columnName The name of the column
 * @param columnValueWanted The values you want to see if exists in a column.
 * @return Does the wanted value exist in the column in any row of the table in the database?
 *//*from   w  w w  . j  av  a  2s. c o m*/
public static boolean containsRowWithWhereStatement(SQLiteDatabase db, String tableName, String columnName,
        String columnValueWanted) {
    Cursor c = db.query(tableName, new String[] { columnName }, columnName + "=?",
            new String[] { columnValueWanted }, null, null, null, "1");
    boolean output = c.getCount() > 0;
    c.close();
    return output;
}

From source file:Main.java

public static String loadString(String key, String defaultVal, SQLiteDatabase db) {
    String ret = defaultVal;//ww  w  .j ava2  s  . c om
    if (db == null)
        return ret;

    Cursor cursor = db.query(TABLE_SETTINGS,
            new String[] { KEY_SETTINGS_ID, KEY_SETTINGS_KEY, KEY_SETTINGS_VALUE }, KEY_SETTINGS_KEY + "=?",
            new String[] { key }, null, null, null, null);

    if (cursor != null) {
        boolean moveFirst = cursor.moveToFirst();
        if (moveFirst)
            ret = cursor.getString(2);
    }

    return ret;
}

From source file:org.getlantern.firetweet.util.content.DatabaseUpgradeHelper.java

private static String[] getColumnNames(final SQLiteDatabase db, final String table) {
    final Cursor cur = db.query(table, null, null, null, null, null, null, "1");
    if (cur == null)
        return null;
    try {// ww  w. j  a v  a2 s. c  o m
        return cur.getColumnNames();
    } finally {
        cur.close();
    }
}

From source file:org.frc836.database.DB.java

public static String getPosNameFromID(int posId, SQLiteDatabase db) {

    String[] projection = { POSITION_LU_Entry.COLUMN_NAME_POSITION };
    String[] where = { String.valueOf(posId) };
    Cursor c = db.query(POSITION_LU_Entry.TABLE_NAME, projection, // select
            POSITION_LU_Entry.COLUMN_NAME_ID + "= ?", where, // EventName
            null, // don't group
            null, // don't filter
            null, // don't order
            "0,1"); // limit to 1
    String ret = "";
    try {//from w  w  w. j  a  v  a2  s  .c  om
        c.moveToFirst();
        ret = c.getString(c.getColumnIndexOrThrow(POSITION_LU_Entry.COLUMN_NAME_POSITION));
    } finally {
        if (c != null)
            c.close();
    }
    return ret;
}

From source file:org.frc836.database.DB.java

public static String getEventNameFromID(int eventId, SQLiteDatabase db) {

    String[] projection = { EVENT_LU_Entry.COLUMN_NAME_EVENT_NAME };
    String[] where = { String.valueOf(eventId) };
    Cursor c = db.query(EVENT_LU_Entry.TABLE_NAME, projection, // select
            EVENT_LU_Entry.COLUMN_NAME_ID + "= ?", where, // EventName
            null, // don't group
            null, // don't filter
            null, // don't order
            "0,1"); // limit to 1
    String ret = "";
    try {/*from   w  ww.j a  va  2  s  .  c o  m*/
        c.moveToFirst();
        ret = c.getString(c.getColumnIndexOrThrow(EVENT_LU_Entry.COLUMN_NAME_EVENT_NAME));
    } finally {
        if (c != null)
            c.close();
    }
    return ret;
}

From source file:org.frc836.database.DB.java

public static String getEventCodeFromID(int eventId, SQLiteDatabase db) {

    String[] projection = { EVENT_LU_Entry.COLUMN_NAME_EVENT_CODE };
    String[] where = { String.valueOf(eventId) };
    Cursor c = db.query(EVENT_LU_Entry.TABLE_NAME, projection, // select
            EVENT_LU_Entry.COLUMN_NAME_ID + "= ?", where, // EventName
            null, // don't group
            null, // don't filter
            null, // don't order
            "0,1"); // limit to 1
    String ret = "";
    try {/*from  w  ww .java  2s.  com*/
        c.moveToFirst();
        ret = c.getString(c.getColumnIndexOrThrow(EVENT_LU_Entry.COLUMN_NAME_EVENT_CODE));
    } finally {
        if (c != null)
            c.close();
    }
    return ret;
}

From source file:org.frc836.database.DB.java

public static String getWheelBaseNameFromID(int base, SQLiteDatabase db) {

    String[] projection = { WHEEL_BASE_LU_Entry.COLUMN_NAME_WHEEL_BASE_DESC };
    String[] where = { String.valueOf(base) };
    Cursor c = db.query(WHEEL_BASE_LU_Entry.TABLE_NAME, projection, // select
            WHEEL_BASE_LU_Entry.COLUMN_NAME_ID + "= ?", where, // EventName
            null, // don't group
            null, // don't filter
            null, // don't order
            "0,1"); // limit to 1
    String ret = "";
    try {//  w w  w .  ja v  a 2 s  . c  o  m
        c.moveToFirst();
        ret = c.getString(c.getColumnIndexOrThrow(WHEEL_BASE_LU_Entry.COLUMN_NAME_WHEEL_BASE_DESC));
    } finally {
        if (c != null)
            c.close();
    }
    return ret;
}

From source file:org.frc836.database.DB.java

public static String getWheelTypeNameFromID(int type, SQLiteDatabase db) {

    String[] projection = { WHEEL_TYPE_LU_Entry.COLUMN_NAME_WHEEL_TYPE_DESC };
    String[] where = { String.valueOf(type) };
    Cursor c = db.query(WHEEL_TYPE_LU_Entry.TABLE_NAME, projection, // select
            WHEEL_TYPE_LU_Entry.COLUMN_NAME_ID + " LIKE ?", where, // EventName
            null, // don't group
            null, // don't filter
            null, // don't order
            "0,1"); // limit to 1
    String ret = "";
    try {/*from   ww  w.  j a va 2s  .c  om*/
        c.moveToFirst();
        ret = c.getString(c.getColumnIndexOrThrow(WHEEL_TYPE_LU_Entry.COLUMN_NAME_WHEEL_TYPE_DESC));
    } finally {
        if (c != null)
            c.close();
    }
    return ret;
}