Reputation: 50
Am trying to pass a not null value to sqlite parameter in as3 in adobe air for desktop, here is the sample of code:
stat.text = "SELECT * FROM people, WHERE gender = @gender AND year = @year AND month = @month";
stat.parameters["@gender"] = genderBox.value;
stat.parameters["@year"] = year.text;
stat.parameters["@month1"] = month.text;
where genderBox is a combobox with 2 values of course male and female and the others are just textboxes. i want to make the genderBox having 3 values the third one is Both males and females so when the user select both the statment select both the males and females i want it to pass something like not null value and select everything from that column but choose the other columns month and year
Upvotes: 0
Views: 172
Reputation: 1074
Why not create statement in two steps?
stat.text = "SELECT * FROM people WHERE year = @year AND month = @month";
if (genderBox.value) {
stat.text += " AND gender=@gender";
stat.parameters["@gender"] = genderBox.value;
}
I don't know if stat.text can be appended this way but I think the idea is clear.
If you still want to keep it in one piece, change the equality to non-equality like this:
stat.text = "SELECT * FROM people WHERE gender != @gender AND year = @year AND month = @month";
The logic of using the param @gender will also reverse. If your genderBox returns "male", the query will search all females. If it returns "female", it will search males. To search all, simply pass a non-existing value. So this will require change in the genderBox logic and it will become confusing. So it's not a good way, actually.
UPDATE
If you can make the combobox return a comma-separated list like "male, female" as a third value, you can use the following query:
SELECT * FROM people WHERE gender in(@gender)... etc
Upvotes: 2