0

データベースに 3 つのテーブル、tbl_events、tbl_exceptions、tbl_archived_events があります。

tbl_eventsはイベントのリストを格納します。これには次のフィールドが含まれます

**eventID** => int(4)Key, AutoIncrement
eventREF => VARCHAR (4) ( will remain the same for each version of the event and will be used to check for an exception)  
eventName => VARCHAR (30) (Name of the event)
eventType => int(4) will determine the type of event it is
eventLocation => VARCHAR (30) hold the event location data
eventDate => DATETIME hold the date of the event
eventStart => DATETIME hold the start time of the event
eventEnd => DATETIME hold the end time of the event
isReoccuring => int(2) Default to 1 which means it is reoccurring 
frequency => VARCHAR (10) will be either Daily/Weekly/Monthly/Yearly
eventLink => VARCHAR (30) will contain a link to the event page if there is one
eventValid => int(2) Will be set to 1 if the event is on and 0 if there is an exception

tbl_exceptionsには、一連のイベントと開催されない日付が格納されます。定期的なイベントが開催されない場合があります。このテーブルには、次のフィールド情報が保持されます

**exceptionID** KeyField, AutoIncrement => int(4)
eventREF => VARCHAR (4) Holds the event ref number
exceptionDate => DATETIME , Hold the date of the exception

tbl_archive_eventsは、有効期限が切れた過去のイベントを保存します。このテーブルは tbl_events テーブルと同じデータを格納しますが、過去のイベントのみを対象としています

**eventID** => int(4)Key, AutoIncrement
eventREF => VARCHAR (4) ( will remain the same for each version of the event and will be used to check for an exception)  
eventName => VARCHAR (30) (Name of the event)
eventType => int(4) will determine the type of event it is
eventLocation => VARCHAR (30) hold the event location data
eventDate => DATETIME hold the date of the event
eventStart => DATETIME hold the start time of the event
eventEnd => DATETIME hold the end time of the event
isReoccuring => int(2) Default to 1 which means it is reoccurring 
frequency => VARCHAR (10) will be either Daily/Weekly/Monthly/Yearly
eventLink => VARCHAR (30) will contain a link to the event page if there is one
eventValid => int(2) Will be set to 1 if the event is on and 0 if there is an exception[/CODE]

したがって、イベントの有効期限が切れたら、mysql に次のことを実行してもらいたい:

  • 1/ イベントが定期的なイベントである場合は、新しいイベントを作成し、既存のイベントに対する頻繁フィールドで指定された時間の長さに相対的な eventDate 日付を設定します。
  • 2/ 新しいイベント eventREF が eventException テーブルで見つかった場合、eventValid を 0 に設定します。
  • 3/ イベントの有効期限が切れたら、イベントを eventsArchive テーブルにコピーします
  • 4/ tbl_events テーブルから期限切れのイベントを削除する

私はこれまでのところこれを持っています

DELIMITER $$
CREATE 
EVENT `new_event` 
ON SCHEDULE EVERY 1 DAY STARTS '2016-07-24 03:00:00' 
DO BEGIN

       -- create new event
       SELECT eventID, eventREF, eventTitle, eventLocation, eventDate, eventStart, eventEnd, isReoccuring, frequency, eventType, eventLink, eventValid
       FROM tbl_events
       WHERE eventDate < now()

       --- for each event found create a new event
       INSERT INTO tbl_events (eventID, eventREF, eventTitle, eventLocation, eventDate, eventStart, eventEnd, isReoccuring, frequency, eventType, eventLink, eventValid) 


       -- copy expired events to tbl_archived_events
       INSERT INTO tbh_archived_events (eventID, eventREF, eventTitle, eventLocation, eventDate, eventStart, eventEnd, isReoccuring, frequency, eventType, eventLink, eventValid) 
       SELECT eventID, eventREF, eventTitle, eventLocation, eventDate, eventStart, eventEnd, isReoccuring, frequency, eventType, eventLink, eventValid
       FROM tbl_events
       WHERE eventDate < now();

       -- delete expired events from tbl_events
       DELETE FROM tbl_events WHERE eventDate < now();

END */$$[/PHP]

明らかに上記は正しくなく、私が何をしているのかよくわかりません。助けていただければ幸いですありがとう

ルーク

4

1 に答える 1