I actually try to make an mobile app with SQLite. I juste try to create two tables:
constructor(private sqlite:SQLite,public modalCtrl: ModalController,public navCtrl: NavController, private navParam: NavParams, private databaseprovider: DatabaseProvider, private employeesProvider: EmployeeProvider) { this.createDetabaseFile(); } private createDetabaseFile() : void { this.sqlite.create({ name: DATABASE_FILE_NAME, location: 'default' }).then((dbRes: SQLiteObject) => { alert("bdd créée"); this.db = dbRes; this.createTables(); }) } private createTables() : void { this.db.executeSql('CREATE table IF NOT EXISTS symbole(id INTEGER NOT NULL ,name TEXT)',{}) .then(() => { alert("table symbole created"); this.db.executeSql('CREATE table IF NOT EXISTS representationPhoto(name VARCHAR(32))',{}) .then(() => { alert("table representationPhoto created"); }) .catch(e => alert("erreur creation table")); }) .catch(e => alert("erreur creation table")); }
And db.executeSql()
seem not working, indeed, the alert("table symbole created");
don't appear, however alert("bdd créée")
appear, and the program don't triggered the catch.
Have you an idea?
ps: sorry for my bad english
2 Answers
Answers 1
Kindly try declaring db variable above createDetabaseFile function it seems to me the problem because you are using this.db without declaring it in the class scope.
Try doing this:
public db: any; // above createDetabaseFile function
Answers 2
You're missing platform ready
block before handling SQLite
.Try this:
import { Platform } from 'ionic-angular'; constructor(private platform: Platform, ...other imports) { this.platform.ready().then(() => { this.createDetabaseFile(); }) }
0 comments:
Post a Comment