0

I have the following problem:

I'm making an INSERT INTO with Golang, but for some reason, it's not inserting the special characters correctly (IE: ñ).

This is the SQL sentence:

ins, err := db.Prepare("INSERT INTO historico_twitter_instagram( texto_encontrado,
                        busqueda_realizada, id_usuario, link, total_reacciones, 
                        total_negativas, total_positivas, total_neutras, fecha_publicacion,
                        id_red_social,is_falso_positivo,ID_comentario) 
                        VALUES "+ fmt.Sprintf("%s",buscado))

Right above it I have a print to show in console what is supposed to insert, and it shows this:

INSERT INTO historico_twitter_instagram( texto_encontrado, busqueda_realizada,
            id_usuario, link, total_reacciones, total_negativas, total_positivas,
            total_neutras, fecha_publicacion,id_red_social,is_falso_positivo,ID_comentario)
     VALUES ('Test: ñ','@wtonki','999','','1','0','0','1','2017-10-24 00:00:00.0','2','1',
             '922923057840144384')

But in phpMyAdmin it's replacing the ñ character for other characters like ñ

The strange part is, if I execute that SQL manually, it inserts okay. Any ideas?

PS: The table structure has utf8_general_ci PS2: Sorry for my bad English! :( PS3: The SQL is executed on Go with _, err = ins.Run()

Paul T.
  • 4,703
  • 11
  • 25
  • 29
W.Tonki
  • 19
  • 3
  • [I would try utf8_unicode_ci](https://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci) – bigless Oct 24 '17 at 23:03
  • 1
    Could you check locales, connection settings for all apps? Possibly one where in the middle the letter gets corrupted. Have you tried to insert the row manually with console tool `mysql`? – Eugene Lisitsky Oct 25 '17 at 00:31
  • I already tried inserting the row manually with mysql console, and it inserts okay. I have other table that has exactly the same structure and it has no problemas inserting data with ñ characters on it via Golang – W.Tonki Oct 25 '17 at 12:09
  • Use placeholders and bind your values. Never use Sprintf. That may already fix your problem, because now the driver will take care of encoding the strings. https://play.golang.org/p/PGPB6VyBLI – Peter Oct 25 '17 at 13:59

0 Answers0