StackedQ
StackedQ

Reputation: 4139

delete whole couchbase lite db issue

I wanna delete my entire Couchbase lite DB, but for some reasons some records won't be deleted, I tried the following code:

try{ db.delete()} catch{...}

but it won't work, it seems like SQLite got some problems with old indexes, with something like:

revisionId has already existed...

any help would be appreciated.

Upvotes: 3

Views: 1578

Answers (2)

Swapnil Naukudkar
Swapnil Naukudkar

Reputation: 626

try this..

first stop replication and then delete DB

public void stopReplication() {
    if (mPull != null) {
        mPull.stop();
    }
    if (mPush != null) {
        mPush.stop();
    }
    Log.d(TAG, "stopReplication: success");
}

public boolean deleteAllDocuments() {
    try {
        mDatabase.close();
        mDatabase.delete();
        mDatabase = null;
        mManager = null;
        Log.d(TAG, "deleteAllDocuments: success");
        return true;
    } catch (CouchbaseLiteException e) {
        e.printStackTrace();
        Log.e(TAG, "deleteAllDocuments: Failed to close and delete database.");

    }
    catch (Exception e)
    {
        e.printStackTrace();
        Log.e(TAG, "deleteAllDocuments: Failed to close and delete database.");
    }
    return false;
}

happy coding... :)

Upvotes: 2

sonali.barge
sonali.barge

Reputation: 47

You should use following steps 1.Delete database 2.Close database manager 3.Assign database to null

code:-

try {
     myDatabase.delete();
     myDatabase.manager(close);
     myDatabase = null;
} catch (IOExcept`enter code here`ion e) {
     Log.e(TAG, "Cannot delete database", e);
     return;
}

Upvotes: 1

Related Questions