![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
What I need to do is to convert a field to its equivalent in ASCII mode, so that I can perform searches with accented characters (ISO8850-1). Please consider table with three fields: id, text_accented, text_ascii Now, what I do is: 0. Only id and text_accented are filled up. 1. dump table with field of accented characters; 2. iconv the dump file to ASCII 3. import the dump to another schema 4. update initial table, the ASCII field, with text from the new table. This process is time consuming and very manual. Is there a way I can do it with a single update command or with a trigger? I don't find a suitable function for this. |
|
| *id* || *text_accented* || | 1 || Árbol || |
#3
| |||
| |||
|
|
El 21/03/2011 23:40, Luis P. Mendes escribió/wrote: What I need to do is to convert a field to its equivalent in ASCII mode, so that I can perform searches with accented characters (ISO8850-1). Please consider table with three fields: id, text_accented, text_ascii Now, what I do is: 0. Only id and text_accented are filled up. 1. dump table with field of accented characters; 2. iconv the dump file to ASCII 3. import the dump to another schema 4. update initial table, the ASCII field, with text from the new table. This process is time consuming and very manual. Is there a way I can do it with a single update command or with a trigger? I don't find a suitable function for this. The usual approach is to set a proper collation and let MySQL do the search... CREATE TABLE `test` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `text_accented` VARCHAR(50) NULL COLLATE 'latin1_spanish_ci', PRIMARY KEY (`id`) ) ENGINE=InnoDB; INSERT INTO test (text_accented) VALUES ('Árbol'), ('Café'), ('Cañón'); SELECT * FROM test WHERE text_accented = 'arbol'; || *id* || *text_accented* || || 1 || Árbol || I'm using 'latin_general_ci' for portuguese characters. |
#4
| |||
| |||
|
|
Tue, 22 Mar 2011 09:26:19 +0100, Álvaro G. Vicario escreveu: El 21/03/2011 23:40, Luis P. Mendes escribió/wrote: What I need to do is to convert a field to its equivalent in ASCII mode, so that I can perform searches with accented characters (ISO8850-1). Please consider table with three fields: id, text_accented, text_ascii Now, what I do is: 0. Only id and text_accented are filled up. 1. dump table with field of accented characters; 2. iconv the dump file to ASCII 3. import the dump to another schema 4. update initial table, the ASCII field, with text from the new table. This process is time consuming and very manual. Is there a way I can do it with a single update command or with a trigger? I don't find a suitable function for this. The usual approach is to set a proper collation and let MySQL do the search... CREATE TABLE `test` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `text_accented` VARCHAR(50) NULL COLLATE 'latin1_spanish_ci', PRIMARY KEY (`id`) ) ENGINE=InnoDB; INSERT INTO test (text_accented) VALUES ('Árbol'), ('Café'), ('Cañón'); SELECT * FROM test WHERE text_accented = 'arbol'; || *id* || *text_accented* || || 1 || Árbol || I'm using 'latin_general_ci' for portuguese characters. With this collation, searches do not returned similar accented words. It seems that I should change the collation to 'latin1_spanish_ci'. Or is there any other possibility? |
|
| *id* || *text_accented* || | 4 || coração || | 5 || consciência || |
#5
| |||
| |||
|
|
I'm using 'latin_general_ci' for portuguese characters. With this collation, searches do not returned similar accented words. It seems that I should change the collation to 'latin1_spanish_ci'. Or is there any other possibility? There doesn't seem to be a specific collation for Portuguese: http://dev.mysql.com/doc/refman/5.1/...-charsets.html However, the Spanish Latin1 collation appears to handle Portuguese characters as expected: INSERT INTO test (text_accented) VALUES ('coração'), ('consciência'); SELECT * FROM test WHERE text_accented = 'CORACAO' OR text_accented = 'CONSCIENCIA'; || *id* || *text_accented* || || 4 || coração || || 5 || consciência || In any case, you should have a look at the available charsets and make some tests to check that all Portuguese chars are found and you get the correct alphabetical order when doing an ORDER BY. Thank you very much! |
![]() |
| Thread Tools | |
| Display Modes | |
| |