<?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="piannone">
    <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="false">
      CREATE DEFINER = 'theorchard'@'10.10.%' FUNCTION stripSpecialCharsLong(dirty_string TEXT)
        RETURNS TEXT CHARSET utf8
      DETERMINISTIC
        BEGIN
        /**
        * MySQL function to remove Special characters: \t, \n, \r and replace null with empty string
        * @param TEXT dirty_string : dirty string as input
        * @return TEXT 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">
        DROP FUNCTION IF EXISTS stripSpecialCharsLong;
      </sql>
    </rollback>
  </changeSet>
</databaseChangeLog>
