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

Using database object in native code, with Swift #65

Open
jigyasu11 opened this issue Feb 8, 2019 · 1 comment
Open

Using database object in native code, with Swift #65

jigyasu11 opened this issue Feb 8, 2019 · 1 comment

Comments

@jigyasu11
Copy link

Hi there,

We are using sqlite-plugin to handle db operations in ionic app side. We have our own plugin that needs to interact with database as well. Its has been observed that sometimes we get 'db locked' errors. On root causing the issue, the obvious suspect was indeed the culprit! In our plugin, for every execution we open the db and when plugin exits close the db.

    init() {
        self.db = self.open()
    }
    
    deinit {
        if sqlite3_close(db) != SQLITE_OK {
            print("error while closing database")
        } else{
            print("successfully closed database")
        }

    }

Since our plugin gets executed multiple time in quick succession, results in multiple db objects live on the fly.
Hence I was wondering, if we can somehow re-use the same database object that sqlite-plugin uses. This will be a robust solution as well. Is it possible?
Thanks so much,
Richeek

@brody4hire brody4hire changed the title Using database object in native code Using database object in native code, with Swift Mar 28, 2019
@brody4hire
Copy link

Thanks for reporting this issue. It is clearly an issue with using the sqlite plugin together with a custom plugin written in Swift. I have seen this kind of an issue multiple times now.

The recommended solution is to completely remove any kind of existing sqlite plugin and use https://github.com/xpbrew/cordova-sqlite-express-build-support instead. It uses the builtin SQLite libraries on iOS, Android, and macOS (does not support Windows).

In general I would not encourage using the same database object that the sqlite plugin uses. I think it would be much safer and cleaner for the custom plugin to open and use its own sqlite database object. I think SQLite was designed to work this way.

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

No branches or pull requests

2 participants