Example usage for android.database Cursor moveToFirst

List of usage examples for android.database Cursor moveToFirst

Introduction

In this page you can find the example usage for android.database Cursor moveToFirst.

Prototype

boolean moveToFirst();

Source Link

Document

Move the cursor to the first row.

Usage

From source file:com.clutch.ClutchStats.java

public int getCachedChoice(String name) {
    int resp = -1;
    SQLiteDatabase db = getReadableDatabase();
    String[] args = { name };/*w  ww . j a v  a 2  s  . co m*/
    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:com.yozio.android.YozioDataStoreImpl.java

public int getNumEvents() {
    synchronized (this) {
        int count = -1;
        try {/*from  w w w  .ja  va2  s.  co m*/
            Cursor cursor = dbHelper.getReadableDatabase()
                    .rawQuery("SELECT COUNT(*) FROM " + EVENTS_TABLE + where(), null);
            cursor.moveToFirst();
            count = cursor.getInt(0);
            cursor.close();
        } catch (SQLiteException e) {
            Log.e(LOGTAG, "getNumEvents", e);
        } finally {
            dbHelper.close();
        }
        return count;
    }
}

From source file:com.zoterodroid.activity.BrowseCitations.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse_bookmarks);

    mAccountManager = AccountManager.get(this);
    mAccount = mAccountManager.getAccountsByType(Constants.ACCOUNT_TYPE)[0];
    mContext = this;

    Log.d("browse bookmarks", getIntent().getDataString());
    Uri data = getIntent().getData();/*from   w w w.  j a  v a2 s .  com*/
    String scheme = data.getScheme();
    String path = data.getPath();
    Log.d("path", path);
    String username = data.getQueryParameter("username");
    String tagname = data.getQueryParameter("tagname");
    String recent = data.getQueryParameter("recent");

    myself = mAccount.name.equals(username);

    ArrayList<Citation> citationList = new ArrayList<Citation>();

    if (scheme.equals("content") && path.equals("/citations") && myself) {

        try {

            String[] projection = new String[] { Citation._ID, Citation.Title, Citation.Key,
                    Citation.Creator_Summary, Citation.Item_Type };
            String selection = null;
            String sortorder = null;

            selection = Citation.Account + " = '" + username + "'";

            Uri citations = Citation.CONTENT_URI;

            Cursor c = managedQuery(citations, projection, selection, null, sortorder);

            if (c.moveToFirst()) {
                int idColumn = c.getColumnIndex(Citation._ID);
                int titleColumn = c.getColumnIndex(Citation.Title);
                int keyColumn = c.getColumnIndex(Citation.Key);
                int creatorSummaryColumn = c.getColumnIndex(Citation.Creator_Summary);
                int itemTypeColumn = c.getColumnIndex(Citation.Item_Type);

                do {

                    Citation b = new Citation(c.getInt(idColumn), c.getString(titleColumn),
                            c.getString(keyColumn), c.getString(creatorSummaryColumn),
                            c.getString(itemTypeColumn));

                    citationList.add(b);

                } while (c.moveToNext());

            }

            setListAdapter(new CitationListAdapter(this, R.layout.bookmark_view, citationList));
        } catch (Exception e) {
        }

    }

    lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        }
    });

    /* Add Context-Menu listener to the ListView. */
    lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            menu.setHeaderTitle("Actions");
            if (myself) {
                menu.add(Menu.NONE, 0, Menu.NONE, "Delete");
            } else {
                menu.add(Menu.NONE, 1, Menu.NONE, "Add");
            }

        }
    });
}

From source file:it.ms.theing.loquitur.functions.Storage.java

/**
 * Get a list of keys and related values
 * @param genre/*  ww  w . ja v a 2s  . c  o m*/
 * The genre of the key
 * @return
 * a string conaining a json array of json objects structure :
 * [ { key:<name>, value:<value>} , ... ]
 */

@JavascriptInterface
public String getList(String genre) {
    Cursor cursor = dataBase.rawQuery("select * from alias where genre=?",
            new String[] { genre.toUpperCase() });
    cursor.moveToFirst();
    JSONArray ja = new JSONArray();
    while (!cursor.isAfterLast()) {
        JSONObject jo = new JSONObject();
        try {
            jo.put("key", cursor.getString(1));
            jo.put("value", cursor.getString(2));
        } catch (JSONException e) {
        }
        ja.put(jo);
        cursor.moveToNext();
    }
    return ja.toString();
}

From source file:com.mp3tunes.android.player.RemoteAlbumArtHandler.java

private String getArtworkFromStore(Track t) {
    Uri uri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
    String[] projection = new String[] { MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART };
    Log.w("Mp3Tunes",
            "Artist: " + t.getArtistName() + " Album: " + t.getAlbumTitle() + " Title: " + t.getTitle());

    String where = MediaStore.Audio.Media.ALBUM + "=?";
    String[] args = new String[] { t.getAlbumTitle() };
    Log.w("Mp3tunes", "Album: " + t.getAlbumTitle());
    Cursor cursor = mContext.getContentResolver().query(uri, projection, where, args, null);
    if (cursor.moveToFirst()) {
        String url = cursor.getString(1);
        Log.w("Mp3tunes", "url: " + url);
        return cursor.getString(1);
    }/*  www  .  j  a v a 2 s .c om*/
    Log.w("Mp3tunes", "Returning null for local album art");
    return null;
}

From source file:com.samknows.measurement.storage.TestResultDataSource.java

public List<AggregateTestResult> getAverageResults(long starttime, long endtime) {
    List<AggregateTestResult> ret = new ArrayList<AggregateTestResult>();
    String selection = String.format("dtime BETWEEN %d AND %d AND success <> 0", starttime, endtime);
    String averageColumn = String.format("AVG(%s)", SKSQLiteHelper.TR_COLUMN_RESULT);

    String[] columns = { SKSQLiteHelper.TR_COLUMN_TYPE, averageColumn, "COUNT(*)" };
    String groupBy = SKSQLiteHelper.TR_COLUMN_TYPE;
    Cursor cursor = database.query(SKSQLiteHelper.TABLE_TESTRESULT, columns, selection, null, groupBy, null,
            null);//  w  w w . j  a  v a  2s .c  o  m
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        AggregateTestResult curr = new AggregateTestResult();
        curr.testType = cursor.getString(0);
        curr.aggregateFunction = "average";
        curr.value = cursor.getDouble(1);
        curr.numberOfResults = cursor.getInt(2);
        ret.add(curr);
    }
    cursor.close();
    return ret;
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java

public ArrayList<TrafficData> getAllTrafficFromDate(String date, int typeID) {
    ArrayList<TrafficData> list = new ArrayList<TrafficData>();
    String q = "SELECT * FROM " + LocalTransformationDB.TABLE_TRAFFIC_MON
    // + ";";//  ww w  . j  a v a  2s .  c  o  m
            + " where( " + LocalTransformationDB.COLUMN_DATE_TEXT + " like '" + date + "%' AND "
            + LocalTransformationDB.COLUMN_TYPE + " = " + typeID + ")" + " ORDER BY "
            + LocalTransformationDB.COLUMN_ID + ";";
    Cursor cursor = database.rawQuery(q, null);
    if (cursor.moveToFirst()) {
        do {
            TrafficData trafficData = new TrafficData(
                    cursor.getString(cursor.getColumnIndex(LocalTransformationDB.COLUMN_DATE_TEXT)),
                    cursor.getInt(cursor.getColumnIndex(LocalTransformationDB.COLUMN_TYPE)),
                    cursor.getDouble(cursor.getColumnIndex(LocalTransformationDB.COLUMN_X_AXIS)),
                    cursor.getDouble(cursor.getColumnIndex(LocalTransformationDB.COLUMN_Y_AXIS)));
            list.add(trafficData);
        } while (cursor.moveToNext());
    }
    cursor.close();
    return list;
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java

public JSONArray getAlljsonData() {
    JSONArray jArray = new JSONArray();
    String q = "SELECT * FROM " + LocalTransformationDB.TABLE_JSON_DATA_EXCHANGE + " ORDER BY "
            + LocalTransformationDB.COLUMN_JSON_ID + ";";
    Cursor cursor = database.rawQuery(q, null);
    if (cursor.moveToFirst()) {
        do {//from  ww w.  j  ava2s.co  m
            String contents = cursor.getString(cursor.getColumnIndex(LocalTransformationDB.COUMN_JSON_CONTENT));
            int id = cursor.getInt(cursor.getColumnIndex(LocalTransformationDB.COLUMN_JSON_ID));
            try {
                JSONObject jObj = new JSONObject(contents);
                jObj.put(JSONDataExchange.JSON_CONTENT_ID, id);
                jArray.put(jObj);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    return jArray;
}

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 ww  .  java 2  s. c om*/
        return true;
}

From source file:it.ms.theing.loquitur.functions.Storage.java

/**
 * Get a key value/*from  w  w w.j ava2 s.  c om*/
 * @param genre
 * The genre of the key
 * @param key
 * The key
 * @return
 * The key value
 */
@JavascriptInterface
public String getKey(String genre, String key) {
    Cursor cursor = dataBase.rawQuery("select * from alias where genre=? and key=?",
            new String[] { genre.toUpperCase(), key });
    cursor.moveToFirst();
    if (cursor.isAfterLast()) {
        return "";
    }
    String s = cursor.getString(2);
    cursor.close();
    return s;
}