<commit_before>-- Procedure to add a new language in the database.
-- 1) Add it in 'languages' table.
-- 2) Update the 'lang' field of the sentences involved.
-- 3) Update the count in the 'languages' table.
--
-- Example:
-- CALL add_new_language('gla', 412);
--
-- If there is no list:
-- CALL add_new_language('gla', 0);

DELIMITER |

DROP PROCEDURE IF EXISTS add_new_language |

CREATE PROCEDURE add_new_language(IN lang_iso_code CHAR(4), IN list_id_for_lang INT)
ThisProc: BEGIN

SELECT COUNT(*) INTO @code_found FROM languages WHERE code = lang_iso_code;
IF NOT (@code_found = 0) THEN
    SELECT CONCAT('Language code ', lang_iso_code, ' has already been added.');
END IF;
-- We know this will fail when the language already exists, but we want the exception
-- to occur so the caller will catch it.
INSERT INTO languages (code) VALUES (lang_iso_code);

SELECT COUNT(*) INTO @sentences_in_list FROM sentences, sentences_sentences_lists
    WHERE sentences_list_id = list_id_for_lang AND sentences.id = sentence_id;

IF (@sentences_in_list = 0) THEN
    select CONCAT('There are no sentences in list ', list_id_for_lang);
    LEAVE ThisProc;
END IF;

UPDATE sentences, sentences_sentences_lists
    SET lang = lang_iso_code
    WHERE sentences_list_id = list_id_for_lang
    AND sentences.id = sentence_id;
UPDATE languages
    SET sentences = (SELECT count(*) FROM sentences WHERE lang = lang_iso_code)
    WHERE code = lang_iso_code;

END |

DELIMITER ;<commit_msg>Add better labels for the error messages<commit_after>-- Procedure to add a new language in the database.
-- 1) Add it in 'languages' table.
-- 2) Update the 'lang' field of the sentences involved.
-- 3) Update the count in the 'languages' table.
--
-- Example:
-- CALL add_new_language('gla', 412);
--
-- If there is no list:
-- CALL add_new_language('gla', 0);

DELIMITER |

DROP PROCEDURE IF EXISTS add_new_language |

CREATE PROCEDURE add_new_language(IN lang_iso_code CHAR(4), IN list_id_for_lang INT)
ThisProc: BEGIN

SELECT COUNT(*) INTO @code_found FROM languages WHERE code = lang_iso_code;
IF NOT (@code_found = 0) THEN
    SELECT CONCAT('Language code ', lang_iso_code, ' has already been added.') AS Error;
END IF;
-- We know this will fail when the language already exists, but we want the exception
-- to occur so the caller will catch it.
INSERT INTO languages (code) VALUES (lang_iso_code);

SELECT COUNT(*) INTO @sentences_in_list FROM sentences, sentences_sentences_lists
    WHERE sentences_list_id = list_id_for_lang AND sentences.id = sentence_id;

IF (@sentences_in_list = 0) THEN
    select CONCAT('There are no sentences in list ', list_id_for_lang) AS Warning;
    LEAVE ThisProc;
END IF;

UPDATE sentences, sentences_sentences_lists
    SET lang = lang_iso_code
    WHERE sentences_list_id = list_id_for_lang
    AND sentences.id = sentence_id;
UPDATE languages
    SET sentences = (SELECT count(*) FROM sentences WHERE lang = lang_iso_code)
    WHERE code = lang_iso_code;

END |

DELIMITER ;
{'fraction_non_alphanumeric': 0.08559010364426613, 'fraction_numerical': 0.006686726847208292, 'mean_word_length': 4.314387211367674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2002924', 'n_tokens_mistral': 981, 'n_tokens_neox': 924, 'n_words': 352}