This chapter shows how to convert a database to locale UTF8.

1 Export database

The first step is to export the database stablising the environment variables to the corresponding database current locale.

Copy
export DB_LOCALE=es_es.8859-1 (or es_es.8859-15)
export CLIENT_LOCALE=es_es.8859-1 (or es_es.8859-15)

Export the database.

Copy
dbexport database_name -ss

2 Import database

To import the database set the environment variable CLIENT_LOCALE to the current locale and DB_LOCALE to UTF8.

Copy
export DB_LOCALE=en_us.UTF8
export CLIENT_LOCALE=es_es.8859-1 (or es_es.8859-15)

Then import the database using the dbexport previously generated.

Copy
dbimport database_name in d_dbspace_name

3 Convert clobs to UTF8

Finally it is necessary to execute this XSQL-Script to convert the content in CLOB fields. This script can be execute from command line or DBStudio tool.

XSQL-Script clob2utf8

This script must be execute only one time. If you execute this script more than one time the content of columns will be corrupted.
Copy
<xsql-script>
    <body>

        <!-- WARNING: foreach clob raw read -->
        <system.setProperty name='xsqlscript.clob.raw' value='true' />
        <foreach>
            <in prefix='m_'>
                <connection.metadata.getColumns>
                    <null />
                    <null />
                    <null />
                    <null />
                </connection.metadata.getColumns>
            </in>
            <do>
                <if>
                    <expr>
                        <eq><m_data_type/>2005</eq>
                    </expr>
                    <then>
                        <println><m_table_name />.<m_column_name /> <m_data_type/></println>

                        <connection.begin />
                        <foreach>
                            <select prefix='m_' for-update='yes'>
                                <columns>
                                #m_column_name text
                                </columns>
                                <from table='#m_table_name' />
                            </select>
                            <do>
                                <update table='#m_table_name'>
                                    <column name='#m_column_name'>
                                    <m_text />
                                    </column>
                                    <where-current-of />
                                </update>
                            </do>
                        </foreach>
                        <connection.commit />

                    </then>
                </if>
            </do>
        </foreach>

    </body>
</xsql-script>