Skip to content

Instantly share code, notes, and snippets.

@sfan5
Last active April 9, 2017 11:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sfan5/9242511ca9718d98457edd864111b0c8 to your computer and use it in GitHub Desktop.
DELIMITER //
CREATE PROCEDURE `ilbot_log_line2`(IN p_time TIMESTAMP, IN p_channel VARCHAR(30), IN p_nick VARCHAR(40), IN p_line mediumtext)
LANGUAGE SQL
NOT DETERMINISTIC
SQL SECURITY INVOKER
COMMENT 'Log a line from IRC with custom timestamp'
BEGIN
DECLARE channel_id, day_id INT(11);
DECLARE today CHAR(10);
START TRANSACTION;
SELECT id INTO channel_id FROM ilbot_channel WHERE channel = p_channel;
IF (channel_id IS NULL) THEN BEGIN
INSERT INTO ilbot_channel (channel) VALUES (p_channel);
SELECT id INTO channel_id FROM ilbot_channel WHERE channel = p_channel;
END; END IF;
SELECT DATE(p_time) INTO today;
SELECT id INTO day_id FROM ilbot_day WHERE channel = channel_id AND day = today;
IF (day_id IS NULL) THEN BEGIN
INSERT INTO ilbot_day (channel, day) VALUES (channel_id, today);
SELECT id INTO day_id FROM ilbot_day WHERE channel = channel_id AND day = today;
END; END IF;
INSERT INTO ilbot_lines (day, nick, timestamp, line)
VALUES(day_id, p_nick, UNIX_TIMESTAMP(p_time), p_line);
COMMIT;
END//
-- Use like this: (make sure to have the correct timezone!)
--CALL ilbot_log_line2('2017-04-09 10:24:06', '#channel-name', 'le_person', 'hey gaise xdd');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment