<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <changeSet id="1" author="vbogatyrev">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            USE accountingflat;;

            CREATE DEFINER = 'theorchard'@'10.10.%' FUNCTION stripSpecialCharsLong(dirty_string TEXT)
                RETURNS TEXT CHARSET utf8
            DETERMINISTIC

            BEGIN
            /**
             * MySQL function to remove Special characters: \n, \t, \r and replace blank when null
             * @param VARCHAR dirty_string : dirty string as input
             * @return VARCHAR clean_string : clean string as output
             *
             * Usage Syntax: stripSpecialCharsLong(string);
             * Usage SQL> SELECT stripSpecialCharsLong("sdfa7987\t\n\ru");
             * result : 'sdfa7987u'
             */
              RETURN IFNULL(TRIM(REPLACE(REPLACE(REPLACE(dirty_string,'\t',''),'\n',''),'\r','')),'');
            END;;

        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                USE accountingflat;;

                DROP FUNCTION IF EXISTS stripSpecialCharsLong;;
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
