2

I'm getting strange response to MySQL query. I tested the same query in Go with database/SQL module and in PHP mysqli. In PHP polish symbols are working but in Go when I log the response I'm getting something like this:

2022/10/12 13:32:24 Drukarka 3D CR-200B - wkr�tce dost�pne
2022/10/12 13:32:24 Drukarka 3D ED V1 PRO
2022/10/12 13:32:24 Drukarka 3D CR-3040 PRO - wkr�tce dost�pne
2022/10/12 13:32:24 Mikrokontroler BBC micro:bit
2022/10/12 13:32:24 Zestaw Startowy micro:bit
2022/10/12 13:32:24 Niesamowity Samoch�d
2022/10/12 13:32:24 EduBot
2022/10/12 13:32:24 EduDron
2022/10/12 13:32:24 Kreatywny Konstruktor
2022/10/12 13:32:24 Innowacyjny In�ynier
2022/10/12 13:32:24 Matatalab Pro - wkr�tce dost�pne
2022/10/12 13:32:24 Matatalab TaleBot - wkr�tce dost�pne
2022/10/12 13:32:24 Matatalab Lite - wkr�tce dost�pne

Go code:

            var products []models.Product
            var product models.Product
            
            rows, _ := db.Query("select title from products")
            defer rows.Close()

            for rows.Next() {
                rows.Scan(&product.Title)
                title := utf8string.NewString(product.Title)
                log.Println(fmt.Sprint(title))
                products = append(products, product)
            }

            json.NewEncoder(w).Encode(products)

MySQL table:

CREATE TABLE `products` (
  `title` mediumtext COLLATE utf8mb4_polish_ci NOT NULL,
  `description` mediumtext COLLATE utf8mb4_polish_ci NOT NULL,
  `content` varchar(1024) COLLATE utf8mb4_polish_ci DEFAULT NULL,
  `isVisible` int(11) DEFAULT NULL,
  `id` bigint(20) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_polish_ci;


INSERT INTO `products` (`title`, `description`, `content`, `isVisible`, `id`) VALUES
('Mikrokontroler BBC micro:bit', '<a href=\"https://eduko.pl/robotyka/649-zestaw-startowy-microbit-mikrokontroler-z-czujnikami-i-akcesoriami.html\"><br/><button class=\"btn btn-primary d-none d-lg-flex\">Tutaj znajdziesz zestaw startowy micro:bit</button></a>', 'BBC micro:bit - Wprowadzenie;Scenariusze;:INDEX:;Lekcja 1;Lekcja 2;Lekcja 3;Lekcja 4;Lekcja 5;:INDEX:', 1, 4);

Anyone here knows how to solve that problem?

Stefan Wuebbe
  • 2,109
  • 5
  • 17
  • 28
  • okay, i'm closing this thread cuz i simply used charmap module and it works! :) – Norbert Wagner Oct 12 '22 at 15:44
  • 1
    If you have further troubles like this, see "black diamond" in https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Oct 13 '22 at 05:28

0 Answers0