Errors using the ngCordova $cordovaSQLite plugin with Ionic

怎甘沉沦 提交于 2019-12-03 21:17:51

Like Nic Raboy stated, the syntax for the ngCordova SQLite openDB calls has changed, despite what the documentation has said, to the following:

db = $cordovaSQLite.openDB( databasename, databaseType );

The second parameter databaseType, is how the database is being stored. In my case I used the number use to store the database in the background hidden from iTunes, but backed-up with iCloud.

By changing the syntax of this call, this fixed my error.

NOTE: if you are trying to work in the browser, this open database call will error. To work around this, you will need to introduce an "if" statement to change out the call depending on your environment. The following worked for me:

if (window.cordova && window.SQLitePlugin) {
    var db = $cordovaSQLite.openDB( 'accounts.db', 1 );
} else {
    db = window.openDatabase('accounts', '1.0', 'accounts.db', 100 * 1024 * 1024);
}

I spent more then half a day to figure the solution out.In my case I updated my project from previous version of ionic to a newer one.But the problem was that I copied www folder but didn't add the sqlite plugin again.

So all I did to fix was :

cordova plugin add cordova-sqlite-storage

I don't know if you found the answer. I had many issues first than configurate properly project.

  • One problem could be that you should import as last thing ng-cordova.js and then cordova.js. app.js and controller.js should be imported first.

  • If you are running in a web app could have a problem with cordova ready parameter that won't be never ready so database won't be open.

  • Try with new call that Triccum said.

I don't remember more issues.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!