I wonder why MySQL does not allow table locking inside a stored procedure.
I have the following SQL statements inside my stored procedure:
-- Total amount of money for comments
start transaction;
select @num_comments := count(*)
from `comment` c
where
c.user_id = user_id and
c.payment_rejection = 'NO' and
c.is_recorded = 0;
update `user` u set account_balance += u.comment_price * @num_comments where u.user_id = user_id;
update `comment` c set is_recorded = 1 where c.user_id = user_id and c.payment_rejection = 'NO' and c.is_recorded = 0;
commit;
So I have to lock table comment
to prevent any writing to it for it may cause the number of rows selected in the first SQL statement be different from the number of actually updated.