Ruslan Polupan
Dec. 14, 2018, 6:48 p.m.

MySQL stored procedures

Good day.

I create a Duty schedule application for our technical support hotline, using Qt + MySQL.
For each month it is necessary to monthly fill in the calendar table containing the date and sign of the day off or working day..


The table structure is as follows:

  1. CREATE TABLE `calendar` (
  2. `calendarID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  3. `monthID` int(10) unsigned NOT NULL,
  4. `date` date NOT NULL,
  5. `iswork` tinyint(3) unsigned NOT NULL,
  6. PRIMARY KEY (`calendarID`),
  7. KEY `month` (`monthID`)
  8. ) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8mb4

The procedure was written without checking incoming values.
February leap year handles correctly.

Called

  1. call filling_the_calendar(2,2016);
  1. CREATE DEFINER=`root`@`localhost` PROCEDURE `filling_the_calendar`(IN cur_month INT, cur_year INT)
  2. BEGIN
  3. -- We declare variables the current day, the first day of the month, the first day of the next month.
  4. DECLARE cur_day, first_day, next_month DATE;
  5. --Month ID, working day or not
  6. DECLARE monthID, iswork INT;
  7. /*Variable initialization*/
  8. SET first_day = CONCAT(cur_year,'-',cur_month,'-01');
  9. SET monthID = cur_year * 100 + cur_month;
  10. SET next_month = DATE_ADD(first_day, INTERVAL 1 MONTH);
  11. SET cur_day = first_day;
  12. /*Going through all the days of the month */
  13. WHILE cur_day < next_month DO
  14. /*If the day of the week is Saturday or Sunday they are not working*/
  15. IF (WEEKDAY(cur_day) = 6 OR WEEKDAY(cur_day) = 5) THEN
  16. SET iswork = 0;
  17. ELSE
  18. SET iswork = 1;
  19. END IF;
  20. /*add record to table*/
  21. INSERT INTO calendar (`monthID`, `date`, `iswork`)
  22. VALUES (monthID, cur_day, iswork);
  23. /*Increase the day*/
  24. SET cur_day = DATE_ADD(cur_day, INTERVAL 1 DAY);
  25. END WHILE;
  26. END

By article asked0question(s)

2

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • AK
    April 1, 2025, 11:41 a.m.
    Добрый день. В данный момент работаю над проектом, где необходимо выводить звук из программы в определенное аудиоустройство (колонки, наушники, виртуальный кабель и т.д). Пишу на Qt5.12.12 поско…
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
  • ИМ
    Nov. 22, 2024, 9:51 p.m.
    Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
  • Evgenii Legotckoi
    Oct. 31, 2024, 11:37 p.m.
    Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup