Ruslan Polupan
Ruslan Polupan14. Dezember 2018 07:48

Gespeicherte MySQL-Prozeduren

guten Tag

Ich baue mit Qt + MySQL eine Duty Schedule-Anwendung für unsere technische Support-Hotline.
Für jeden Monat muss eine monatliche Kalendertabelle ausgefüllt werden, die das Datum und das Zeichen des Wochenendes oder Arbeitstages enthält.


Die Tabellenstruktur ist wie folgt:

CREATE TABLE `calendar` (
  `calendarID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `monthID` int(10) unsigned NOT NULL,
  `date` date NOT NULL,
  `iswork` tinyint(3) unsigned NOT NULL,
  PRIMARY KEY (`calendarID`),
  KEY `month` (`monthID`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8mb4

Die Prozedur wurde geschrieben, ohne die eingehenden Werte zu prüfen.
Der Februar ist ein richtig gehandhabtes Schaltjahr.

Anruf

call filling_the_calendar(2,2016);
CREATE DEFINER=`root`@`localhost` PROCEDURE `filling_the_calendar`(IN cur_month INT, cur_year INT)
BEGIN
    -- We declare variables the current day, the first day of the month, the first day of the next month.
    DECLARE cur_day, first_day, next_month DATE;
    --Month ID, working day or not
    DECLARE monthID, iswork INT;
    /*Variable initialization*/
    SET first_day = CONCAT(cur_year,'-',cur_month,'-01');
    SET monthID = cur_year * 100 + cur_month;
    SET next_month = DATE_ADD(first_day, INTERVAL 1 MONTH);
    SET cur_day = first_day;
    /*Going through all the days of the month */
    WHILE cur_day < next_month DO
    /*If the day of the week is Saturday or Sunday they are not working*/
        IF  (WEEKDAY(cur_day) = 6 OR WEEKDAY(cur_day) = 5) THEN 
            SET iswork = 0;
        ELSE 
            SET iswork = 1;
        END IF;
        /*add record to table*/
        INSERT INTO calendar (`monthID`, `date`, `iswork`)
                    VALUES (monthID, cur_day, iswork);
     /*Increase the day*/
        SET cur_day = DATE_ADD(cur_day, INTERVAL 1 DAY);
    END WHILE;
END
Рекомендуємо хостинг TIMEWEB
Рекомендуємо хостинг TIMEWEB
Stabiles Hosting des sozialen Netzwerks EVILEG. Wir empfehlen VDS-Hosting für Django-Projekte.

Magst du es? In sozialen Netzwerken teilen!

Kommentare

Nur autorisierte Benutzer können Kommentare posten.
Bitte Anmelden oder Registrieren
Letzte Kommentare
ИМ
Игорь Максимов5. Oktober 2024 07:51
Django – Lektion 064. So schreiben Sie eine Python-Markdown-Erweiterung Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
d
dblas55. Juli 2024 11:02
QML - Lektion 016. SQLite-Datenbank und das Arbeiten damit in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
k
kmssr8. Februar 2024 18:43
Qt Linux - Lektion 001. Autorun Qt-Anwendung unter Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
Qt WinAPI - Lektion 007. Arbeiten mit ICMP-Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
EVA
EVA25. Dezember 2023 10:30
Boost - statisches Verknüpfen im CMake-Projekt unter Windows Ошибка LNK1104 часто возникает, когда компоновщик не может найти или открыть файл библиотеки. В вашем случае, это файл libboost_locale-vc142-mt-gd-x64-1_74.lib из библиотеки Boost для C+…
Jetzt im Forum diskutieren
J
JacobFib17. Oktober 2024 03:27
добавить qlineseries в функции Пользователь может получить любые разъяснения по интересующим вопросам, касающимся обработки его персональных данных, обратившись к Оператору с помощью электронной почты https://topdecorpro.ru…
JW
Jhon Wick1. Oktober 2024 15:52
Indian Food Restaurant In Columbus OH| Layla’s Kitchen Indian Restaurant If you're looking for a truly authentic https://www.laylaskitchenrestaurantohio.com/ , Layla’s Kitchen Indian Restaurant is your go-to destination. Located at 6152 Cleveland Ave, Colu…
КГ
Кирилл Гусарев27. September 2024 09:09
Не запускается программа на Qt: точка входа в процедуру не найдена в библиотеке DLL Написал программу на C++ Qt в Qt Creator, сбилдил Release с помощью MinGW 64-bit, бинарнику напихал dll-ки с помощью windeployqt.exe. При попытке запуска моей сбилженной программы выдаёт три оши…
F
Fynjy22. Juli 2024 04:15
при создании qml проекта Kits есть но недоступны для выбора Поставил Qt Creator 11.0.2. Qt 6.4.3 При создании проекта Qml не могу выбрать Kits, они все недоступны, хотя настроены и при создании обычного Qt Widget приложения их можно выбрать. В чем может …

Folgen Sie uns in sozialen Netzwerken