Hi boys,
I’m in trouble… when I compile my code, it goes to a function to insert Data from input/textarea to a SQLite database. It goes just before making the SQL query and then get out the function without announcing any of my Alert(JSON.stringify(error)); …
What do you think of that ?
There is my alert if you follow step by step the process to create a memo and save it.
- Here is the menu, so you press “Nouveau memo” (it means “new memo”)
- Then you arrive on the New Memo editor page. I complete the title input and the textarea with “Test”. I’m going to press the back-arrow at the top on the left
ALERTS RESULTS :
function goBack()
: Back button press --> “Enter in goBack function if id == null…” --> “Going to INSERT query” --> function loadMemos
: “Select result: {“rows”:{length":0},“rowsAffected”:0}”
Without any errors…
Source code :
private goBack(showBadge: boolean = true)
{
if (this.memo.id == null) {
alert("Enter in goBack function if id == null...")
// Calling the existing database
this.storage.create({
name: "MemoPlus.db",
location: "default"
}).then((db: SQLiteObject) =>
{
alert("Going to INSERt query");
db.executeSql('INSERT INTO PAGE (title, content) VALUES (?, ?)', [this.memoInfo.title, this.memoInfo.content]).then((data) => {
alert("INSERTED error " + JSON.stringify(data));
alert("Insert into page title content OK !");
this.returnID(this.memoInfo.title);
}, (error) => {
alert("Report Error inserting table page title content : " + error);
alert("ERROR: " + JSON.stringify(error.err));
});
}, (error) => {
alert("ERROR: " + JSON.stringify(error.err));
alert("DB error : " + error);
});
}
else
{
alert("Memo already existing so memoupdate function")
this.memoService.memoUpdate(this.memo);
}
// Redirect on HomePage
this.navCtrl.setRoot(HomePage);
// ShowBadge (toast) is a little pop-up during 3 seconds, to tell the user that the memo has been saved (optional)
if (showBadge) {
let toast = this.toastCtrl.create({
message: 'Memo saved',
duration: 3000
});
toast.present();
}
}
if needed :
public returnID(title: string ) : any
{
alert("Enter into returnID function");
this.storage.create({
name: "MemoPlus.db",
location: "default"
}).then((db: SQLiteObject) =>
{
db.executeSql('SELECT id FROM page WHERE title = ?', title).then((data) => {
let temp = JSON.stringify(data);
alert("selected ID of the page where title = ? !!");
return temp['id'];
}, (error) => {
console.log("ERROR: " + JSON.stringify(error.err));
alert("Report Error select id FROm page where title = ?: " + error);
});
});
}
and loadMemos :
public loadMemos()
{
// Calling the existing database (MemoPlus.db)
this.storage.create
({
name: "MemoPlus.db",
location: "default"
}).then((db: SQLiteObject) =>
{
// SQL Query to SELECT all the data (Memos) that the table "page" contains
db.executeSql("SELECT * FROM page", []).then((data) =>
{
alert ("Select result: " + JSON.stringify(data));
}, (error) => {
// In case of an error while trying to SELECT the data from the database, return the error
alert("Unable to execute SQL query: " + error);
alert(JSON.stringify(error));
});
}, (error) => {
// In case of an error while trying to open the database, return the error
alert("Unable to open database: " + error);
alert("ici bug...: " + JSON.stringify(error));
});
}
tell me if you need more information.
Thanks in advance.