I referig column name, descriptionand user_idtable meta. Twice, maybe more (who knows?) In the future. These columns are used to calculate the ETag of my meta resource.
Adding one column that contributes to ETag calculation in the future will force me to change the code N times, and this is bad.
Is there any way to do this DRY and save these column names elsewhere? Because I would like to use these column names when executing INSERTin meta.
IF only = true THEN
UPDATE meta
SET etag = etag(CONCAT(name, description, user_id))
WHERE id = meta_id;
ELSE
BEGIN
DECLARE c_etags VARCHAR(32);
UPDATE meta
SET etag = etag(CONCAT(etag(name, description, user_id), c_etags))
WHERE id = meta_id;
END;
END IF;
Disclaimer: this code has not been verified, I am pretty new to MySQL materials, separately for simple statements.
EDIT : etagThere is a MD5MySQL function . Perhaps this is one of the options:
CREATE PROCEDURE set_meta_etag(IN meta_id INT, IN related TEXT)
NOT DETERMINISTIC
BEGIN
UPDATE meta
SET etag = etag(CONCAT(name, description, user_id,
IF(related IS NOT NULL, related, '')))
WHERE id = meta_id;
END //
CALL set_meta_etag(meta_id, NULL);
CALL set_meta_etag(meta_id, c_etags);
INSERT.