Mysql auto reconnect

Hello

I use the mysql plugin to connect to a mysql database (hence the name…)
But, because the mysql instance is created in code, I don’t have events on the mysql plugin.

I cannot find it in the documentation, but is there a way to get informed when the connection is lost? So that I can reconnect?

Look here: http://documentation.xojo.com/index.php/AddHandler.
With AddHandler you will be able to receive events that would be passed to a window, container control, etc. instance.

Thanks, this is very useful.

But one thing left: mysql doens’t seem to have any events. Is that normal?
Even the parent object “Database” doesn’t seem to have any events. This asks for a feature request I think.

How do other people solve this problem?

No idea about that since I have never used the mysql plugin, sorry. I thought you were saying that there were events available but you could’t use them because you were initiating via code (the perfect situation to use addhandler). If there are no events available maybe there is a connected property or a method to check if the DB is connected? Just check that with a timer periodically and if it’s disconnected trigger your reconnect code.

No problem, I was wrong, I thought there were events. But there aren’t.
Testing with a Timer is a good idea.

And your AddHandler link is also very handy, will come in use one time or another!

I use a Thread for this kind of connection test. A thread which is called from within a Timer within my Main Window.

RecordSetObject = DatabaseObject.SQLSelect("SELECT 1 FROM DUAL") If RecordSetObject = Nil Then BooleanObject = ConnectToDatabase

And i use a “SELECT 1 FROM DUAL” statement because of this.

Hope i could help. Regards.

I usually just attempt a database action and check the error that comes back. If it indicates the connection is lost, I reconnect and retry the db action.