Android SQLiteOpenHelper - 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 SQLiteOpenHelper class.

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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:onCreate, onOpen
 
    @Implementation 
    public synchronized SQLiteDatabase getReadableDatabase() {
        if (database == null) {
            database = SQLiteDatabase.openDatabase("path", null, 0);
            realHelper.onCreate(database);
        } 
 
        realHelper.onOpen(database);
        return database;
    } 
 
    @Implementation 
    public synchronized SQLiteDatabase getWritableDatabase() {
        if (database == null) {
            database = SQLiteDatabase.openDatabase("path", null, 0);
            realHelper.onCreate(database);
        } 
 
        realHelper.onOpen(database);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getReadableDatabase, getWritableDatabase
 
	private SQLiteDatabase getReadableDatabase()
	{ 
		SQLiteDatabase db;
		try { 
			db = historyDB.getReadableDatabase();			
		} 
		catch(SQLiteException e) {
			db = historyDB.getWritableDatabase();
		} 
		return db;		
	}	 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getReadableDatabase, getWritableDatabase
	 
	private SQLiteDatabase getReadableDatabase()
	{ 
		SQLiteDatabase db;
		try { 
			db = bookmarkDB.getReadableDatabase();			
		} 
		catch(SQLiteException e) {
			db = bookmarkDB.getWritableDatabase();
		} 
		return db;		
	} 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close
    } 
 
    @SuppressLint("NewApi") 
    @Override 
    public void shutdown() { 
        mDatabaseHelper.close();
 
        super.shutdown(); 
    } 
 
    public static class MyDatabaseHelper extends SQLiteOpenHelper {
        public static final int DATABASE_VERSION = 1;
        public static final String DATABASE_NAME = "tests.db";
        public static final String CREATE_TABLE_SQL = "CREATE TABLE tests(" + BaseColumns._ID +" INTEGER PRIMARY KEY NOT NULL, name TEXT NOT NULL)";
        public static final String DROP_TABLE_SQL = "DROP TABLE tests;";
 
        public MyDatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            Log.v(TAG, "construct");
        } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:onCreate, onOpen
 
    @Implementation 
    public synchronized SQLiteDatabase getReadableDatabase() {
        if (database == null) {
            database = SQLiteDatabase.openDatabase("path", null, 0);
            realHelper.onCreate(database);
        } 
 
        realHelper.onOpen(database);
        return database;
    } 
 
    @Implementation 
    public synchronized SQLiteDatabase getWritableDatabase() {
        if (database == null) {
            database = SQLiteDatabase.openDatabase("path", null, 0);
            realHelper.onCreate(database);
        } 
 
        realHelper.onOpen(database);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java

Related Android SQLiteOpenHelper Questions & Answers:

Other Android SQLiteOpenHelper Examples

0:	public class DatabaseHandler extends SQLiteOpenHelper {
1:	
2:		// All Static variables

Read More

0:	public class DatabaseHelper extends SQLiteOpenHelper {
1:	
2:		// Logcat tag

Read More

9:	import android.database.sqlite.SQLiteOpenHelper;
10:	
11:	public class DatabaseHandler extends SQLiteOpenHelper {
12:	    // Database Version
13:	    private static final int DATABASE_VERSION = 1;

Read More

See Code Examples for Android SQLiteOpenHelper Methods: