let fetch = ('select password from user where email='+email);
this.db1.executeSql(fetch, {})
what is wrong in this query
this is what error I am getting
"message":“sqlite3_prepare_v2 failure: no such column: dsadsad”,“code”:5}
“dsadsad” -> my input at login page
email
is a string and should be surrounded in quotes, otherwise it’s looking for a column with the name of the email.
Ohh thanks and one more thing can u give me one example how do I return column name back to calling function
In the promise it should return an array with objects of the selected columns - what do you mean? Can you show when you do after executeSql?
below is my function in provider
public checkUser(email:string,password:string)
{
this.db1.executeSql('select password,id from user where email = ? and password= ?',[email,password])
.then((data) => {
if (data.rows.length == 1) {
this.people = [];
for (var i = 0; i < data.rows.length; i++) {
this.people.push(JSON.stringify(data.rows.item(i)));
console.log(JSON.stringify(data.rows.item(i)));
}
return this.people;
}else{
return true;
}
}).catch(e => console.log(JSON.stringify(e)));
}
and from other function I am calling above function like this
this.sqlUser.checkUser(this.email,this.password)
Uhh not sure I understood this completely. Here’s what I think you want
public checkUser(email: string, password: string) {
return new Promise((resolve, reject) => {
this.db1.executeSql("select password,id from user where email = ? and password= ?", [email, password]).then(
data => {
if(data.rows.length === 1) {
resolve(data.rows[0]);
} else if(data.rows.length > 1) {
reject("Multiple users found");
} else {
reject("No user found");
}
},
err => {
reject(err);
}
);
});
}
this.sqlUser.checkUser(this.email, this.password).then(
user => {
},
err => {
}
);
resolve part will return me ok but in which type of variable I need to store that data.rows[0] and if I want to display that reject messages how I can do so…
I more thing example->create table if not exists user (user_id int PRIMARY KEY autoincrement,name VARCHAR(32),email VARCHAR(32)) is like this but autoincrement not working in this why…
An item in the data.rows array will be an object of
{
id: number,
password: string
}
So
this.sqlUser.checkUser(this.email, this.password).then(
user => {
console.log("User id is", user.id);
},
err => {
}
);
I imagine. As for your second question I don’t know, I haven’t used the SQLite plugin before
hey I am not getting why like this I am declaring
localStorage.setItem(“user_id”,user.rowid);
in my calling function and returning
like resolve(JSON.stringify(data.rows.item(0)));
but its showing that error Property ‘rowid’ does not exist on type ‘{}’.
The column you’re selecting is just called id
and not rowid
isn’t it? Can you show the code again, both the function and where you are using it
No I changed to road only and it’s printing in that function. But to calling function it’s showing that error
What is the code that you’re using now?
Also, there’s usually never a need to directly create a Promise.
Same way after my code return is there by Mac
Please tell me you are not storing plaintext passwords.
Of course will decrypt them and maintain the hash also this is for testing only how to interact with Ionic but in calling function why I m getting that error