Web SQL deprected

Hi Team,
I am no longer able to run the app in my local and also when deployed the apk on a Tablet getting issue when trying to open the DB.

I have tried to use the plugin mentioned in one of the forums at this URL WebSQL replacement for local DB - #3 by designlink
but no luck. It still stuck when try to open the DB.

Error getting in local : window.opendatabase is not function.

Can someone please advise what plugin to use or how to overcome this problem.
As we have 3-4 apps heavily relied on Web SQL stuff.

Thanks

That error is expected. You will need to change your code slight so that it uses window.sqlitePlugin.openDatabase. I would suggest carefully reading the documentation for the plugin as it’s not entirely a drop in replacement: cordova-sqlite-evcore-extbuild-free/README.md at master · storesafe/cordova-sqlite-evcore-extbuild-free · GitHub

I have already replaced the code to open the DB as below.
function openDB()
{
var db = window.sqlitePlugin.openDatabase({
name: ‘Vinea’,
location: ‘default’,
androidDatabaseProvider: ‘system’
});
return db;
}

But still no luck as I cannot see any tables getting created.

I have added this in my config.xml file.

Tried in local and with apk but no luck.

Am I missing something else here.
Can you please advise.
Thanks

How are you looking for tables? Are there any errors in the remote debugging console?

These are the errors in my debug console.

I am using this plugin
plugin name=“cordova-sqlite-evcore-extbuild-free” source=“npm”

Code to open DB:

function openDB()
{
var db = window.sqlitePlugin.openDatabase({
name: ‘Vinea’,
location: ‘default’,
androidDatabaseProvider: ‘system’
});
return db;
};

Using below version for cordova.js file when running locally.
2.9.0-0-g83dc4bd

Please advise how to fix this error.

thanks

If you review the documentation for the plugin, you’ll see it directs you to only attempt to open the database after deviceready has fired:

var db = null;

document.addEventListener('deviceready', function() {
  db = window.sqlitePlugin.openDatabase({
    name: 'my.db',
    location: 'default',
  });
});

Based on your log and code, I suspect you aren’t doing this. Give it a try and let us know if that resolves the issue.

1 Like

Yes, it worked on the tablet after making this change.
Thank you so much.

One more question
Does this plugin will not work when test locally on browser?
Cheers

Cordova plugins don’t function in the browser. There are a number of options for the local browser for SQLite, but that landscape is in flux now that Chrome has deprecated support. Here’s an article outlining some of the options: Using SQLite with Chrome 119 - NSB App Studio

This is centered around our other product AppStudio, however much of the information still applies. Many of our users check to see if the plugin is installed and then if not, fall back to a browser native option.

will look into it. much appreciate your help for sorting all this. thanks