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.shalzz.attendance.DatabaseHandler.java

/**
 * Check if the Student data is in database.
 * *///from w  w w.j  a  va  2s .c o m
public int getUserCount() {
    SQLiteDatabase db = getReadableDatabase();
    try (Cursor cursor = db.rawQuery(User.SELECT_COUNT, null)) {
        int rowCount = 0;
        if (cursor.moveToNext())
            rowCount = cursor.getInt(0);

        return rowCount;
    }
}

From source file:com.shalzz.attendance.DatabaseHandler.java

public int getPeriodCount() {
    SQLiteDatabase db = getReadableDatabase();
    try (Cursor cursor = db.rawQuery(Period.SELECT_COUNT, null)) {
        int rowCount = 0;
        if (cursor.moveToNext())
            rowCount = cursor.getInt(0);
        cursor.close();/*  www. j  a  v  a  2s  .c o  m*/

        return rowCount;
    }
}

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

public void ssSaveHighlights(int ssDaySerial, String highlights) {
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cu = db.rawQuery("UPDATE ss_days SET day_highlights = ? " + "WHERE serial = ?",
            new String[] { highlights, String.valueOf(ssDaySerial) });
    cu.moveToFirst();/*from   w w  w  .j  a  v a 2  s  . co m*/
    cu.close();
    db.close();
}

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

public void ssSaveComments(int ssDaySerial, String comments) {
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cu = db.rawQuery("UPDATE ss_days SET day_comments = ? " + "WHERE serial = ?",
            new String[] { comments, String.valueOf(ssDaySerial) });
    cu.moveToFirst();//w ww. ja va 2 s  .  com
    cu.close();
    db.close();
}

From source file:com.shalzz.attendance.DatabaseHandler.java

public User getUser() {
    SQLiteDatabase db = this.getReadableDatabase();

    try (Cursor cursor = db.rawQuery(User.SELECT_ALL, null)) {

        if (cursor.moveToNext()) {
            return User.MAPPER.map(cursor);
        }//from  ww  w .j  a v  a2s .  co  m
    }
    return null;
}

From source file:com.shalzz.attendance.DatabaseHandler.java

public ArrayList<Period> getAllPeriods(Date date, AsyncTaskLoader callback) {
    String dayName = DateHelper.getShortWeekday(date);
    ArrayList<Period> periods = new ArrayList<>();
    SQLiteDatabase db = getReadableDatabase();
    try (Cursor cursor = db.rawQuery(Period.SELECT_BY_WEEK_DAY, new String[] { dayName })) {

        while (cursor.moveToNext()) {
            // Check isLoadInBackgroundCanceled() to cancel out early
            if (callback != null && callback.isLoadInBackgroundCanceled()) {
                break;
            }//from   www  .j a va  2  s  .co  m
            periods.add(Period.MAPPER.map(cursor));
        }
    }

    return periods;
}

From source file:com.shalzz.attendance.DatabaseHandler.java

public long getLastSync() {
    SQLiteDatabase db = this.getReadableDatabase();
    try (Cursor cursor = db.rawQuery(Subject.SELECT_LAST_SYNC, null)) {

        if (cursor.moveToFirst()) {
            long now = new Date().getTime();
            long lastSync = cursor.getLong(0);
            return (now - lastSync) / (1000 * 60 * 60);
        }/*w  ww  .ja  v a2 s  . co  m*/
        cursor.close();
        return -1;
    }
}

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

public ArrayList<SSDay> ssGetDaysByLessonSerial(int ssLessonSerial) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(
            "SELECT ss_days.* " + "FROM ss_days WHERE day_lesson_serial = ? " + "ORDER BY serial ASC",
            new String[] { String.valueOf(ssLessonSerial) });

    ArrayList<SSDay> ret = new ArrayList<SSDay>();
    if (c.moveToFirst()) {
        do {/*from  w w  w. j  ava  2  s.  c  o m*/
            ret.add(new SSDay(c.getInt(0), c.getString(2), c.getString(3), c.getString(7)));
        } while (c.moveToNext());
    }
    return ret;
}

From source file:com.dpcsoftware.mn.EditCategories.java

private void renderCategories() {
    SQLiteDatabase db = DatabaseHelper.quickDb(this, 0);
    Cursor c = db
            .rawQuery(//from  www  . j a  v  a2s  . c  o  m
                    "SELECT " + Db.Table2._ID + "," + Db.Table2.COLUMN_NCAT + "," + Db.Table2.COLUMN_CORCAT
                            + " FROM " + Db.Table2.TABLE_NAME + " ORDER BY " + Db.Table2.COLUMN_NCAT + " ASC",
                    null);
    if (adapter == null) {
        adapter = new CategoriesAdapter(this, c);
        lv.setAdapter(adapter);
        setContentView(lv);
    } else {
        adapter.swapCursor(c);
        adapter.notifyDataSetChanged();
    }
    db.close();
}

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

public boolean quarterlyForLanguageExists() {
    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[] { new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date()),
                    LANGUAGE });/*from w ww .ja  v  a 2 s.  com*/

    c.moveToFirst();
    int count = c.getInt(0);
    c.close();

    return count > 0;
}