SQLiteDatabase query - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SQLiteDatabase query method.

This code example shows how to use the following methods:close, delete, insert, query
		if(fileName != null)
			mActivity.deleteFile(fileName);
		//mActivity.openFileOutput(fileName, Context.MODE_PRIVATE).getFD(). 
 
		String[] whereArgs = {playlistName};
		db.delete(TABLE_PLAYLIST, "PlaylistName = ?", whereArgs);
 
		db.close();
	} 
 
	@Override 
	public ArrayList<String> getAvailablePlaylists() {
		ArrayList<String> playlists = new ArrayList<String>(); 
		SQLiteDatabase db = mActivity.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null);
 
		String[] columns = {"PlaylistName"};
		Cursor query = db.query(TABLE_PLAYLIST, columns, null, null, null, null, "PlaylistName ASC");
 
		if(query != null){
			query.moveToFirst();

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:execSQL, insert, query
			m_db = myCtx.openOrCreateDatabase(DATABASE_NAME, 0,null);
 
			// Check for the existence of the DBVERSION table 
			// If it doesn't exist than create the overall data, 
			// otherwise double check the version 
			Cursor c =
				m_db.query("sqlite_master", new String[] { "name" },
						"type='table' and name='"+TABLE_DBVERSION+"'", null, null, null, null);
			int numRows = c.getCount();
			if (numRows < 1)
			{ 
				CreateDatabase(m_db);
			} 
			else 
			{ 
				int version=0;
				Cursor vc = m_db.query(true, TABLE_DBVERSION, new String[] {"version"},
						null, null, null, null, null,null); 
				if(vc.getCount() > 0) {
				    vc.moveToLast();

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:delete, insert, query
    @Test 
    public void testDeleteAll() throws Exception { 
        addChuck(); 
        addJulie(); 
 
        int deleted = database.delete("table_name", "1", null);
        assertThat(deleted).isEqualTo(2);
 
        assertEmptyDatabase(); 
    } 
 
 
    @Test 
    public void testExecSQL() throws Exception { 
        Statement statement;
        ResultSet resultSet;
 
        database.execSQL("INSERT INTO table_name (id, name) VALUES(1234, 'Chuck');");
 
        statement = shadowOf(database).getConnection().createStatement();

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:query
        cv.put(KEY_BYTES, result.getBytes());
        mDb.insert(table, null, cv);
    } 
 
    public Cursor getAbstractResults(String table) throws SQLException {
        return mDb.query(false, table, new String[] {KEY_BYTES}, null, null, null, null,
                KEY_PATH + " ASC", null);
    } 
 
    public static AbstractResult getAbstractResult(Cursor cursor) {
        return AbstractResult.create(cursor.getBlob(cursor.getColumnIndex(KEY_BYTES)));
    } 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:query
    /** 
     * Returns a cursor that can be used to read all the rows and columns of 
     * the "purchased items" table. 
     */ 
    public Cursor queryAllPurchasedItems() {
        return mDb.query(PURCHASED_ITEMS_TABLE_NAME, PURCHASED_COLUMNS, null,
                null, null, null, null); 
    } 
 
    /** 
     * This is a standard helper class for constructing the database. 
     */ 
    private class DatabaseHelper extends SQLiteOpenHelper {
        public DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        } 
 
        @Override 
        public void onCreate(SQLiteDatabase db) {
            createPurchaseTable(db);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, query
   * @return Text of the status 
   */ 
  public String getStatusTextById(long id) {  // <11>
    SQLiteDatabase db = this.dbHelper.getReadableDatabase();
    try { 
      Cursor cursor = db.query(TABLE, DB_TEXT_COLUMNS, C_ID + "=" + id, null,
          null, null, null); 
      try { 
        return cursor.moveToNext() ? cursor.getString(0) : null;
      } finally { 
        cursor.close();
      } 
    } finally { 
      db.close();
    } 
  } 
 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:execSQL, insert, query
			m_db = myCtx.openOrCreateDatabase(DATABASE_NAME, 0,null);
 
			// Check for the existence of the DBVERSION table 
			// If it doesn't exist than create the overall data, 
			// otherwise double check the version 
			Cursor c =
				m_db.query("sqlite_master", new String[] { "name" },
						"type='table' and name='"+TABLE_DBVERSION+"'", null, null, null, null);
			int numRows = c.getCount();
			if (numRows < 1)
			{ 
				CreateDatabase(m_db);
			} 
			else 
			{ 
				int version=0;
				Cursor vc = m_db.query(true, TABLE_DBVERSION, new String[] {"version"},
						null, null, null, null, null,null); 
				if(vc.getCount() > 0) {
				    vc.moveToLast();

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:beginTransaction, endTransaction, query, setTransactionSuccessful
     * @return a copy of all the MetaData fields. 
     */ 
    public Fields getFields() { 
        Fields fields = new Fields();
        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        db.beginTransaction();
        try { 
            // If the fields have not been initialized from the database, 
            // then read the database. 
            if (!mInitialized) {
                readLocked(db);
            } 
            fields.timezone = mFields.timezone;
            fields.minInstance = mFields.minInstance;
            fields.maxInstance = mFields.maxInstance;
            db.setTransactionSuccessful();
        } finally { 
            db.endTransaction();
        } 
        return fields;

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isOpen, query
		schemaVersion = getSchemaVersion();
      mDatabasePath = path;
	} 
	 
	public boolean validDatabase(){ 
		return (mDatabase == null)? false : mDatabase.isOpen();
	} 
 
   public boolean reopenDatabase(){ 
      try { 
         mDatabase = SQLiteDatabase.openDatabase(mDatabasePath,
                 null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
         return (mDatabase != null);
      } 
      catch (Exception e){ return false; }
   } 
	 
	public Cursor getVerses(int sura, int minAyah, int maxAyah){
		return getVerses(sura, minAyah, maxAyah, VERSE_TABLE);
	} 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:delete, query
		String path = getString(cursor, RecordingColumn.RECORDING_PATH);
		cursor.close();
		if (new File(path).exists()) {
			Runtime.getRuntime().exec("rm " + path);
		} 
		db.delete(TABLE_RECORDINGS, recordingIdClause(id), null);
	} 
 
	public Cursor getAllScenes() {
		return db.query(TABLE_SCENES, null, null, null, null, null, SceneColumn.SCENE_TITLE.label);
	} 
	 
	public Cursor getAllRecordings() {
		return db.query(TABLE_RECORDINGS, null, null, null, null, null, RecordingColumn.RECORDING_TIMESTAMP.label);
	} 
	 
	public Cursor getScene(long id) {
		Cursor cursor = db.query(TABLE_SCENES, null, sceneIdClause(id), null, null, null, null);
		cursor.moveToFirst();
		return cursor;

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related SQLiteDatabase query Questions & Answers:

Other SQLiteDatabase query Examples

135:			SQLiteDatabase db = this.getReadableDatabase();
136:	
137:			Cursor cursor = db.query(TABLE_RSS, new String[] { KEY_ID, KEY_TITLE,
138:					KEY_LINK, KEY_RSS_LINK, KEY_DESCRIPTION }, KEY_ID + "=?",
139:					new String[] { String.valueOf(id) }, null, null, null, null);

Read More

70:			SQLiteDatabase db = this.getReadableDatabase();
71:	
72:			Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
73:					KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
74:					new String[] { String.valueOf(id) }, null, null, null, null);

Read More

2:			SQLiteDatabase db = this.getReadableDatabase();
3:	
4:			Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
5:					KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
6:					new String[] { String.valueOf(id) }, null, null, null, null);

Read More

query Method Overview
Query the given table, returning a Cursor over the result set.
See Code Examples for other Android SQLiteDatabase Methods: