Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reopen database with same name after database file deleted #25

Open
sjdrew opened this issue Feb 9, 2017 · 1 comment
Open

Comments

@sjdrew
Copy link

sjdrew commented Feb 9, 2017

My app has need to remove database files to free up space when no longer needed. (As db.destroy() does not free any space). It might be that this database is never needed again so removing the file is the best method for my app. However if I try to reopen a database with the same name PouchDB fails with

"WebSQL threw an error – Error: database not open — SQLitePlugin.js:25"

Seems like pouchdb may keep some reference to the file after being opened once?

(I could live with using Vacuum as that is supposed to truncate the file. But I can find no example of how you could actually run that command under cordova-sql-lite)

Below is a sample script that reproduce the problem.

cordova-sqlite-storage 2.0.1
"pouchdb": "6.1.2",
"pouchdb-adapter-cordova-sqlite": "2.0.2",

This is with IOS 10,

var options = {
            adapter: 'cordova-sqlite', 
            iosDatabaseLocation: 'Documents',
        };
        var name = 'TESTDB';
        var db = new PouchDB(name, options); 
        setTimeout(function() {
            console.log("Now closing",db);
            db.close(function() {
                db.destroy(function() {
                    setTimeout(function() {
                        console.log("now delete file ");
                        SQLite.deleteDatabase({name:name,iosDatabaseLocation: 'Documents'}).then( () => {
                            console.log("database file delete");
                            setTimeout(function() {
                                console.log("now reopen");
                                var db2 = new PouchDB(name,options);
                                console.log(db2);
                            },1000);
                        });
                    },1000);
                });
            })
        },2000);

Thanks in advance for any help.
Steve.

@eoussama
Copy link

bump, anything new related to this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants