DROP TABLE IF EXISTS `v_schedule`;
DROP VIEW IF EXISTS `v_schedule`;

CREATE OR REPLACE VIEW `_db_calendar`.`v_schedule` AS 
SELECT m_schedule.id_schedule, m_schedule.id_account, m_schedule.c_date, m_schedule.c_time1, m_schedule.c_time2, m_schedule.c_subject, m_schedule.c_memo, m_schedule.c_updatetime, m_schedule.c_delete, m_schedule.c_privacy, m_schedule.id_category, m_category.c_categoryName, m_category.c_categoryDisplayColor, m_category.c_iconImage, m_schedule.c_attachFile1, m_schedule.c_attachFile2, m_schedule.c_attachFile3, m_schedule.id_group, m_schedule.c_map, m_schedule.c_memo_strip_tags, m_schedule.upd_id_account, m_schedule.add_id_account, _db_account.m_account.c_handle as add_c_handle
FROM m_schedule
LEFT OUTER JOIN m_category ON m_schedule.id_category = m_category.id_category
LEFT OUTER JOIN _db_account.m_account ON m_schedule.add_id_account = _db_account.m_account.id_account
WHERE m_schedule.c_delete = 0;

DROP TABLE IF EXISTS `v_weather`;
DROP VIEW IF EXISTS `v_weather`;

CREATE OR REPLACE VIEW `_db_calendar`.`v_weather` AS 
SELECT m_weather.*, r_kenmei.c_kenmei
FROM m_weather
LEFT OUTER JOIN r_kenmei ON m_weather.c_kenid = r_kenmei.c_kenid;

DROP TABLE IF EXISTS `v_message`;
DROP VIEW IF EXISTS `v_message`;

CREATE OR REPLACE VIEW `_db_calendar`.`v_message` AS 
SELECT m_message.id_message, m_message.from_id_account, m_message.to_id_account, m_message.c_message, m_message.c_registtime, m_message.c_receivedtime, m_message.c_sendmail, from_m_account.c_handle as from_c_handle, to_m_account.c_handle as to_c_handle
FROM m_message
LEFT OUTER JOIN _db_account.m_account from_m_account ON m_message.from_id_account = from_m_account.id_account
LEFT OUTER JOIN _db_account.m_account to_m_account ON m_message.to_id_account = to_m_account.id_account;

