SQLiteOpenHelper getWritableDatabase - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:close, getWritableDatabase
     * @param helper 
     * @return writable database or null if it failed to create/open 
     */ 
    protected SQLiteDatabase getWritable(SQLiteOpenHelper helper) {
        try { 
            return helper.getWritableDatabase();
        } catch (SQLiteException e1) {
            // Make second attempt 
            try { 
                return helper.getWritableDatabase();
            } catch (SQLiteException e2) {
                return null; 
            } 
        } 
    } 
 
    /** 
     * Get readable database 
     * 
     * @param helper 

8
CodeRank
This code example shows how to use the following methods:getReadableDatabase, getWritableDatabase
This code example shows how to use the following methods:getWritableDatabase
    this.context        = context.getApplicationContext();
    this.databaseHelper = databaseHelper;
  } 
 
  public void setVerified(String number, byte[] zid) {
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    String encodedNumber    = PhoneNumberFormatter.formatNumber(context, number);
    String encodedZid       = Base64.encodeBytes(zid);
 
    ContentValues values = new ContentValues();
    values.put(VERIFIED, 1);
 
    database.update(TABLE_NAME, values, NUMBER + " = ? AND " + ZID + " = ?",
                    new String[] {encodedNumber, encodedZid});
  } 
 
  public boolean isVerified(String number, byte[] zid) {
    SQLiteDatabase database = databaseHelper.getReadableDatabase();
    String encodedZid       = Base64.encodeBytes(zid);
    String encodedNumber    = PhoneNumberFormatter.formatNumber(context, number);
7
CodeRank
This code example shows how to use the following methods:getReadableDatabase, getWritableDatabase
This code example shows how to use the following methods:getWritableDatabase
      SQLiteOpenHelper db=(SQLiteOpenHelper)params[0];
      String table=(String)params[1];
      String nullColumnHack=(String)params[2];
      ContentValues values=(ContentValues)params[3];
 
      db.getWritableDatabase().insert(table, nullColumnHack, values);
 
      return(null); 
    } 
  } 
 
  private class UpdateTask extends 
      ContentChangingTask<Object, Void, Void> {
    UpdateTask(SQLiteCursorLoader loader) {
      super(loader);
    } 
 
    @Override 
    protected Void doInBackground(Object... params) {
      SQLiteOpenHelper db=(SQLiteOpenHelper)params[0];
7
CodeRank
This code example shows how to use the following methods:getReadableDatabase, getWritableDatabase
	} 
 
	public MyNoteDBAdapter open() throws SQLException { 
		try { 
			Log.d(TAG, "about to getWritableDatabase");
			db = dbHelper.getWritableDatabase();
		} catch (SQLiteException ex) {
			Log.d(TAG, "about to getReadableDatabase");
			db = dbHelper.getReadableDatabase();
		} 
		return this;
	} 
 
	public void close() { 
		db.close();
	} 
 
	public MyNoteDto insertMyNote(MyNoteDto mynote) {
		// Create a new row of values to insert. 
		Log.d(TAG, "about to insertMyNote: " + mynote.getKey());
6
CodeRank
This code example shows how to use the following methods:getWritableDatabase
        SQLiteDatabase db = null;
 
        try { 
            String newSelection = buildSelection(uri, selection);
 
            db = mDatabaseHelper.getWritableDatabase();
            db.beginTransaction();
            final int count = db.delete("tests", newSelection, selectionArgs);
            db.setTransactionSuccessful();
            return count;
        } finally { 
            if (db != null) {
                db.endTransaction();
            } 
        } 
    } 
 
    @Override 
    public String getType(Uri uri) {
        switch (URI_MATCHER.match(uri)) {
6
CodeRank
This code example shows how to use the following methods:getWritableDatabase
		} 
		if (connection == null) {
			SQLiteDatabase db;
			if (sqliteDatabase == null) {
				try { 
					db = helper.getWritableDatabase();
				} catch (android.database.SQLException e) {
					throw SqlExceptionUtil.create("Getting a writable database from helper " + helper + " failed", e);
				} 
			} else { 
				db = sqliteDatabase;
			} 
			connection = new AndroidDatabaseConnection(db, true);
			logger.trace("created connection {} for db {}, helper {}", connection, db, helper);
		} else { 
			logger.trace("{}: returning read-write connection {}, helper {}", this, connection, helper);
		} 
		return connection;
	} 
 
6
CodeRank
This code example shows how to use the following methods:getWritableDatabase
This code example shows how to use the following methods:getWritableDatabase

Related SQLiteOpenHelper getWritableDatabase Questions & Answers:

Other SQLiteOpenHelper getWritableDatabase Examples

57:		 * */
58:		public void addSite(WebSite site) {
59:			SQLiteDatabase db = this.getWritableDatabase();
60:	
61:			ContentValues values = new ContentValues();
-
113:		 * */
114:		public int updateSite(WebSite site) {
115:			SQLiteDatabase db = this.getWritableDatabase();
116:	
117:			ContentValues values = new ContentValues();
-
158:		 * */
159:		public void deleteSite(WebSite site) {
160:			SQLiteDatabase db = this.getWritableDatabase();
161:			db.delete(TABLE_RSS, KEY_ID + " = ?",
162:					new String[] { String.valueOf(site.getId())});

Read More

55:		// Adding new contact
56:		void addContact(Contact contact) {
57:			SQLiteDatabase db = this.getWritableDatabase();
58:	
59:			ContentValues values = new ContentValues();
-
88:			String selectQuery = "SELECT  * FROM " + TABLE_CONTACTS;
89:	
90:			SQLiteDatabase db = this.getWritableDatabase();
91:			Cursor cursor = db.rawQuery(selectQuery, null);
92:	
-
109:		// Updating single contact
110:		public int updateContact(Contact contact) {
111:			SQLiteDatabase db = this.getWritableDatabase();
112:	
113:			ContentValues values = new ContentValues();
-
122:		// Deleting single contact
123:		public void deleteContact(Contact contact) {
124:			SQLiteDatabase db = this.getWritableDatabase();
125:			db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
126:					new String[] { String.valueOf(contact.getID()) });

Read More

57:		 * */
58:		public void addUser(String name, String email, String uid, String created_at) {
59:			SQLiteDatabase db = this.getWritableDatabase();
60:	
61:			ContentValues values = new ContentValues();
-
114:		 * */
115:		public void resetTables(){
116:			SQLiteDatabase db = this.getWritableDatabase();
117:			// Delete All Rows
118:			db.delete(TABLE_LOGIN, null, null);

Read More

getWritableDatabase Method Overview
Create and/or open a database that will be used for reading and writing.
See Code Examples for other Android SQLiteOpenHelper Methods: