public static void addFlaggedCountColumn(SQLiteDatabase db) { try { db.execSQL("ALTER TABLE folders ADD flagged_count INTEGER default 0"); } catch (SQLiteException e) { if (!e.getMessage().startsWith("duplicate column name: flagged_count")) { throw e; } } } }
public static void addMessagesThreadingColumns(SQLiteDatabase db) { try { db.execSQL("ALTER TABLE messages ADD thread_root INTEGER"); db.execSQL("ALTER TABLE messages ADD thread_parent INTEGER"); db.execSQL("ALTER TABLE messages ADD normalized_subject_hash INTEGER"); db.execSQL("ALTER TABLE messages ADD empty INTEGER"); } catch (SQLiteException e) { if (!e.getMessage().startsWith("duplicate column name:")) { throw e; } } } }
public static void db41FoldersAddClassColumns(SQLiteDatabase db) { try { db.execSQL("ALTER TABLE folders ADD integrate INTEGER"); db.execSQL("ALTER TABLE folders ADD top_group INTEGER"); db.execSQL("ALTER TABLE folders ADD poll_class TEXT"); db.execSQL("ALTER TABLE folders ADD push_class TEXT"); db.execSQL("ALTER TABLE folders ADD display_class TEXT"); } catch (SQLiteException e) { if (!e.getMessage().startsWith("duplicate column name:")) { throw e; } } }
public static void changeThreadingIndexes(SQLiteDatabase db) { try { db.execSQL("DROP INDEX IF EXISTS msg_empty"); db.execSQL("CREATE INDEX IF NOT EXISTS msg_empty ON messages (empty)"); db.execSQL("DROP INDEX IF EXISTS msg_thread_root"); db.execSQL("CREATE INDEX IF NOT EXISTS msg_thread_root ON messages (thread_root)"); db.execSQL("DROP INDEX IF EXISTS msg_thread_parent"); db.execSQL("CREATE INDEX IF NOT EXISTS msg_thread_parent ON messages (thread_parent)"); } catch (SQLiteException e) { if (!e.getMessage().startsWith("duplicate column name:")) { throw e; } } } }
public static void foldersAddNotifyClassColumn(SQLiteDatabase db, MigrationsHelper migrationsHelper) { try { db.execSQL("ALTER TABLE folders ADD notify_class TEXT default '" + Folder.FolderClass.INHERITED.name() + "'"); } catch (SQLiteException e) { if (!e.getMessage().startsWith("duplicate column name:")) { throw e; } } ContentValues cv = new ContentValues(); cv.put("notify_class", Folder.FolderClass.FIRST_CLASS.name()); Account account = migrationsHelper.getAccount(); db.update("folders", cv, "name = ?", new String[] { account.getInboxFolder() }); } }
Log.d("SQLiteException", ex.getMessage());
@Test public void badDeleteThrows() { try { db.delete("missing", "1"); fail(); } catch (SQLiteException e) { assertThat(e.getMessage()).contains("no such table: missing"); } }
@Test public void badQueryThrows() { try { //noinspection CheckResult db.query("SELECT * FROM missing"); fail(); } catch (SQLiteException e) { assertThat(e.getMessage()).contains("no such table: missing"); } }
@Test public void badUpdateThrows() { try { db.update("missing", CONFLICT_NONE, employee("john", "John Johnson"), "1"); fail(); } catch (SQLiteException e) { assertThat(e.getMessage()).contains("no such table: missing"); } }
@Test public void badInsertThrows() { try { db.insert("missing", CONFLICT_NONE, employee("john", "John Johnson")); fail(); } catch (SQLiteException e) { assertThat(e.getMessage()).contains("no such table: missing"); } }
} catch (SQLiteException ex) { errorMessage = ex.getMessage(); FLog.e(SQLitePlugin.TAG, "SQLiteStatement.executeUpdateDelete() failed", ex); needRawQuery = false; errorMessage = ex.getMessage(); FLog.e(SQLitePlugin.TAG, "SQLiteDatabase.executeInsert() failed", ex); queryResult.putInt("rowsAffected", 0); } catch (SQLiteException ex) { errorMessage = ex.getMessage(); FLog.e(SQLitePlugin.TAG, "SQLiteDatabase.beginTransaction() failed", ex); queryResult.putInt("rowsAffected", 0); } catch (SQLiteException ex) { errorMessage = ex.getMessage(); FLog.e(SQLitePlugin.TAG, "SQLiteDatabase.setTransactionSuccessful/endTransaction() failed", ex); queryResult.putInt("rowsAffected", 0); } catch (SQLiteException ex) { errorMessage = ex.getMessage(); FLog.e(SQLitePlugin.TAG, "SQLiteDatabase.endTransaction() failed", ex);
} catch (SQLiteException ex) { errorMessage = ex.getMessage(); FLog.e(TAG, "SQLiteStatement.executeUpdateDelete() failed", ex); needRawQuery = false; errorMessage = ex.getMessage(); FLog.e(TAG, "SQLiteDatabase.executeInsert() failed", ex); } finally { queryResult.putInt("rowsAffected", 0); } catch (SQLiteException ex) { errorMessage = ex.getMessage(); FLog.e(TAG, "SQLiteDatabase.beginTransaction() failed", ex); queryResult.putInt("rowsAffected", 0); } catch (SQLiteException ex) { errorMessage = ex.getMessage(); FLog.e(TAG, "SQLiteDatabase.setTransactionSuccessful/endTransaction() failed", ex); queryResult.putInt("rowsAffected", 0); } catch (SQLiteException ex) { errorMessage = ex.getMessage(); FLog.e(TAG, "SQLiteDatabase.endTransaction() failed", ex);
try{ db.beginTransaction(); //Do whatever you need to do... db.setTransactionSuccessful(); }catch(SQLiteException e){ Log.e("SQLite","Error while updating rows: " + e.getMessage()); }finally{ db.endTransaction(); //Commit (if everything ok) or rollback (if any error occured). db.close(); //Close databse; }
try { //code } catch(SQLiteException ex) { Log.v("Insert into database exception caught", ex.getMessage()); return -1; } }
@Override public void onCreate(SQLiteDatabase db) { Log.v("MyDBhelper onCreate","Creating all the tables"); try { db.execSQL(CREATE_TABLE); for(int i=1; i <= 48; i++) { insertdiary("", ""); } } catch(SQLiteException ex) { Log.v("Create table exception", ex.getMessage()); } }
private SQLiteDatabase returnDatabase(){ try { SQLiteDatabase db = SQLiteDatabase.openDatabase(mDatabasePath + "/" + mName, mFactory, SQLiteDatabase.OPEN_READWRITE); Log.i(TAG, "successfully opened database " + mName); return db; } catch (SQLiteException e) { Log.w(TAG, "could not open database " + mName + " - " + e.getMessage()); return null; } }
private SQLiteDatabase returnDatabase(){ try { SQLiteDatabase db = SQLiteDatabase.openDatabase(mDatabasePath + "/" + mName, mFactory, SQLiteDatabase.OPEN_READWRITE); Log.i(TAG, "successfully opened database " + mName); return db; } catch (SQLiteException e) { Log.w(TAG, "could not open database " + mName + " - " + e.getMessage()); return null; } }
@Override public int deleteItemByCondition(Uri uri, String selection, String[] selectionArgs) { int count = 0; try{ SQLiteDatabase sqLiteDatabase=dbHelper.getReadableDatabase(); String tableName=uri.getPathSegments().get(0); count=sqLiteDatabase.delete(tableName,selection,selectionArgs); }catch (SQLiteException e){ new Exception(""+e.getMessage()); } return count; }
public class Executor { public static void runOperation(Operation operation) { SQLiteDatabase database = this.getWritableDatabase(); try { operation.run(database); } catch (SQLiteException e) { Log.e(operation.getClass().getName(), e.getMessage()); return false; } finally { database.close(); } }
protected Long persistCore(final ContentValues core, final SQLiteDatabase dbCon) { try { final Long id = dbCon.insertOrThrow(getTableName(), null, core); debug("inserted %s for ID %d", getTableName(), id); return id; } catch (SQLiteException e) { debug("%s updating existing row", e.getMessage()); return updateByCore(core, dbCon); } }