¿Por qué las variables de activación de MySQL no pueden manejar caracteres especiales?

I've got a table where all fields are set to 'utf8_general_ci'. There's a trigger on the table which captures data changes and inserts them into a 'log' table.

The trigger has a variable (var_row_data) which stores the updated row's old data, and that variable is then inserted into the log table. However, somehow MySQL throws an exception each time a special character (e.g ł and ń) is part of the data stored in the trigger variable.

Am I missing something about trigger variables and their encoding? Connections are using utf8, tables are utf8, webpages are utf8. In short; MySQL handles the special characters just fine but once the trigger tries to store the special characters it all goes wrong.

Does anyone have any experience with this? There's apparently something going on with the trigger variables, but I just don't understand how to get around it.

For the record, here's the trigger:

DROP TRIGGER IF EXISTS `SYM_ON_U_FOR_VRBLS_WBPRD`//
CREATE TRIGGER `SYM_ON_U_FOR_VRBLS_WBPRD` AFTER UPDATE ON `variables`
 FOR EACH ROW begin
                                  DECLARE var_row_data mediumtext;
                                  DECLARE var_old_data mediumtext;
                                  if 1=1 and @sync_triggers_disabled is null then
                                    set var_row_data = concat(
          if(new.`id` is null,'',concat('"',cast(new.`id` as char),'"')),',',
          if(new.`variable` is null,'',concat('"',replace(replace(new.`variable`,'\','\\'),'"','\"'),'"')),',',
          if(new.`value` is null,'',concat('"',replace(replace(new.`value`,'\','\\'),'"','\"'),'"')));
                                    set var_old_data = concat(
          if(old.`id` is null,'',concat('"',cast(old.`id` as char),'"')),',',
          if(old.`variable` is null,'',concat('"',replace(replace(old.`variable`,'\','\\'),'"','\"'),'"')),',',
          if(old.`value` is null,'',concat('"',replace(replace(old.`value`,'\','\\'),'"','\"'),'"')));
                                    if 1=1 then 
                                        insert into trackerdatabase_production_synch.sym_data (table_name, event_type, trigger_hist_id, pk_data, row_data, old_data, channel_id, transaction_id, source_node_id, external_data, create_time)
                                        values(
                                          'variables',
                                          'U',
                                          18,
                                          concat(
          if(old.`id` is null,'',concat('"',cast(old.`id` as char),'"'))
                                           ),
                                          var_row_data,
                                          var_old_data,
                                          'default', trackerdatabase_production_synch.sym_transaction_id(), @sync_node_disabled,
                                          null,
                                          CURRENT_TIMESTAMP
                                        );
                                    end if;
                                  end if;
                                end
//

preguntado el 01 de febrero de 12 a las 14:02

The error message is "#1366 - Incorrect string value: '\xC5\x84 s"' for column 'var_row_data' at row 1" -

1 Respuestas

Quizás:

DECLARE var_row_data MEDIUMTEXT CHARACTER SET utf8;

Respondido 01 Feb 12, 18:02

I haven't been able to find documentation for declaration of triggers. Does any documentation define character sets for triggers? - sbrattla

I don't think triggers have character sets. I think the variables you declare inside of them do. - schtever

I'll try that and come back with an update of how it went. Just need to figure out an easy way to edit the triggers. - sbrattla

It worked! Thanks! I've written a summary of my issue at another forum for SymmetricDS if your'e interested. sourceforge.net/projects/symmetricds/forums/forum/739236/topic/… - sbrattla

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.