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(boolean distinct, String table, String[] columns, String selection, String[] selectionArgs,
        String groupBy, String having, String orderBy, String limit) 

Source Link

Document

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

Usage

From source file:net.zionsoft.obadiah.model.translations.TranslationHelper.java

public static List<String> getDownloadedTranslationShortNames(SQLiteDatabase db) {
    Cursor cursor = null;/*w  w w .  jav a  2s .  c o m*/
    try {
        cursor = db.query(true, DatabaseHelper.TABLE_BOOK_NAMES,
                new String[] { DatabaseHelper.COLUMN_TRANSLATION_SHORT_NAME }, null, null, null, null, null,
                null);
        final int translationShortName = cursor.getColumnIndex(DatabaseHelper.COLUMN_TRANSLATION_SHORT_NAME);
        final List<String> translations = new ArrayList<String>(cursor.getCount());
        while (cursor.moveToNext())
            translations.add(cursor.getString(translationShortName));
        return translations;
    } finally {
        if (cursor != null)
            cursor.close();
    }
}

From source file:Main.java

/**
 * Check if the database exist//  w  ww.  j a va  2 s.c o m
 *
 * @return true if it exists, false if it doesn't
 */
public static boolean checkDataBase(Context context) {
    SQLiteDatabase checkDB = null;
    int count = 0;
    try {
        if (android.os.Build.VERSION.SDK_INT >= 17) {
            DB_PATH = context.getApplicationInfo().dataDir + "/databases/";
        } else {
            DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
        }
        checkDB = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, SQLiteDatabase.OPEN_READONLY);

        String selectRegistros = "SELECT COUNT(*) FROM Grupo_Gastos";

        Cursor mCursor = checkDB.query(true, "Grupo_Gastos", new String[] { "_id" }, null, null, null, null,
                null, null);
        count = mCursor.getCount();

        checkDB.close();
    } catch (SQLiteException e) {
        // database doesn't exist yet.
        return false;
    }
    return count > 0;
}

From source file:uk.org.rivernile.edinburghbustracker.android.SettingsDatabase.java

/**
 * Get a Cursor to all the favourite stop items.
 *
 * @return A Cursor object to all the favourite stop items.
 *///from w  ww. j ava 2s  .  c o m
public Cursor getAllFavouriteStops() {
    final SQLiteDatabase db = getReadableDatabase();
    return db.query(true, FAVOURITE_STOPS_TABLE,
            new String[] { FAVOURITE_STOPS_STOPCODE, FAVOURITE_STOPS_STOPNAME }, null, null, null, null,
            FAVOURITE_STOPS_STOPNAME + " ASC", null);
}

From source file:org.opendatakit.common.android.utilities.ODKDatabaseUtils.java

/**
 * Perform a query with the given parameters.
 * /*  ww w .  jav a  2 s .co m*/
 * @param db
 * @param distinct
 *          true if each returned row should be distinct (collapse duplicates)
 * @param table
 * @param columns
 * @param selection
 * @param selectionArgs
 * @param groupBy
 * @param having
 * @param orderBy
 * @param limit
 * @return
 */
public Cursor query(SQLiteDatabase db, boolean distinct, String table, String[] columns, String selection,
        String[] selectionArgs, String groupBy, String having, String orderBy, String limit) {
    Cursor c = db.query(distinct, table, columns, selection, selectionArgs, groupBy, having, orderBy, limit);
    return c;
}