<?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="pkuong">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="false">
			CREATE DEFINER = 'theorchard'@'10.10.%' FUNCTION stripSpecialChars(dirty_string VARCHAR(2048)) RETURNS VARCHAR(2048) CHARSET utf8
			BEGIN
			/**
			 * MySQL function to remove Special characters: \t, \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: stripSpeciaChars(string);
			 * Usage SQL> SELECT stripSpeciaChars("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">
				DROP FUNCTION IF EXISTS stripSpecialChars;
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>