0

I've implemented the optimistic in mysql database using MD5 and SHA-1 and everything work well. My problem is that i don't know if this is the best solution as i don't know how much time mysql take to calculate each hash. Here is the method

select field1 , field2 ,sha1(field1),md5(field2) from mytable
where id = someValueHere

update mytable set column1=value1,column2=value2
where id= someValueHere  
and sha1(field1) = storedValue 

this method gives you the possibily to not touch your databse or make changes on it. But as i've mentionned i need to know more details about performance of this method.

Yazid
  • 108
  • 3
  • 12
  • 1
    This might answer your question: [link](http://stackoverflow.com/questions/1184543/whats-faster-better-to-use-mysql-md5-function-or-run-md5-php-function) – sridesmet Mar 31 '14 at 10:32
  • Can you elaborate a bit on what is the purpose of those hashes? In the second query is unclear where `storedValue` comes from, and assuming `id` is a primary key - why do you need to compare hashes? – Vatev Mar 31 '14 at 10:52

0 Answers0