synchronized void ensureDatabase() { if (mDb != null && mDb.isOpen()) { return; } // Sometimes retrieving the database fails. We do 2 retries: first without database deletion // and then with deletion. for (int tries = 0; tries < 2; tries++) { try { if (tries > 0) { //delete db and recreate deleteDB(); } mDb = getWritableDatabase(); break; } catch (SQLiteException e) { e.printStackTrace(); } // Wait before retrying. try { Thread.sleep(SLEEP_TIME_MS); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } } if(mDb == null){ return; } createTableIfNotExists(mDb); mDb.setMaximumSize(mMaximumDatabaseSize); }
public SQLiteDatabase openDB(File file) { if (file == null || !file.exists()) { return null; } try { return SQLiteDatabase.openDatabase(file.getAbsolutePath(), null, SQLiteDatabase.OPEN_READWRITE); } catch (SQLiteException e) { e.printStackTrace(); return null; } }
@Override protected Void doInBackground(Void... voids) { try { shortcutList = AppUtils.getShortcuts(); } catch (SecurityException e) { e.printStackTrace(); } catch (SQLiteException e) { e.printStackTrace(); shortcutList = new ArrayList<ShortcutInfo>(); } return null; }
/** * 检查数据库是否存在 * @return */ public boolean checkDataBase() { SQLiteDatabase checkDB = null; String dbPath = DB_PATH + DB_NAME; try { checkDB = SQLiteDatabase.openDatabase(dbPath,null,SQLiteDatabase.OPEN_READONLY); } catch (SQLiteException e) { e.printStackTrace(); } finally { if (checkDB != null) { checkDB.close(); } } return checkDB!=null ? true : false; }
e.printStackTrace(); db.execSQL("create index 'related_idx_pword' on related (pword)"); }catch (SQLiteException e){ e.printStackTrace(); db.execSQL("create index 'related_idx_cword' on related (cword)"); }catch (SQLiteException e){ e.printStackTrace();
} catch (SQLiteException e) { Log.e("DeoxideDb", "SQLite error, maybe column already exists?"); e.printStackTrace(); } catch (SQLiteException e) { Log.e("DeoxideDb", "SQLite error, maybe column already exists?"); e.printStackTrace(); } catch (SQLiteException e) { Log.e("DeoxideDb", "SQLite error, maybe column already exists?"); e.printStackTrace(); } catch (SQLiteException e) { Log.e("DeoxideDb", "SQLite error, maybe column already exists?"); e.printStackTrace();
public boolean updateDownload(DownloadInfo di, ContentValues cv) { long id = di == null ? -1 : getIDForDownloadInfo(di); try { final SQLiteDatabase sqldb = mHelper.getWritableDatabase(); if (id != -1) { if (1 != sqldb.update(DownloadColumns.TABLE_NAME, cv, DownloadColumns._ID + " = " + id, null)) { return false; } } else { return -1 != sqldb.insert(DownloadColumns.TABLE_NAME, DownloadColumns.URI, cv); } } catch (android.database.sqlite.SQLiteException ex) { ex.printStackTrace(); } return false; }
public static boolean execute(Worker worker) { SQLiteDatabase db = Orm.getDatabase(); db.beginTransaction(); try { boolean isOk = worker.doTransition(db); if (isOk) { db.setTransactionSuccessful(); } return isOk; } catch(SQLiteException e) { e.printStackTrace(); } finally { db.endTransaction(); } return false; } }
/** * @see SQLiteDatabase#delete(String, String, String[]) */ public void delete(String whereClause, String[] whereArgs) { if (mIgnoreWrites) { return; } try { mOpenHelper.getWritableDatabase().delete(mTableName, whereClause, whereArgs); } catch (SQLiteFullException e) { onDiskFull(e); } catch (SQLiteException e) { e.printStackTrace(); } }
/** * Method used to add note text to EditText * * @param noteID ID number of the Note entry in the SQLite database */ private void loadNote(int noteID) { try { Note n = dbHandler.getNote(noteID); //todo fix editText.setText(n.getSpannable()); editText.setSelection(editText.getText().toString().length()); noteTitle.setText(n.getTitle()); drawingView.setBitmap(n.getImage()); }catch (SQLiteException e){ e.printStackTrace(); } }
}catch(SQLiteException e){ e.printStackTrace();
/** * @see SQLiteDatabase#insertWithOnConflict(String, String, ContentValues, int) */ public void insertOrReplace(ContentValues values) { if (mIgnoreWrites) { return; } try { mOpenHelper.getWritableDatabase().insertWithOnConflict( mTableName, null, values, SQLiteDatabase.CONFLICT_REPLACE); } catch (SQLiteFullException e) { onDiskFull(e); } catch (SQLiteException e) { e.printStackTrace(); } }
e.printStackTrace(); } finally { if (c != null) {
@Deprecated public void upgradeRelatedTable(SQLiteDatabase dbin) { try { String BACKUP_OLD_RELATED = "ALTER " + Lime.DB_RELATED + " RENAME TO " + Lime.DB_RELATED + "_old"; execSQL(dbin, BACKUP_OLD_RELATED); String CREATE_NEW_TABLE = ""; CREATE_NEW_TABLE += "CREATE TABLE \"" + Lime.DB_RELATED + "\" ( "; CREATE_NEW_TABLE += " \"" + Lime.DB_COLUMN_ID + "\" INTEGER PRIMARY KEY AUTOINCREMENT,"; CREATE_NEW_TABLE += " \"" + Lime.DB_RELATED_COLUMN_PWORD + "\" text,"; CREATE_NEW_TABLE += " \"" + Lime.DB_RELATED_COLUMN_CWORD + "\" text,"; CREATE_NEW_TABLE += " \"" + Lime.DB_RELATED_COLUMN_BASESCORE + "\" integer,"; CREATE_NEW_TABLE += " \"" + Lime.DB_RELATED_COLUMN_USERSCORE + "\" INTEGER DEFAULT 0"; CREATE_NEW_TABLE += ");"; execSQL(dbin, CREATE_NEW_TABLE); String CREATE_INDEX = ""; CREATE_INDEX += "CREATE INDEX \"" + Lime.DB_RELATED + "\".\"related_idx_pword\" "; CREATE_INDEX += "ON \"" + Lime.DB_RELATED + "\" (\"" + Lime.DB_RELATED_COLUMN_PWORD + "\" ASC); "; execSQL(dbin, CREATE_INDEX); String MIGRATE_DATA = ""; MIGRATE_DATA += "INSERT INTO " + Lime.DB_RELATED + "(" + Lime.DB_RELATED_COLUMN_PWORD + ", " + Lime.DB_RELATED_COLUMN_CWORD + ", " + Lime.DB_RELATED_COLUMN_BASESCORE + ")"; MIGRATE_DATA += "SELECT " + Lime.DB_RELATED_COLUMN_PWORD + ", " + Lime.DB_RELATED_COLUMN_CWORD + ", score FROM " + Lime.DB_RELATED + "_old"; execSQL(dbin, MIGRATE_DATA); String DROP_OLD_TABLE = "DROP TABLE " + Lime.DB_RELATED + "_old"; execSQL(dbin, DROP_OLD_TABLE); // Download and restore related DB } catch (SQLiteException e) { e.printStackTrace(); } }