ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
332 stars 133 forks source link

Слова на русском языке. #213

Open micruha opened 1 year ago

micruha commented 1 year ago

Здравствуйте. Подскажите пожалуйста, MySQL_Connection поддерживает отправку запросов со словами на русском языке?

void loop() { int value = random(101); String event_caption = String(shop_name) + ": " + String(value) + " посетителей."; String event_message = String(shop_name) + ": " + String(value) + " посетителей."; MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn); char query[512]; sprintf(query, INSERT_DATA, db_name, table_name, event_caption.c_str(), event_message.c_str()); Serial.println(query); cur_mem->execute(query); delete cur_mem; delay(60000); }

Вместо слова " посетителей." в таблицу записывается " посетителей." В мониторинге порта Serial.println(query); выводится слово " посетителей.", а до таблицы доходят каракули.

ChuckBell commented 1 year ago

I am sorry, but could you please post in English? Also, please include the INSERT_DATA string. Thanks.

On May 26, 2023, at 4:07 AM, micruha @.***> wrote:

Здравствуйте. Подскажите пожалуйста, MySQL_Connection поддерживает отправку запросов со словами на русском языке?

void loop() { int value = random(101); String event_caption = String(shop_name) + ": " + String(value) + " посетителей."; String event_message = String(shop_name) + ": " + String(value) + " посетителей."; MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn); char query[512]; sprintf(query, INSERT_DATA, db_name, table_name, event_caption.c_str(), event_message.c_str()); Serial.println(query); cur_mem->execute(query); delete cur_mem; delay(60000); }

Вместо слова " посетителей." в таблицу записывается " поÑ�етителей." В мониторинге порта Serial.println(query); выводится слово " посетителей.", а до таблицы доходят каракули.

— Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/213, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYBAEHXPA4EBXRXWLNDXIBQE5ANCNFSM6AAAAAAYP4GI6E. You are receiving this because you are subscribed to this thread.

micruha commented 1 year ago

Hello. Please tell me, does MySQL_Connection support sending queries with words in Russian?

char db_name[] = "testdatabase"; char table_name[] = "org_events"; char shop_name[] = "Maximum"; //Пока только на английском языке. char INSERT_DATA[] = "INSERT INTO %s.%s (event_caption, event_type, start_date, finish_date, label_color, event_message, event_options, recurrence_idx, reminder_date, reminder_min_before_start, resource_id, event_state, doc_id, project_id) VALUES ('%s', 0, CURDATE(), DATE_ADD(CURDATE(), INTERVAL 1 DAY), '536870912', '%s', 3, -1, NOW(), 15, 0, 0, 0, 1)";

void loop() { int value = random(101); String event_caption = String(shop_name) + ": " + String(value) + " посетителей."; String event_message = String(shop_name) + ": " + String(value) + " посетителей."; MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn); char query[512]; sprintf(query, INSERT_DATA, db_name, table_name, event_caption.c_str(), event_message.c_str()); Serial.println(query); cur_mem->execute(query); delete cur_mem; delay(60000); }

Instead of the word " посетителей.", the table is written " Ð¿Ð¾Ñ ÐµÑ‚Ð¸Ñ‚ÐµÐ»ÐµÐ¹." In port monitoring Serial.println(query); the word " посетителей." is displayed, and doodles reach the table.

ChuckBell commented 1 year ago

Hi. I have not tried the Russian language, but if MySQL is configured to support it and the chars are 1-byte each, it should work, but I know it does not support 2-byte chars.

On May 27, 2023, at 1:17 PM, micruha @.***> wrote:

Hello. Please tell me, does MySQL_Connection support sending queries with words in Russian?

char table_name[] = "org_events"; char shop_name[] = "Maximum"; //Пока только на английском языке. char INSERT_DATA[] = "INSERT INTO %s.%s (event_caption, event_type, start_date, finish_date, label_color, event_message, event_options, recurrence_idx, reminder_date, reminder_min_before_start, resource_id, event_state, doc_id, project_id) VALUES ('%s', 0, CURDATE(), DATE_ADD(CURDATE(), INTERVAL 1 DAY), '536870912', '%s', 3, -1, NOW(), 15, 0, 0, 0, 1)";

