Rename set_sys_config() to sys_get_config() and do not check whether the corresponding user variable already is set. There is little benefit checking whether the user variable is already set as sys_get_config() may be used from functions, e.g. format_statement() that in some cases is called for each row in a result set (see e.g. the processlist view) and it'll anyway be necessary to check whether the user variable is set in the parent program to avoid an additional unnecessary procedure call for each invokation. Removing the check for whether the user variable has already been set also greatly simplifies the sys_get_config() procedure.
Convert sys_get_config() to a function and return the value for the configuration option. This is needed as it can otherwise not be used by functions as dynamic SQL is not allowed in functions. This also removes the need to have a user variable in sys_get_config() for storing the value as that was only required due to the use of a prepared statement.
Change format_statement() to use the new sys_get_config() function
Change so the format_statement sys config option for the max length of a formatted statement is sys.statement_truncate_len instead of statement_truncate_len