Sqlite in RC3, can't open database?


#1

After upgrading to RC3, I can’t seem to open a Sqlite database.

After playing with it for a while in my app, I created a new app, installed cordova-sqlite-storage, and entered the following code into app.component.ts:

import { Component } from ‘@angular/core’;
import { Platform } from ‘ionic-angular’;
import { StatusBar, Splashscreen, SQLite } from ‘ionic-native’;

import { TabsPage } from ‘…/pages/tabs/tabs’;

@Component({
templateUrl: ‘app.html’
})
export class MyApp {
rootPage = TabsPage;

constructor(platform: Platform) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();

  let db = new SQLite();
  db.openDatabase({
      name: "data.db",
      location: "default"
  }).then(() => {
      db.executeSql("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY AUTOINCREMENT, firstname TEXT, lastname TEXT)", {}).then((data) => {
          console.log("TABLE CREATED: ", data);
      }, (error) => {
          console.error("Unable to execute sql", error);
      })
  }, (error) => {
      console.error("Unable to open database", error);
  });
});

}
}

This was based on this tutorial, which, admittedly is pre-RC3.

On running the app on the emulator, I get: “console.error: Unable to open database {“line”:76,“column”:25}”

Is anyone else having trouble with the Sqlite Plugin? Suggestions?


#2

Same error here with RC3


#3

Frankly, not what I wanted to hear.

I tried downgrading to RC2 and still couldn’t connect. Wondering if its some other component that upgraded at the same time then?


#4

So I tried this, and it seemed to work:

npm uninstall -g cordova
npm install -g cordova
ionic start --v2 myApp3 tabs
cd myApp3
cordova plugin add cordova-sqlite-storage

Then copied in the code above and it worked fine. Maybe an issue with cordova? I have the same version of cordova installed before and after, so not sure what it could be.


#5

Thanks for the solution,it worked for me but I have no idea why it works
:confused: