How can I be dry in column names in this MySQL procedure?

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
    -- Calculate ETag on meta fields only
    UPDATE meta
    SET etag = etag(CONCAT(name, description, user_id))
    WHERE id = meta_id;
ELSE
    -- Calculate Etag on meta fields and meta customers
    BEGIN
        DECLARE c_etags VARCHAR(32);

        -- Compute c_etags

        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 //

-- First call
CALL set_meta_etag(meta_id, NULL);

-- Second call
CALL set_meta_etag(meta_id, c_etags);

INSERT.

+5
2

( foreach, , , etag) SQL , SQL , .

, SQL (Java, PHP ..), .

" sql", , . .

SQL MySQL

PREPARE EXECUTE .

, , , . , , "[etag]" .

information_schema.COLUMNS.COLUMN_COMMENT

, .

0

, , . AFTER INSERT, UPDATE. . MySQL Fire Trigger .

0

All Articles