# $cordovaSQLite with ngCordova in ios emulator

**URL:** <https://forum.ionicframework.com/t/cordovasqlite-with-ngcordova-in-ios-emulator/21743>\
**Category:** cordova\
**Created:** [April 27, 2015, 3:44am UTC](https://forum.ionicframework.com/t/cordovasqlite-with-ngcordova-in-ios-emulator/21743 "2015-04-27T03:44:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rdrapertraction](https://avatars.discourse-cdn.com/v4/letter/r/c5a1d2/32.png) [@Rdrapertraction](https://forum.ionicframework.com/u/Rdrapertraction)\
**Post date:** [April 27, 2015, 3:44am UTC](https://forum.ionicframework.com/t/cordovasqlite-with-ngcordova-in-ios-emulator/21743/1 "2015-04-27T03:44:46Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Rdrapertraction](https://avatars.discourse-cdn.com/v4/letter/r/c5a1d2/32.png) [@Rdrapertraction](https://forum.ionicframework.com/u/Rdrapertraction)\
**Post date:** [April 27, 2015, 3:53am UTC](https://forum.ionicframework.com/t/cordovasqlite-with-ngcordova-in-ios-emulator/21743/2 "2015-04-27T03:53:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jeremy](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jeremy](https://forum.ionicframework.com/u/jeremy)\
**Post date:** [May 12, 2015, 5:08am UTC](https://forum.ionicframework.com/t/cordovasqlite-with-ngcordova-in-ios-emulator/21743/3 "2015-05-12T05:08:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rdrapertraction](https://avatars.discourse-cdn.com/v4/letter/r/c5a1d2/32.png) [@Rdrapertraction](https://forum.ionicframework.com/u/Rdrapertraction)\
**Post date:** [May 12, 2015, 5:45am UTC](https://forum.ionicframework.com/t/cordovasqlite-with-ngcordova-in-ios-emulator/21743/4 "2015-05-12T05:45:57Z")

</div>

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.
