Database triggers

Hello all,

Is there a way to get a trigger from a database insert (or change, etc.) so that some code will be executed from the triggering event? I am using MySQLCommunityServer.

You mean you want the trigger to call your Xojo code? I don’t think that’s possible.

1 Like

maybe you can set a flag or timestamp for any table/field in the trigger and poll this in xojo app via timer.

PostgreSQL have some kind of message system in xojo.

1 Like

Thank you, Tim Hare and MarkusR.

This example uses MariaDB, but there is a lot of overlap to MySQL:

From a security perspective, using Triggers to call external programs is highly discouraged, but depending on your environment, this may not be an issue.

1 Like

Thank you, Arthur.

Also look at XojoORM. With this you’ll be able to define your own database events.

1 Like

Hi @Lars_Lehmann correct me if I’m wrong but using XojoORM for this purpose would essentially involve raising an event or similar before changes are made to the db ? IOW actual db triggers themselves would not invoke an event, correct ?

1 Like

It actually is, and I’ve used it a lot (with PostgreSQL). The key is to have a persistant db connection in your Xojo app and have it listen for notifications, which you then send from within the trigger. On the Xojo side the ReceivedNotifications-Event is triggered (see: PostgreSQLDatabase — Xojo documentation). Works like a charm.

1 Like