I am working on a โgradingโ system and try to prevent a person from submitting an assessment twice using a stored procedure that will check whether a person has rated a particular item before allowing a new one to be saved. Strange, I pass in the user ID and object ID, but when my stored procedure selects COUNT (*), I get the wrong number.
Here is my stored procedure:
CREATE PROCEDURE `ADD_GRADE`(IN objectID int, IN grader int) BEGIN DECLARE gradeCount INT; SELECT COUNT(*) FROM GRADES WHERE Obj_ID = objectID AND Grader = grader INTO gradeCount; IF gradeCount <= 0 THEN INSERT INTO Grades (Obj_ID, Grader) VALUES (objectID, grader); END IF;
The IF statement works, but for some reason, my Count class seems to be ignoring the Grader ID and just checking based on Obj_ID. I added options to make sure that my parameters remain at the correct value, and they are. If I copy only the selection and do it manually elsewhere, I will get the correct number.
Although new to MySql, I am not new to SQL. Am I just losing my mind? Or am I doing something wrong?
thanks
source share