Prettify Messages on MySQL-MariaDB with Common_schema

Posted by in MariaDB, MySQL

One feature I really like about Common_schema is writtin messages that describe what is happening on a procedure during execution, and once finished, show the message created splitting in several “lines”.

Basicaly, I execute a task on a stored procedure while compliting the message. There is a separator that is the “key” of all this process. Let’s write a test stored procedure to see an example:

CREATE PROCEDURE `probando`()
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
# Config Message y Separator
SET @message := ''; -- Mensaje
SET @sep := '\n'; -- Separador de Mensajes

SET @message := CONCAT(@message, 'Linea 1', @sep);
SET @message := CONCAT(@message, 'Linea 2', @sep);


# Mensaje de ejecución de CREACION de TABLAS CRUZADAS
CALL common_schema.prettify_message('Ejemplo', common_schema.trim_wspace(@message));

END

In my opinion, when you have to work with long stored procedures, it’s a good idea to show the user what had happend during execution, and instead of using SELECTs, create a message where each line will be separated by a separator. I think this option is elegant. Here you have the result of executing this example:

Probando prettify_message

Probando prettify_message

Have a nice day, and I hope you use it a lot!

NOTE about a MySQL Bug onHeidiSQL:

When you show the code behind a stored procedure that include a \n , it’s possible that you don’t see it the right way. It’s a MySQL but, as you can read here and here. I include this note because I asked on the heidiSQL forum.