Query not properly working


#1
 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


#2

email is a string and should be surrounded in quotes, otherwise it’s looking for a column with the name of the email.


#3

Ohh thanks and one more thing can u give me one example how do I return column name back to calling function


#4

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?


#5

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)

#6

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 => {
		
	}
);

#7

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…


#8

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


#9

thank u so much buddy


#10

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 ‘{}’.


#11

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


#12

No I changed to road only and it’s printing in that function. But to calling function it’s showing that error


#13

What is the code that you’re using now?

Also, there’s usually never a need to directly create a Promise.


#14

Same way after my code return is there by Mac


#15

Please tell me you are not storing plaintext passwords.


#16

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


#17