简体   繁体   中英

Trigger and Stored Procedure in MariaDB

I am developing an online airticketing application and backend is in MariaDB database. I have the reservation table with the following structure:

预订表结构

When the record is inserted in the reservation_status the default value is TE which means timer expired. In this system I want to give users a 15 minute session time to complete the reservation. If the reservation is complete within 15 minutes of time the value of reservation_status field changes to XE which means successful booking.

I have a next table called schedule which has the following structure:

进度表结构 .

When a record is inserted in the reservation table the value in a row is updated. It means it increments the value of booked field and at the same time it decrements the value of remaining field by the same number. The problem arises when 15 minutes of time is over and passenger is not able to complete his booking due to any kind of reason. If the booking is not complete within 15 minutes of time i need to decrease the value of booked field and increase the value of the remaining field which was changed when booking process started. I have no idea how to reverse those values automatically in MariaDB database after the session of 15 minutes booking time is expired for every booking request of the reservation table.

When booking...

BEGIN;
increment one thing
decrement the other
record the time in the "job" table
COMMIT;

When time has expired...

BEGIN;
DEcrement one thing
INcrement the other
remove the item from job table
COMMIT;

The "job" table may need more than just a timestamp -- it may need a seat number, room number, or whatever, so you know what to in/decrement.

I would suggest the "job" be a program that continually runs; it wakes up periodically (say, every minute) and checks whether there is something to cleanup.

One more thing, in case the "job" crashes, you need some mechanism, such as a cron job, to perform a "keep-alive" on it. That launches it, but it is coded to die if it is currently running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM