Java Code Examples for android.database.sqlite.SQLiteDatabase#deleteDatabase()

The following examples show how to use android.database.sqlite.SQLiteDatabase#deleteDatabase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CachingTests.java    From PhilHackerNews with MIT License 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {
    super.tearDown();
    toggleAirplaneMode();
    //TODO Figure out how to isolate tests from one another. Currently, the next test seems to start before this method completes, causing a No Such Table exception.
    SQLiteDatabase.deleteDatabase(mHackerNewsDatabaseFile);
}
 
Example 2
Source File: LauncherProvider.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
public void deleteDatabase() {
    // Are you sure? (y/n)
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final File dbFile = new File(db.getPath());
    mOpenHelper.close();
    if (dbFile.exists()) {
        SQLiteDatabase.deleteDatabase(dbFile);
    }
    mOpenHelper = new DatabaseHelper(getContext());
}
 
Example 3
Source File: LauncherProvider.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
public void deleteDatabase() {
    // Are you sure? (y/n)
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final File dbFile = new File(db.getPath());
    mOpenHelper.close();
    if (dbFile.exists()) {
        SQLiteDatabase.deleteDatabase(dbFile);
    }
    mOpenHelper = new DatabaseHelper(getContext());
    mOpenHelper.mListener = mListener;
}
 
Example 4
Source File: SplashActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
private void checkUserDatabase() {
    File oldUserDatabase = getDatabasePath(UserDataDBHelper.DATABASE_NAME);
    File newUserDatabasePath = new File(UserDataDBHelper.getDatabasePath(this));
    if (oldUserDatabase.exists() && !newUserDatabasePath.exists()) {
        try {
            StorageUtils.copyFile(oldUserDatabase, newUserDatabasePath);
            SQLiteDatabase.deleteDatabase(oldUserDatabase);
        } catch (IOException e) {
            Timber.e(e);
        }
    } else if (oldUserDatabase.exists() && newUserDatabasePath.exists()) {
        SQLiteDatabase.deleteDatabase(oldUserDatabase);
    }
}
 
Example 5
Source File: ContextImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteDatabase(String name) {
    try {
        File f = getDatabasePath(name);
        return SQLiteDatabase.deleteDatabase(f);
    } catch (Exception e) {
    }
    return false;
}
 
Example 6
Source File: AccountsDb.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@code CeDatabaseHelper}. If pre-N db file is present at the old location,
 * it also performs migration to the new CE database.
 */
static CeDatabaseHelper create(
        Context context,
        File preNDatabaseFile,
        File ceDatabaseFile) {
    boolean newDbExists = ceDatabaseFile.exists();
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "CeDatabaseHelper.create ceDatabaseFile=" + ceDatabaseFile
                + " oldDbExists=" + preNDatabaseFile.exists()
                + " newDbExists=" + newDbExists);
    }
    boolean removeOldDb = false;
    if (!newDbExists && preNDatabaseFile.exists()) {
        removeOldDb = migratePreNDbToCe(preNDatabaseFile, ceDatabaseFile);
    }
    // Try to open and upgrade if necessary
    CeDatabaseHelper ceHelper = new CeDatabaseHelper(context, ceDatabaseFile.getPath());
    ceHelper.getWritableDatabase();
    ceHelper.close();
    if (removeOldDb) {
        Slog.i(TAG, "Migration complete - removing pre-N db " + preNDatabaseFile);
        if (!SQLiteDatabase.deleteDatabase(preNDatabaseFile)) {
            Slog.e(TAG, "Cannot remove pre-N db " + preNDatabaseFile);
        }
    }
    return ceHelper;
}
 
Example 7
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteDatabase(String name) {
    try {
        File f = getDatabasePath(name);
        return SQLiteDatabase.deleteDatabase(f);
    } catch (Exception e) {
    }
    return false;
}
 
Example 8
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteDatabase(String name) {
    try {
        File f = validateFilePath(name, false);
        return SQLiteDatabase.deleteDatabase(f);
    } catch (Exception e) {
    }
    return false;
}
 
Example 9
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteDatabase(String name) {
    try {
        File f = validateFilePath(name, false);
        return SQLiteDatabase.deleteDatabase(f);
    } catch (Exception e) {
    }
    return false;
}
 
Example 10
Source File: LauncherProvider.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
public void deleteDatabase() {
    // Are you sure? (y/n)
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final File dbFile = new File(db.getPath());
    mOpenHelper.close();
    if (dbFile.exists()) {
        SQLiteDatabase.deleteDatabase(dbFile);
    }
    mOpenHelper = new DatabaseHelper(getContext());
}
 
Example 11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteDatabase(String name) {
    try {
        File f = validateFilePath(name, false);
        return SQLiteDatabase.deleteDatabase(f);
    } catch (Exception e) {
    }
    return false;
}
 
Example 12
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteDatabase(String name) {
    try {
        File f = getDatabasePath(name);
        return SQLiteDatabase.deleteDatabase(f);
    } catch (Exception e) {
    }
    return false;
}
 
Example 13
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteDatabase(String name) {
    try {
        File f = validateFilePath(name, false);
        return SQLiteDatabase.deleteDatabase(f);
    } catch (Exception e) {
    }
    return false;
}
 
Example 14
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteDatabase(String name) {
    try {
        File f = validateFilePath(name, false);
        return SQLiteDatabase.deleteDatabase(f);
    } catch (Exception e) {
    }
    return false;
}
 
Example 15
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteDatabase(String name) {
    try {
        File f = getDatabasePath(name);
        return SQLiteDatabase.deleteDatabase(f);
    } catch (Exception e) {
    }
    return false;
}
 
Example 16
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteDatabase(String name) {
    try {
        File f = getDatabasePath(name);
        return SQLiteDatabase.deleteDatabase(f);
    } catch (Exception e) {
    }
    return false;
}
 
Example 17
Source File: AbstractDataSource.java    From kripton with Apache License 2.0 5 votes vote down vote up
private void deleteDatabaseFile(String fileName) {
	if (fileName.equalsIgnoreCase(":memory:") || fileName.trim().length() == 0) {
		return;
	}
	if (this.logEnabled) {
		Logger.fatal("deleting the database file: " + fileName);
	}
	try {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
			SQLiteDatabase.deleteDatabase(new File(fileName));
		} else {
			try {
				final boolean deleted = new File(fileName).delete();
				if (!deleted) {
					if (this.logEnabled) {
						Logger.fatal("Could not delete the database file " + fileName);
					}
				}
			} catch (Exception error) {
				if (this.logEnabled) {
					Logger.fatal("error while deleting corrupted database file " + error.getMessage());
				}
			}
		}
	} catch (Exception e) {
		if (this.logEnabled) {
			/* print warning and ignore exception */
			Logger.warn("delete failed: ", e);
		}
	}
}
 
Example 18
Source File: DatabaseHelper.java    From Mizuu with Apache License 2.0 4 votes vote down vote up
private void moveFileSourcesDb(Context context, SQLiteDatabase database) {
	File dbFile = context.getDatabasePath("mizuu_sources");
	if (dbFile.exists()) {
		// The old database file exists! Let's create
		// a table for it in the new combined database
		database.execSQL(DATABASE_CREATE_FILESOURCES);

		String KEY_FILEPATH = "filepath";
		String KEY_TYPE = "type"; // movie / TV show
		String KEY_FILESOURCE_TYPE = "is_smb"; // local file / NAS / other sources... Used to be 0 = local file, 1 = smb.
		String KEY_USER = "user";
		String KEY_PASSWORD = "password";
		String KEY_DOMAIN = "domain";

		String[] SELECT_ALL = new String[]{KEY_FILEPATH, KEY_TYPE, KEY_FILESOURCE_TYPE, KEY_USER, KEY_PASSWORD, KEY_DOMAIN};

		SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
		Cursor c = db.query("sources", SELECT_ALL, null, null, null, null, null);

		try {
			while (c.moveToNext()) {
				ContentValues cv = new ContentValues();
				cv.put(KEY_FILEPATH, c.getString(c.getColumnIndex(KEY_FILEPATH)));
				cv.put(KEY_TYPE, c.getString(c.getColumnIndex(KEY_TYPE)));
				cv.put(KEY_FILESOURCE_TYPE, c.getInt(c.getColumnIndex(KEY_FILESOURCE_TYPE)));
				cv.put(KEY_USER, c.getString(c.getColumnIndex(KEY_USER)));
				cv.put(KEY_PASSWORD, c.getString(c.getColumnIndex(KEY_PASSWORD)));
				cv.put(KEY_DOMAIN, c.getString(c.getColumnIndex(KEY_DOMAIN)));

				database.insert("sources", null, cv);
			}
		} catch (Exception e) {} finally {
			c.close();
			db.close();

			if (MizLib.hasJellyBean())
				SQLiteDatabase.deleteDatabase(dbFile);
			else					
				dbFile.delete();
		}
	}
}
 
Example 19
Source File: AccountsDb.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
static void deleteDbFileWarnIfFailed(File dbFile) {
    if (!SQLiteDatabase.deleteDatabase(dbFile)) {
        Log.w(TAG, "Database at " + dbFile + " was not deleted successfully");
    }
}
 
Example 20
Source File: MainActivityTests.java    From PhilHackerNews with MIT License 4 votes vote down vote up
@After
public void unregisterIdlingResources() {
    Espresso.unregisterIdlingResources(mSyncAdapterIdlingResource);
    SQLiteDatabase.deleteDatabase(mHackerNewsDatabaseFile);
}