void loop() { int value = random(101); String event_caption = String(shop_name) + ": " + String(value) + " посетителей."; String event_message = String(shop_name) + ": " + String(value) + " посетителей."; MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn); char query[512]; sprintf(query, INSERT_DATA, db_name, table_name, event_caption.c_str(), event_message.c_str()); Serial.println(query); cur_mem->execute(query); delete cur_mem; delay(60000); }

Instead of the word " visitors.", the table is written " Ð¿Ð¾Ñ ÐµÑ‚Ð¸Ñ‚ÐµÐ»ÐµÐ¹." In port monitoring Serial.println(query); the word " visitors" is displayed.", and doodles reach the table.

— Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/213#issuecomment-1565603886, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYHFUMT5EFBMX4MXYZTXIIZMHANCNFSM6AAAAAAYP4GI6E. You are receiving this because you commented.

micruha commented 1 year ago

Russian Russian letters are freely supported by MySQL, and in Serial.println(query); text with Russian letters is displayed, which is sent to the table, and incorrectly interpreted characters are written to the table. Is there any plans to support Russian letters?

ChuckBell commented 1 year ago

Hi. Not immediately, now, but let’s leave this request open and I’ll look into it. Or you can if you’d like. :)

On May 27, 2023, at 1:28 PM, micruha @.***> wrote:

Russian Russian letters are freely supported by MySQL, and in Serial.println(query); text with Russian letters is displayed, which is sent to the table, and incorrectly interpreted characters are written to the table. Is there any plans to support Russian letters?

— Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/213#issuecomment-1565607710, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYATUUBOLLPFXOMCLBDXII2THANCNFSM6AAAAAAYP4GI6E. You are receiving this because you commented.

micruha commented 1 year ago

I'm not good at programming. Everything I can do is thanks to ChatGPT, but all the advice he gives me on fixing my code doesn't work.

ChuckBell commented 1 year ago

Do you know which collation you are using in MySQL? If you can identify a charset/collation, I may be able to suggest a quick hack to make it work. Is it one of these? If so, which one?

https://dev.mysql.com/doc/refman/8.0/en/charset-cyrillic-sets.html

On May 27, 2023, at 1:35 PM, micruha @.***> wrote:

I'm not good at programming. Everything I can do is thanks to ChatGPT, but all the advice he gives me on fixing my code doesn't work.

— Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/213#issuecomment-1565609995, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYCOMAMNWAUOAASM7VTXII3OZANCNFSM6AAAAAAYP4GI6E. You are receiving this because you commented.

ChuckBell commented 1 year ago

Basically, open MySQL_Packet.cpp and change line#122 to set the charset number from 08 to whatever you want. For example, the following are the Cyrillic charsets that MySQL supports.

mysql> SELECT id, collation_name FROM information_schema.collations WHERE collation_name like '%1251%' ORDER BY id; +----+---------------------+ | id | collation_name | +----+---------------------+ | 14 | cp1251_bulgarian_ci | | 23 | cp1251_ukrainian_ci | | 50 | cp1251_bin | | 51 | cp1251_general_ci | | 52 | cp1251_general_cs | +----+---------------------+ 5 rows in set (0.00 sec)

For example, suppose your desired charset if cp1251_general_ci, which is id = 51. We convert it to hex (0x33) and change:

// charset - default is 8 buffer[size_send] = byte(0x08); To:

// charset - default is 8 buffer[size_send] = byte(0x33); // cp1251_general_ci

This should work and worth a try. If you get a chance to try it, let me know if it works. If it does, I will put it on the list for the next revision.

On May 27, 2023, at 3:01 PM, Charles Bell @.***> wrote:

Do you know which collation you are using in MySQL? If you can identify a charset/collation, I may be able to suggest a quick hack to make it work. Is it one of these? If so, which one?

