Ich habe eine gespeicherte Prozedur verwendet, die einen Cursor zum Durchlaufen und Verarbeiten einer Anwesenheitsdatentabelle in der Mariadb 10.1-Datenbank nach dem ersten Aufruf aller Tabellen in der Datenbank verwendet ausführen INSERT INTO oder UPDATE-Anweisungen, wenn die Zieltabelle zuerst abgeschnitten wird, kann jemand mir sagen, was schief gelaufen ist und wie es das Verfahren zu beheben, die das Problem verursacht:Alle Tabellen können 'INSERT' oder 'UPDATE' nicht ausführen
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `settle_attendance`()
MODIFIES SQL DATA
BEGIN
DECLARE trans_done BOOLEAN DEFAULT FALSE;
DECLARE punchid BIGINT(20);
DECLARE timein DATETIME;
DECLARE utctimein DATETIME;
DECLARE timeout DATETIME;
DECLARE utctimeout DATETIME;
DECLARE inday DATE;
DECLARE outday DATE;
DECLARE todaysdate DATE;
DECLARE attendcur CURSOR FOR
SELECT id, punch_in_utc_time, punch_in_user_time,
punch_out_utc_time, punch_out_user_time
FROM ohrm_attendance_record
ORDER BY id ASC;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET trans_done = TRUE;
OPEN attendcur;
edit_loop: LOOP
SET todaysdate = CURRENT_DATE();
FETCH attendcur INTO punchid, utctimein, timein, utctimeout, timeout;
IF trans_done THEN
CLOSE attendcur;
LEAVE edit_loop;
END IF;
SET inday = DATE(timein);
SET outday = DATE(timeout);
SET todaysdate = CURRENT_DATE();
IF (inday < todaysdate) OR (outday < todaysdate) THEN
CASE
WHEN (timein IS NULL OR timein = '')
OR (utctimein IS NULL OR utctimein = '') THEN
UPDATE ohrm_attendance_record
SET punch_in_utc_time = utctimeout,
punch_in_user_time = timeout,
state = 'PUNCHED OUT'
WHERE punchid = id;
ELSE BEGIN END;
END CASE;
CASE
WHEN (timeout IS NULL OR timeout = '')
OR (utctimeout IS NULL OR utctimeout = '') THEN
UPDATE ohrm_attendance_record
SET punch_out_utc_time = utctimein,
punch_out_user_time = timein,
state = 'PUNCHED OUT'
WHERE punchid = id;
ELSE BEGIN END;
END CASE;
END IF;
END LOOP edit_loop;
END $$
DELIMITER ;
Was meinen Sie mit "Tabellen verloren die Fähigkeit, INSERT durchzuführen"? Wenn Sie Fehler bekommen, fügen Sie sie wörtlich zu Ihrer Frage hinzu. – mustaccio
Wenn ich eine Abfrage manuell ausführen, funktioniert es, aber es funktioniert nicht in der gespeicherten Prozedur –