473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

trigger to run an external program

Hi

Can I trigger an external program to run when a new record is added to
the mysql table?

The external program is in C and instead of scanning the table
continuously for new insertions, it will be better if an external
program could be triggered.

Any suggestions?

Nov 23 '05 #1
4 20081
My SQL wrote:
Hi

Can I trigger an external program to run when a new record is added to
the mysql table?
In theory yes, you can write a UDF to do something like this, and call
that UDF from a trigger, but that's not an advisable solution, IMO.

UDF's that try to change state outside the DBMS (e.g. writing files,
starting processes, sending notifications, etc.) are risky. They may
take an unbounded amount of time to execute. Or they may be a security
vulnerability. Or they may have a bug that makes them crash, which
would bring down your MySQL server.
The external program is in C and instead of scanning the table
continuously for new insertions, it will be better if an external
program could be triggered.


I think it's better to have another process monitor the data for
changes. If you really have a requirement that this be close to
real-time, you need to do continual scanning.

You might consider defining a special table to store the "flag" data
that a change has occurred, and on which record, etc. Then the external
process monitors only that one table. Once the external process has
accounted for a given change, it deletes the flag from that table.

Perhaps you could use the CSV storage engine to make it easier for that
external process to perform the monitoring without burdening the MySQL
engine.
See http://dev.mysql.com/doc/refman/5.0/...ge-engine.html

Regards,
Bill K.
Nov 23 '05 #2
>Can I trigger an external program to run when a new record is added to
the mysql table?
This is awkward, and tends to have problems if the external program
can fail.
The external program is in C and instead of scanning the table
continuously for new insertions, it will be better if an external
program could be triggered.

Any suggestions?


One approach is to have a new table: work_to_do. A trigger inserts
a record into this table with a date stamp and identification of
the record that changed (and perhaps WHAT changed or the old value
of the field) along with a "job number". You have a process look
at work_to_do occasionally and process the changes. Since there's
a date in there, you can do the changes in order.

If the external program succeeds, delete the record from work_to_do
(by "job number"). Note that you could have several changes for
the same record before the external program gets to it, or perhaps
while the external program is handling some of the changes, another
one comes in. If the external program *FAILS*, leave the record
in work_to_do. Whether you proceed with independent changes after
a failed change is up to you.

This sort of thing is common when you've got a central billing
system and a distributed mail system, so when a mail account is
created, the mailbox has to be created on one of the mail servers.
If the mail server is down for maintenance at the moment, it's
important that the mailbox creation be done eventually.

Gordon L. Burditt
Nov 23 '05 #3
Thanks Bill

I got to know the risks involved. Will this continuous reading cause
any serious delays to the other queries being executed?

Thanks again

Nov 23 '05 #4
My SQL wrote:
I got to know the risks involved. Will this continuous reading cause
any serious delays to the other queries being executed?


Probably not serious delays. I can't answer for certain, because I
don't know your system. The answer depends on many things, including
your database structure, the queries used on it by both readers and
writers, and also your system hardware, etc.

The only way to answer for certain is for you to implement it and test
with the monitoring application on and off.

Regards,
Bill K.
Nov 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: chandan | last post by:
Is it possible to call an external java program from a trigger in oracle 8i. I know that you can call a stored procedure in java from a trigger but i want to know is it possible to call an...
4
by: Joel Thornton | last post by:
Whenever something is inserted to a given table, I want to run some shell commands using xp_cmdshell. Would it be a bad idea to put this xp_cmdshell in the INSERT trigger of this table? I...
6
by: Rolf Kemper | last post by:
Dear All, we are running SQL2000 Sever and make use of the xp_sendmail. For any reason the mail service can run into problems and it looks like that the statemnt below gets not finished. ...
1
by: Simon Holmes | last post by:
Hi, I am having trouble calling a UDF from a 'before update' trigger whereas I have no problems calling it from the 'after update' trigger. The trigger is as below : CREATE TRIGGER foo NO...
0
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
0
by: JohnO | last post by:
Thanks to Serge and MarkB for recent tips and suggestions. Ive rolled together a few stored procedures to assist with creating audit triggers automagically. Hope someone finds this as useful as...
1
by: Thierry Missimilly | last post by:
Hi Postgres users, I wonder to know if it is possible to launch a Perl program or a unix comand in a trigger function. I have tried to do that in a C trigger developed with the SPI function....
5
by: Mike Nolan | last post by:
I have a before insert trigger that updates a value in another table. It appears that I cannot depend upon that update having taken place in an after insert trigger on the first table. (The one...
1
by: Gregi | last post by:
Hello, I'm using VS2005 and SQL 2005. Is it possible for a SQL trigger to immediately raise an event in my C# program? Actually it's C++/CLI, but it's easy to translate C# -C++/CLI, so any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.