https://dev.mysql.com/doc/refman/8.0/en/charset-cyrillic-sets.html

On May 27, 2023, at 1:35 PM, micruha @.***> wrote:

I'm not good at programming. Everything I can do is thanks to ChatGPT, but all the advice he gives me on fixing my code doesn't work.

— Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/213#issuecomment-1565609995, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYCOMAMNWAUOAASM7VTXII3OZANCNFSM6AAAAAAYP4GI6E. You are receiving this because you commented.

micruha commented 1 year ago

Знаете ли вы, какое сопоставление вы используете в MySQL? Если вы можете определить кодировку/сопоставление, я могу предложить быстрый хак, чтобы заставить его работать. Это один из них? Если да, то какой? https://dev.mysql.com/doc/refman/8.0/en/charset-cyrillic-sets.html On May 27, 2023, at 1:35 PM, micruha @.***> wrote: I'm not good at programming. Everything I can do is thanks to ChatGPT, but all the advice he gives me on fixing my code doesn't work. — Reply to this email directly, view it on GitHub <#213 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYCOMAMNWAUOAASM7VTXII3OZANCNFSM6AAAAAAYP4GI6E. You are receiving this because you commented.

image

micruha commented 1 year ago

I can't change anything in the MySQL database, because a trade accounting program works with its tables. If I change MySQL parameters, then my program stops working correctly. I am assembling an Arduino device that sends some data to the MySQL database tables of the program. I adjust my device to the DB, not the DB to my device.

ChuckBell commented 1 year ago

You need not change the DB. The suggested code changes the connector on your Arduino to match the character set on the DB.

On Sat, May 27, 2023 at 15:34 micruha @.***> wrote:

I can't change anything in the MySQL database, because a trade accounting program works with its tables. If I change MySQL parameters, then my program stops working correctly. I am assembling an Arduino device that sends some data to the MySQL database tables of the program. I adjust my device to the DB, not the DB to my device.

— Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/213#issuecomment-1565658699, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYC4KLC6V36LE3T54KLXIJJMBANCNFSM6AAAAAAYP4GI6E . You are receiving this because you commented.Message ID: @.***>

micruha commented 1 year ago

I'm sorry, I didn't understand you. I'm not a programmer and I don't understand many terms. I need time to understand what you wrote to me. I will study all your answers and come back with the results.

micruha commented 1 year ago

I'm sitting now, trying to understand your answer and change the sketch code. WhatsApp Image 2023-05-28 at 02 47 59

micruha commented 1 year ago

That's it, got it. I'll check it out now.

micruha commented 1 year ago

buffer[size_send] = byte(0x33); it didn't work. Signed up for the table - Maximum: 16 посетителей. image

ChuckBell commented 1 year ago

The connector can be altered to support Russian. Here’s how you do it. It’s a multi-step process.

First, modify MySQL_Packet.cpp as suggested only use 0x24 (for charset cp866). buffer[size_send] = byte(0x24); Next, create (or alter) your table to use that character set and default collation for the column(s) you want to support.

CREATE TABLE test.lang (a int auto_increment primary key, b char(40) charset cp866 collate cp866_general_ci);

Next, change the charset in the MySQL monitor (mysql) to use the new charset.

mysql> \C cp866 Charset changed

Finally, execute your script. I wrote a simple INSERT to use the phrase, “правильная фраза”.

Observe:

mysql> select * from test.lang; +---+---------------------------------+ | a | b | +---+---------------------------------+ | 1 | правильная фраза | +---+---------------------------------+ 1 row in set (0.00 sec)

Done. :)

On May 27, 2023, at 4:06 PM, micruha @.***> wrote:

buffer[size_send] = byte(0x33); it didn't work. Signed up for the table - Maximum: 16 посетителей. https://user-images.githubusercontent.com/120698813/241428102-e1575df9-672c-40ec-a3d1-e8132bc1be3f.png — Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/213#issuecomment-1565663390, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYBJYTKLEAR7CDRWZVTXIJNCRANCNFSM6AAAAAAYP4GI6E. You are receiving this because you commented.