$cordovaSQLite with ngCordova in ios emulator

I am writing one of my first apps using ionic + ngCordova + $cordovaSQLite plugin. I have some code that seems to work fine using the android emulator but not so much in the ios emulator. Here’s my startup code:

.run(function($ionicPlatform, $cordovaSQLite) {
  $ionicPlatform.ready(function() {

if (window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
  // org.apache.cordova.statusbar required
  StatusBar.styleDefault();
}

db = $cordovaSQLite.openDB({name: dbname});
console.log('db opened 2: ' + JSON.stringify(db));
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS user (id integer primary key, firstname text, lastname text, password text, email text, username text)");
  });
})

In the android emulator this code gives me no errors and when I do something later like insert a user into the table it completes successfully. In the ios emulator the openDB call works and the DB gets created successfully which I proved with the console log. The execute call that I make next fails. All I get for an error in the console is “new transaction is waiting for open operation”. I believe I am using all the latest stuff: ionic cli, cordova, ngCordova, sqlite plugin from brodysoft.

Any insights on this greatly appreciated. I have Googled quite heavily already…

To be the first to update my own topic, I tried using the following:

db = window.sqlitePlugin.openDatabase({name: dbname, location: 1});

instead of

db = $cordovaSQLite.openDB({name: dbname});

and it seems to have solved the issue. I can successfully insert into the table with no errors. However, my follow up question would be: why doesn’t the $cordovaSQLite version work the same? Why should I bother using the $cordovaSQLite plugin wrapper calls at all if the calls to window.sqlitePlugin seem to work more reliably?

1 Like

Thanks for posting your workaround @Rdrapertraction, I had the same problem and can confirm that simply bypassing ngCordova solves the issue.

My pleasure @jeremy I would still like to know if anyone has any thoughts on my question as I still haven’t figured it out.