Correct SQL locking