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

This code example shows how to use the following methods: execSQL
        super(context, NAME, null, VERSION);
    } 
 
    @Override 
    public void onCreate(final SQLiteDatabase db) {
        db.execSQL("CREATE TABLE orgs (id INTEGER PRIMARY KEY);");
        db.execSQL("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, avatarurl TEXT);");
        db.execSQL("CREATE TABLE repos (id INTEGER PRIMARY KEY, repoId INTEGER, orgId INTEGER, name TEXT, ownerId INTEGER, private INTEGER, fork INTEGER, description TEXT, forks INTEGER, watchers INTEGER, language TEXT, hasIssues INTEGER, mirrorUrl TEXT);");
    } 
 
    @Override 
    public void onUpgrade(final SQLiteDatabase db, final int oldVersion,
            final int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS orgs");
        db.execSQL("DROP TABLE IF EXISTS users");
        db.execSQL("DROP TABLE IF EXISTS repos");
        onCreate(db);
    } 
} 
Full Snippet Info
10
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: beginTransaction, endTransaction, setTransactionSuccessful
 
        final SQLiteDatabase db = getWritable(helper);
        if (db == null)
            return items;
 
        db.beginTransaction();
        try { 
            persistableResource.store(db, items);
            db.setTransactionSuccessful();
        } finally { 
            db.endTransaction();
        } 
        return items;
    } 
 
    private <E> List<E> loadFromDB(final SQLiteOpenHelper helper,
            final PersistableResource<E> persistableResource) {
        final SQLiteDatabase db = getReadable(helper);
        if (db == null)
            return null; 
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: close
 
    /** Closes database resource */ 
    @Override 
    public void close() { 
        if(syncDatabase != null)
            syncDatabase.close();
    } 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: beginTransaction, endTransaction, setTransactionSuccessful, update
    @Override 
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        SQLiteDatabase db = null;
        try { 
            db = mDatabaseHelper.getWritableDatabase();
            db.beginTransaction();
 
            String newSelection = buildSelection(uri, selection);
            int count = db.update("tests", values, newSelection, selectionArgs);
            db.setTransactionSuccessful();
            return count;
        } finally { 
            if (db != null) {
                db.endTransaction();
            } 
        } 
    } 
 
    private String buildSelection(Uri uri, String selection) {
        long id = 0;
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: execSQL, setVersion
            StringBuilder queryBuilder = new StringBuilder();
            queryBuilder.append(String.format("CREATE TABLE %s (", TABLE_NAME));
            TrackerEntry.buildCreationString(queryBuilder);
 
            queryBuilder.append(");");
            db.execSQL(queryBuilder.toString());
            db.setVersion(DB_VERSION);
        } 
 
        @Override 
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO: reimplement this when dB version changes 
            Log.w(LOG_TAG, "Upgrading database from version " + oldVersion
                            + " to " + newVersion
                            + ", which will destroy all old data"); 
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
            onCreate(db);
        } 
    } 
 
    private DatabaseHelper mOpenHelper;
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android SQLiteDatabase Questions & Answers:

Other Android SQLiteDatabase Examples

1:		public void closeDB() {
2:			SQLiteDatabase db = this.getReadableDatabase();
3:			if (db != null && db.isOpen())
4:				db.close();

Read More

2:		 */
3:		public void deleteToDo(long tado_id) {
4:			SQLiteDatabase db = this.getWritableDatabase();
5:			db.delete(TABLE_TODO, KEY_ID + " = ?",
6:					new String[] { String.valueOf(tado_id) });

Read More

1:		public void deleteContact(Contact contact) {
2:			SQLiteDatabase db = this.getWritableDatabase();
3:			db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
4:					new String[] { String.valueOf(contact.getID()) });

Read More

See Code Examples for Android SQLiteDatabase Methods: