Example usage for android.database.sqlite SQLiteDatabase rawQuery

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

Introduction

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

Prototype

public Cursor rawQuery(String sql, String[] selectionArgs) 

Source Link

Document

Runs the provided SQL and returns a Cursor over the result set.

Usage

From source file:Main.java

public static int getNbEspece(SQLiteDatabase db) {
    Cursor res = db.rawQuery("SELECT count(*) FROM espece", null);
    res.moveToFirst();/* www  . j  av a2  s .co m*/
    return res.getInt(0);
}

From source file:Main.java

public static int getNbTravail(SQLiteDatabase db) {
    Cursor res = db.rawQuery("SELECT count(*) FROM travail", null);
    res.moveToFirst();/*from   w w  w .  j av  a 2s  . c o  m*/
    return res.getInt(0);
}

From source file:Main.java

public static Cursor first(SQLiteDatabase db, String name) {
    return db.rawQuery("SELECT id, data FROM " + name + " LIMIT 1;", null);
}

From source file:Main.java

public static Cursor all(SQLiteDatabase db, String name) {
    return db.rawQuery("SELECT id, data FROM " + name + ";", null);
}

From source file:Main.java

/**
 * Read data of the last database entry and returns the data as a cursor
 *
 * @param db//  w w w .  j a v a 2  s.c om
 *            pointer to database
 * @return <code>Cursor</code> dayStamp
 *            Cursor with the data of the last row
 *            Entry is
 *            cursor[0] = year stamp
 *            cursor[1] = month stamp
 *            cursor[2] = day stamp
 *            cursor[3] = hour stamp
 *            cursor[4] = minute stamp
 *            cursor[5] = sensor power
 *            cursor[6] = consumed power
 *            cursor[7] = light value
 */
public static Cursor getLastRow(SQLiteDatabase db) {
    return db.rawQuery("select * from " + TABLE_NAME + " order by id desc LIMIT 1", null);
}

From source file:Main.java

private static boolean columnExists(SQLiteDatabase db, String table, String column) {
    return (db.rawQuery("select * from " + table + " limit 0,1", null).getColumnIndex(column) != -1);
}

From source file:Main.java

public static int getGroupCount(SQLiteDatabase db) {
    int count = 0;
    Cursor cursor = db.rawQuery("select count(*) from classlist", null);
    cursor.moveToNext();/*from   www.j  av a  2 s .c o m*/
    count = cursor.getInt(0);
    cursor.close();
    return count;
}

From source file:Main.java

/**
 *  Check if we have the schema information for a model in our database
 * @param model the model we want to check
 * @param db a readable link to our database
 * @return if the model schema exists/*  w  w  w  . j ava  2  s  . c om*/
 */
public static synchronized boolean schemaCheck(SQLiteDatabase db, String model) {
    Cursor cursor = db.rawQuery("select DISTINCT tbl_name from sqlite_master where tbl_name = '" + model + "'",
            null);
    if (cursor != null) {
        if (cursor.getCount() > 0) {
            cursor.close();
            return true;
        }
        cursor.close();
    }
    return false;
}

From source file:Main.java

public static boolean is_any_info_available(SQLiteDatabase db) {
    boolean result = false;

    Cursor cInfo = db.rawQuery("select INFO_ID from TESTING", null);
    if (cInfo != null) {
        if (cInfo.moveToFirst()) {
            result = true;/*from w ww  .  j  av a 2 s  . c om*/
        }
    }
    if (cInfo != null)
        cInfo.close();
    return result;
}

From source file:Main.java

/**
 * Read data of day "dayNumber" and returns the data as a cursor
 *
 * @param db//from  ww w .  ja  va 2s. com
 *            pointer to database
 * @param dayNumber
 *            the day we want to read (1-31)
 * @param monthSelected
 *            the month we want to read from
 * @param yearSelected
 *            the year we want to read from
 * @return <code>Cursor</code> dayStamp
 *            Cursor with all database entries matching with dayNumber
 *            Entry per minute is
 *            cursor[0] = year stamp
 *            cursor[1] = month stamp
 *            cursor[2] = day stamp
 *            cursor[3] = hour stamp
 *            cursor[4] = minute stamp
 *            cursor[5] = sensor power
 *            cursor[6] = consumed power
 *            cursor[7] = light value
 */
public static Cursor getDay(SQLiteDatabase db, int dayNumber, int monthSelected, int yearSelected) {
    return db
            .rawQuery(
                    "select * from " + TABLE_NAME + " where day= " + String.valueOf(dayNumber) + " and month= "
                            + String.valueOf(monthSelected) + " and year= " + String.valueOf(yearSelected),
                    null);
}