Skip to content

Instantly share code, notes, and snippets.

@sfan5 sfan5/ilbot_log_line2.sql
Last active Apr 9, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.