MySQL Forums
Forum List  »  Stored Procedures

Re: Lock a row
Posted by: Russel James
Date: January 27, 2016 05:21AM

Done some further research.

The following code does not return any errors and seems to work as expected. Anyt potential problems with it ??

START TRANSACTION;

/* COPY PARAMETERS INTO LOCAL VARS */
SET @t = p_tableName;
SET @f = p_fieldName;

/* LOCK THE TABLE ROW */
SET @s = CONCAT("SELECT ", @f, " FROM ", @t , " FOR UPDATE ");
PREPARE stmt FROM @s;
EXECUTE stmt;

/* UPDATE THE TABLE */
SET @s = CONCAT("UPDATE ", @t, " SET ", @f , " = ", @f, " + 1");
PREPARE stmt FROM @s;
EXECUTE stmt;

/* RETURN THE NEW VALUE */
SET @s = CONCAT("SELECT ", @f, " FROM ", @t);

COMMIT;

Options: ReplyQuote


Subject
Views
Written By
Posted
2465
January 26, 2016 03:00PM
Re: Lock a row
965
January 27, 2016 05:21AM
713
January 31, 2016 01:37PM
752
January 27, 2016 12:18PM
768
January 27, 2016 02:01PM
767
January 27, 2016 03:03PM
714
January 29, 2016 06:49PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.