I am currently working on an Ionic2 project that requires users to log in before gaining access to the system. Once the login is successful, I need to post their username to another API to retrieve a list of all entries made by them. The challenge I am facing is inserting all the returned entries into an SQLite database.
userlogin(){
let loader = this.LoadingController.create({
content: 'Please Wait'
});
loader.present().then(()=>{
this.http.post("http://localhost/app/login.php", { 'username': this.username, 'password': this.password }).map(res => res.json()) .subscribe(data => {
if(data.message!="Incorrect Username or Password"){
this.http.post("http://localhost/app/entries.php", { 'username': this.username}).map(res => res.json()) .subscribe(data => {
console.log(JSON.stringify(data));
this.sqlite.create({
name: 'entries.db',
location: 'default'
})
.then((db: SQLiteObject) => {
//data insert section
db.executeSql('INSERT INTO entries_table(entry) VALUES(?)',
[this.data.entry]).then((data)=> {
}, (error) => {
});
})
});
}else{
if(data.message=="Incorrect Username or Password"){
let alert = this.alertCtrl.create({
title: 'Error!',
subTitle: 'Wrong Username or Password',
buttons: ['Try Again']
});
alert.present();
}
}
loader.dismiss();
});
},error=>{
let alert = this.alertCtrl.create({
title: 'Error!',
subTitle: 'Please check your Internet Connectivity',
buttons: ['Try Again']
});
alert.present();
})
}
The login process is working smoothly, but the challenge lies in inserting multiple data returned by the API into the SQLite database simultaneously.