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:com.cryart.sabbathschool.util.SSCore.java

public SSLesson ssGetTodaysLesson() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(
            "SELECT ss_lessons.* FROM ss_lessons, ss_days, ss_quarters "
                    + "WHERE ss_days.day_date = ? AND ss_days.day_lesson_serial = ss_lessons.serial "
                    + "   AND ss_lessons.lesson_quarter_serial = ss_quarters.serial"
                    + "   AND ss_quarters.quarter_lang = ? ORDER BY ss_lessons.serial " + "ASC LIMIT 1",
            new String[] { this.ssTodaysDate(), LANGUAGE });

    if (cursor != null)
        cursor.moveToFirst();/*from w  ww  .  jav a 2 s  .  co m*/

    return new SSLesson(cursor.getInt(0), cursor.getString(2), cursor.getString(4));
}

From source file:com.seneca.android.senfitbeta.DbHelper.java

public void removeFromCal(int id) {
    Log.d("REMOVEING", "deleting");

    String selectQuery = "DELETE FROM calendar WHERE Num = " + id;

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    cursor.moveToFirst();//from  w w w  . j  a v a 2s. c  om

}

From source file:com.cryart.sabbathschool.util.SSCore.java

public SSDay ssGetDay(String day_date) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT ss_days.*, ss_lessons.lesson_image as lesson_image "
            + "FROM ss_days, ss_lessons, ss_quarters "
            + "WHERE ss_days.day_date = ? AND ss_days.day_lesson_serial = ss_lessons.serial "
            + "   AND ss_lessons.lesson_quarter_serial = ss_quarters.serial "
            + "   AND ss_quarters.quarter_lang = ? LIMIT 1", new String[] { day_date, LANGUAGE });

    if (cursor != null)
        cursor.moveToFirst();/*from ww  w  .j av  a 2 s  . c o m*/

    return new SSDay(cursor.getInt(0), cursor.getInt(1), cursor.getString(2), cursor.getString(3),
            cursor.getString(4), cursor.getString(5), cursor.getString(6), cursor.getString(7),
            cursor.getString(8), cursor.getString(9));
}

From source file:com.cryart.sabbathschool.util.SSCore.java

public ArrayList<SSLesson> ssGetLessons() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery("SELECT ss_quarters.serial " + "FROM ss_quarters, ss_lessons, ss_days "
            + "WHERE ss_days.day_date = ? AND ss_days.day_lesson_serial = ss_lessons.serial "
            + "   AND ss_lessons.lesson_quarter_serial = ss_quarters.serial "
            + "   AND ss_quarters.quarter_lang = ?", new String[] { this.ssTodaysDate(), LANGUAGE });

    c.moveToFirst();/*w  w w  . j  a v a  2  s  . c om*/
    int ssQuarterSerial = c.getInt(0);

    c = db.rawQuery("SELECT ss_lessons.* " + "FROM ss_lessons " + "WHERE ss_lessons.lesson_quarter_serial = ?",
            new String[] { String.valueOf(ssQuarterSerial) });

    ArrayList<SSLesson> ret = new ArrayList<SSLesson>();
    if (c.moveToFirst()) {
        do {
            ret.add(new SSLesson(c.getInt(0), c.getString(2), c.getString(4)));
        } while (c.moveToNext());
    }
    return ret;
}

From source file:com.seneca.android.senfitbeta.DbHelper.java

public boolean checkEmailExists(String email) {
    String query = "Select * from " + USER_TABLE + " where email like '" + email + "'";

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(query, null);
    cursor.moveToFirst();//from www. j  a v a 2 s  .co m

    if (cursor.getCount() > 0) {
        return true;
    } else {
        return false;
    }
}

From source file:com.seneca.android.senfitbeta.DbHelper.java

public boolean getUser(String email, String pass) {
    String selectQuery = "select * from " + USER_TABLE + " where " + COLUMN_EMAIL + " = " + "'" + email + "'"
            + " and " + COLUMN_PASS + " = " + "'" + pass + "'";

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    cursor.moveToFirst();//from   w  w w .ja v a2s.c o m

    if (cursor.getCount() > 0) {
        return true;
    }
    cursor.close();
    db.close();
    return false;
}

From source file:com.cryart.sabbathschool.util.SSCore.java

public String ssTodaysDate() {
    if (SSCore.ssTodayDate == null) {
        String ssTodayTmp = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());

        SQLiteDatabase db = this.getReadableDatabase();
        Cursor c = db.rawQuery("SELECT COUNT(1) FROM ss_days, ss_lessons, ss_quarters "
                + "WHERE ss_days.day_date = ? AND ss_days.day_lesson_serial = ss_lessons.serial "
                + "   AND ss_lessons.lesson_quarter_serial = ss_quarters.serial "
                + "   AND ss_quarters.quarter_lang = ?", new String[] { ssTodayTmp, LANGUAGE });

        c.moveToFirst();//from w w w  .  jav  a  2s .c om
        int count = c.getInt(0);
        c.close();

        if (count < 1) {
            c = db.rawQuery(
                    "SELECT ss_days.day_date " + "FROM ss_days, ss_lessons, ss_quarters "
                            + "WHERE ss_days.day_lesson_serial = ss_lessons.serial "
                            + "   AND ss_lessons.lesson_quarter_serial = ss_quarters.serial "
                            + "   AND ss_quarters.quarter_lang = ? " + "ORDER BY ss_days.day_date DESC LIMIT 1",
                    new String[] { LANGUAGE });
            c.moveToFirst();
            ssTodayTmp = c.getString(0);
            c.close();
        }

        SSCore.ssTodayDate = ssTodayTmp;
    }

    return SSCore.ssTodayDate;
}

From source file:com.yammy.meter.MainActivity.java

private void checkJarak() {
    double maxval;
    dbHelper = new MySQLHelper(getApplicationContext());
    SQLiteDatabase jdb = dbHelper.getReadableDatabase();
    Cursor cursor = jdb.rawQuery("SELECT maxlength FROM kendaraan WHERE _id=" + idkendaraan, null);
    if (cursor.moveToFirst()) {
        maxval = cursor.getDouble(0);/*from   w ww .j a va  2  s . c  o m*/
        double temp;
        temp = (totalJarakDitempuhKendaraan % maxval);
        //simple if, need 'mbengkel' data for details
        //cursor = jdb.rawQuery("SELECT jarak FROM latest_mbengkel WHERE id_kendaraan="+idkendaraan, null);
        if (temp >= maxval * 90 / 100) {
            showAlert();
        }
    }
    jdb.close();
}

From source file:com.seneca.android.senfitbeta.DbHelper.java

public ArrayList<Muscle> getMuscles() {
    Log.d("MUSCLE_GET", "Geting muscles");

    String fetchMus = "select * from " + RIP_TABLE + " ORDER BY " + RIP_NAME + " ASC";

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(fetchMus, null);
    cursor.moveToFirst();/*  w  w w . j  a va 2  s  . c om*/

    if (cursor == null) {
        Log.d("exiting", "NOTHING");
    }
    if (cursor.getCount() == 0) {
        Log.d("NOTHING", "0 nothing");
    }

    ArrayList<Muscle> temp = new ArrayList<Muscle>();

    cursor.moveToFirst();
    do {
        Muscle ex = new Muscle();
        ex.setId(cursor.getInt(cursor.getColumnIndex(RIP_ID)));
        ex.setName(cursor.getString(cursor.getColumnIndex(RIP_NAME)));

        temp.add(ex);
    } while (cursor.moveToNext());

    cursor.close();
    getReadableDatabase().close();
    return temp;

}

From source file:com.seneca.android.senfitbeta.DbHelper.java

public ArrayList<Exercise> getExercises() {
    Log.d("SELECT EXDB", "Getinging exercise");

    String fetchdata = "select * from " + EXERCISE_TABLE + " ORDER BY " + NAMETYPE + " ASC";

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(fetchdata, null);
    cursor.moveToFirst();/*  ww w . j  a v  a2  s.c  o m*/

    if (cursor == null) {
        Log.d("exiting", "NOTHING");
    }

    ArrayList<Exercise> temp = new ArrayList<Exercise>();

    cursor.moveToFirst();
    do {
        Exercise ex = new Exercise();
        ex.setId(cursor.getInt(cursor.getColumnIndex(EXERCISE_ID)));
        ex.setLicense_author(cursor.getString(cursor.getColumnIndex(AUTHOR)));
        ex.setDescription(cursor.getString(cursor.getColumnIndex(DESCRIPTION)));
        ex.setName(cursor.getString(cursor.getColumnIndex(NAMETYPE)));
        ex.setName_original(cursor.getString(cursor.getColumnIndex(ORIGNALNAME)));
        ex.setCreation_date(cursor.getString(cursor.getColumnIndex(CREATIONDATE)));
        ex.setCategory(cursor.getString(cursor.getColumnIndex(CATEGORY)));

        temp.add(ex);
    } while (cursor.moveToNext());

    cursor.close();
    getReadableDatabase().close();
    return temp;

}