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:io.vit.vitio.Managers.ConnectDatabase.java

public Boolean check() {
    String countQuery = "SELECT  * FROM " + TABLE_COURSES;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(countQuery, null);
    if (cursor == null || cursor.moveToFirst() == false) {
        return false;
    } else// w  w w  .j a va  2s.c o  m
        return true;
}

From source file:io.vit.vitio.Managers.ConnectDatabase.java

public int getCoursesCount() {
    String countQuery = "SELECT  * FROM " + TABLE_COURSES;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(countQuery, null);

    int count = cursor.getCount();

    cursor.close();/*from  w w  w .  ja v  a  2 s  . co m*/
    db.close();

    return count;
}

From source file:com.clutch.ClutchStats.java

public int getCachedChoice(String name) {
    int resp = -1;
    SQLiteDatabase db = getReadableDatabase();
    String[] args = { name };//from  w w  w  .j  a v  a 2s. c  om
    Cursor cur = db.rawQuery("SELECT choice FROM abcache WHERE name = ?", args);
    cur.moveToFirst();
    while (!cur.isAfterLast()) {
        resp = cur.getInt(0);
        cur.moveToNext();
    }
    db.close();
    return resp;
}

From source file:org.nuxeo.android.cache.sql.DocumentProviderTableWrapper.java

public LazyDocumentsList getStoredProvider(Session session, String name) {

    SQLiteDatabase db = getReadableDatabase();

    String sql = "select * from " + getTableName() + " where " + KEY_COLUMN + "='" + name + "'";
    Cursor cursor = db.rawQuery(sql, null);

    try {//from  ww w .ja v a 2 s .c o  m
        if (cursor.getCount() > 0 && cursor.moveToFirst()) {
            String operationKey = cursor.getString(cursor.getColumnIndex(KEY_COLUMN));
            String operationId = cursor.getString(cursor.getColumnIndex(OPID_COLUMN));
            String jsonParams = cursor.getString(cursor.getColumnIndex(PARAMS_COLUMN));
            String jsonHeaders = cursor.getString(cursor.getColumnIndex(HEADERS_COLUMN));
            String jsonCtx = cursor.getString(cursor.getColumnIndex(CTX_COLUMN));
            String inputType = cursor.getString(cursor.getColumnIndex(INPUT_TYPE_COLUMN));
            String inputRef = cursor.getString(cursor.getColumnIndex(INPUT_REF_COLUMN));
            Boolean inputBin = false;

            if (inputType != null) {
                inputBin = new Boolean(cursor.getString(cursor.getColumnIndex(INPUT_BINARY_COLUMN)));
            }

            OperationRequest request = OperationPersisterHelper.rebuildOperation(session, operationId,
                    jsonParams, jsonHeaders, jsonCtx, inputType, inputRef, inputBin);
            Boolean readOnly = new Boolean(cursor.getString(cursor.getColumnIndex(READ_ONLY_COLUMN)));
            String pageParam = cursor.getString(cursor.getColumnIndex(PAGE_PARAM_COLUMN));

            LazyDocumentsList result = null;
            if (readOnly) {
                result = new LazyDocumentsListImpl(request, pageParam);
            } else {
                result = new LazyUpdatableDocumentsListImpl(request, pageParam);
            }
            result.setName(name);
            return result;
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return null;
}

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

Cursor getAllDestinationCursor() {
    SQLiteDatabase db = getReadableDatabase();
    return db.rawQuery("SELECT * FROM " + TABLE_NAME + " ORDER BY " + COLUMN_NAME_ARRIVAL, null);
}

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

/**
 * Returns the destination with the given _id.
 *//*from www  .ja  v a  2  s  . co m*/
public Destination getDestination(int id) {
    SQLiteDatabase db = getReadableDatabase();
    Cursor c = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + COLUMN_NAME_ID + " = " + id, null);
    c.moveToFirst();
    Destination d = getCursorDestination(c);
    c.close();

    return d;
}

From source file:com.acrylicgoat.scrumnotes.DailyNotesActivity.java

private void getNotes() {
    //Log.d("MainActivity", "getYesterday() called: " + owner);

    DatabaseHelper dbHelper = new DatabaseHelper(this.getApplicationContext());
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    cursor = db.rawQuery("select goals_note from goals", null);
    if (cursor.getCount() > 0) {
        cursor.moveToNext();/* w  w w . j av a  2s. co  m*/
        int notesColumn = cursor.getColumnIndex(Goals.NOTE);
        //Log.d("MainActivity.getYesterday()", "notesColumn: " + notesColumn);
        note.setText(cursor.getString(notesColumn));

    } else {
        note.setText("");
    }
    cursor.close();
    db.close();
}

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

public long getFirstDeparture() {
    SQLiteDatabase db = getReadableDatabase();
    Cursor c = db.rawQuery("SELECT " + COLUMN_NAME_DEPARTURE + " FROM " + TABLE_NAME + " ORDER BY "
            + COLUMN_NAME_DEPARTURE + " ASC LIMIT 1", null);
    c.moveToFirst();/*w ww  . ja v a2  s.c o  m*/
    long l;
    if (c.isAfterLast()) {
        l = -1;
    } else {
        l = c.getLong(c.getColumnIndex(COLUMN_NAME_DEPARTURE));
    }
    c.close();
    return l;
}

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

public long getLastArrival() {
    SQLiteDatabase db = getReadableDatabase();
    Cursor c = db.rawQuery("SELECT " + COLUMN_NAME_ARRIVAL + " FROM " + TABLE_NAME + " ORDER BY "
            + COLUMN_NAME_ARRIVAL + " DESC LIMIT 1", null);
    c.moveToFirst();//w ww.ja v  a 2s  .c  o  m
    long l;
    if (c.isAfterLast()) {
        l = -1;
    } else {
        l = c.getLong(c.getColumnIndex(COLUMN_NAME_ARRIVAL));
    }
    c.close();
    return l;
}

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

public long getLastDeparture() {
    SQLiteDatabase db = getReadableDatabase();
    Cursor c = db.rawQuery("SELECT " + COLUMN_NAME_DEPARTURE + " FROM " + TABLE_NAME + " ORDER BY "
            + COLUMN_NAME_DEPARTURE + " DESC LIMIT 1", null);
    c.moveToFirst();//w ww  .ja  va2 s .c  o m
    long l;
    if (c.isAfterLast()) {
        l = -1;
    } else {
        l = c.getLong(c.getColumnIndex(COLUMN_NAME_DEPARTURE));
    }
    c.close();
    return l;
}