Xojo Conferences

« Kit vs. Plugin for Bo… | Home | Bug of the day: Not e… »

Tip of the day: MySQL Error 1213

With MySQL it can happen that you get an error 1213 with message "Deadlock found when trying to get lock; try restarting transaction". Our MBS Xojo SQL Plugin will report that as exception or through error properties. Now we had the idea that we do the restart of the operation for you. So if you set with next plugins (15.1pr4) the option MySQLRetryAutomaticallyOnDeadLock to true for either Command or Connection, the plugin will try three times. If it gets error 1213, it will automatically try again after waiting 10 milliseconds.

The reason we put it in the plugin right in the execute method is to make sure all attempts can happen in background on the same thread. Using ExecuteMT we do the operation on a preemptive helper thread and if we need two or three attempts the other threads of your application are not influenced and do their work as usual.

Update: This is for a small application which does not use transactions. If you use transactions, this switch may result in problems as it does only repeat last SQL command. If you use transactions, please code it yourself and do proper rollback and start again with a new transaction.
01 04 15 - 17:52
No comments

Remember personal info?

Emoticons / Textile

Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.