Android SQLiteCursor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SQLiteCursor class.

This code example shows how to use the following methods:getColumnIndexOrThrow
 
    @Test(expected = IllegalArgumentException.class) 
    public void testGetColumnIndexOrThrowNotFoundEmpty() throws Exception { 
        setupEmptyResult(); 
 
        cursor.getColumnIndexOrThrow("Fred");
    } 
 
    @Test 
    public void testMoveToFirst() throws Exception { 
        assertThat(cursor.moveToFirst(), equalTo(true));
        assertThat(cursor.getInt(0), equalTo(1234));
        assertThat(cursor.getString(1), equalTo("Chuck"));
    } 
 
    @Test 
    public void testMoveToFirstEmpty() throws Exception { 
        setupEmptyResult(); 
 
        assertThat(cursor.moveToFirst(), equalTo(false));

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:moveToFirst, getString, close, getColumnIndex
            db = this.openOrCreateDatabase("/data/data/info.hagedev.itscool/databases/timetable", SQLiteDatabase.OPEN_READWRITE, null);
         } 
 
        q = "SELECT TimetableURL FROM Routes WHERE Departure = '"+dept+"' AND Arrival ='"+arvl+"';";
        cursor = (SQLiteCursor)db.rawQuery(q, null);
        if(cursor.moveToFirst()){
        		url = cursor.getString(cursor.getColumnIndex("TimetableURL"));
        } 
        db.close();
        cursor.close();
 
        Log.d("query",q);
        Log.d("departure",dept);
        Log.d("arrival", arvl);
        Log.d("url", url);
 
 
        intent.putExtra("departure", dept);
        intent.putExtra("arrival", arvl);
        intent.putExtra("url", url);
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
        if(debugEnabled){
            Log.d("SQL Log", sqLiteQuery.toString());
        } 
 
        return new SQLiteCursor(sqLiteDatabase, sqLiteCursorDriver, editTable, sqLiteQuery);
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:moveToFirst, getDouble
	} 
	 
	public Double[] getLatLngForId(long id) {
		SQLiteDatabase db = this.getReadableDatabase();
		SQLiteCursor c = (SQLiteCursor) db.rawQuery("SELECT lat,lng FROM locations WHERE "+BaseColumns._ID+"="+Long.toString(id), null);
		c.moveToFirst();
		Double[] r = { c.getDouble(0), c.getDouble(1) };
		return r;		
	} 
	 
	public void deleteId(long id) {
		SQLiteDatabase db = this.getWritableDatabase();
		db.delete(LOCATIONS_TABLE_NAME, BaseColumns._ID+"="+Long.toString(id),null);	
	} 
} 
	 
 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getLong, getString
 
    @Override 
    public boolean onContextItemSelected(MenuItem item) {
    	AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        SQLiteCursor  cursor = (SQLiteCursor) getListView().getItemAtPosition(info.position);
        startManagingCursor(cursor);
        final Long suraID = cursor.getLong(1);
        final Long verseID = cursor.getLong(2);
        String verseText = cursor.getString(3);
 
        switch(item.getItemId()) {
            case COPY_ID:
            	clipboard.setText("'"+verseText+"' Al-Quran ("+suraID+":"+verseID+") (Quran360 for Android)");
                Toast.makeText(getApplicationContext(), clipboard.getText().toString(), Toast.LENGTH_SHORT).show();
               return true; 
            case CHECKPOINT_ID:
            	myDBHelper.editReadPoint(suraID, verseID, verseText);
                return true;                                 
            case BOOKMARK_ID:
            	myDBHelper.addBookmark("("+suraID+":"+verseID+")", suraID, verseID, (verseID-1), verseText);
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getString, isBlob, isFloat, isLong, isString
		 
		return result;
	} 
 
	private Object getValue(SQLiteCursor c, int index) {
		if (c.isBlob(index)){
			return c.getBlob(index);
		} 
		if (c.isFloat(index)){
			return c.getFloat(index);
		} 
		 
		if (c.isLong(index)){
			return c.getLong(index);
		} 
		 
		if (c.isString(index)){
			return c.getString(index);
		} 
		 

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getColumnIndexOrThrow, moveToFirst, getLong, close
    } 
 
    public long getLastSmsTS() { 
        SQLiteCursor cursor = (SQLiteCursor) liteDatabase.query(TABLE_SMS_RECEIVED, new String[] {TABLE_COL_TS}, null, null, null, null, null);
        try{ 
	        if(cursor!=null && cursor.moveToFirst())
	        	return cursor.getLong(cursor.getColumnIndexOrThrow(SpeedCopDbAdapter.TABLE_COL_TS));
	        else 
	        	return 0; 
        }finally{ 
        	cursor.close();
        } 
    } 
     
    /** 
     * returns wifi bssid  list or just empty list. 
     */ 
    public synchronized List<String> getLastWifiScanResult(){
        SQLiteCursor cursor = (SQLiteCursor) liteDatabase.query(TABLE_WIFI_SCAN, new String[] {WS_COL_BSSID}, null, null, null, null, null);
        List<String> rtnList = new ArrayList<String>(); 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getColumnIndexOrThrow
 
    @Test(expected = IllegalArgumentException.class) 
    public void testGetColumnIndexOrThrowNotFoundEmpty() throws Exception { 
        setupEmptyResult(); 
 
        cursor.getColumnIndexOrThrow("Fred");
    } 
 
    @Test 
    public void testMoveToFirst() throws Exception { 
        assertThat(cursor.moveToFirst(), equalTo(true));
        assertThat(cursor.getInt(0), equalTo(1234));
        assertThat(cursor.getString(1), equalTo("Chuck"));
    } 
 
    @Test 
    public void testMoveToFirstEmpty() throws Exception { 
        setupEmptyResult(); 
 
        assertThat(cursor.moveToFirst(), equalTo(false));

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getColumnIndexOrThrow
 
    @Test(expected = IllegalArgumentException.class) 
    public void testGetColumnIndexOrThrowNotFoundEmpty() throws Exception { 
        setupEmptyResult(); 
 
        cursor.getColumnIndexOrThrow("Fred");
    } 
 
    @Test 
    public void testMoveToFirst() throws Exception { 
        assertThat(cursor.moveToFirst(), equalTo(true));
        assertThat(cursor.getInt(0), equalTo(1234));
        assertThat(cursor.getString(1), equalTo("Chuck"));
    } 
 
    @Test 
    public void testMoveToFirstEmpty() throws Exception { 
        setupEmptyResult(); 
 
        assertThat(cursor.moveToFirst(), equalTo(false));

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
    private static final CursorFactory sCursorFactory = new CursorFactory() {
        @Override 
        public Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver masterQuery, String editTable, SQLiteQuery query) { 
            Log.d(TAG, query.toString()); 
            return new SQLiteCursor(db, masterQuery, editTable, query); 
        } 
    }; 
 
    interface Tables { 
        String FILES = "files";
    } 
 
    public FilesDatabase(Context context) {
        super(context, DATABASE_NAME, BuildConfig.DEBUG ? sCursorFactory : null, DATABASE_VERSION);
    } 
 
    @Override 
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + Tables.FILES + " ("
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android SQLiteCursor Questions & Answers:

See Code Examples for Android SQLiteCursor Methods: