Python Forum
Who converts data when writing to a database with an encoding different from utf8?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Who converts data when writing to a database with an encoding different from utf8?
#2
If I understood the code right, there happens an implicit encoding to utf8mb4, if no other default encoding has been set.
If I'm right, this means the encoding takes 4 byte for each character. This can be something for internal optimization of MySQL itself.

Where the encoding happens: https://github.com/aio-libs/aiomysql/blo...on.py#L426
DEFAULT_CHARSET from external dependency: https://github.com/PyMySQL/PyMySQL/blob/...ons.py#L91

If you have a str, it's already encoded internally with utf8.
If your input was made with a koi8-r encoding, somewhere must happen a conversion.
For example if you enter form data on a web page, you should receive the parameters as raw bytes.
Then they need to be decoded, to be represented as str.

If the query is a str, then it is automatically encoded to utf8mb4, if no other encoding has been set somewhere.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: Who converts data when writing to a database with an encoding different from utf8? - by DeaD_EyE - Mar-04-2019, 08:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 192 Yesterday, 09:55 PM
Last Post: deanhystad
  How to detect abnormal data in big database python vanphuht91 5 1,128 Jun-27-2023, 11:22 PM
Last Post: Skaperen
  Database that can compress a column, or all data, automatically? Calab 3 1,163 May-22-2023, 03:25 AM
Last Post: Calab
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,012 Dec-06-2022, 11:09 AM
Last Post: mg24
  Basic SQL query using Py: Inserting or querying sqlite3 database not returning data marlonbown 3 1,362 Nov-08-2022, 07:16 PM
Last Post: marlonbown
  Create a function for writing to SQL data to csv mg24 4 1,151 Oct-01-2022, 04:30 AM
Last Post: mg24
  [SOLVED] [Windows] Converting filename to UTF8? Winfried 5 2,549 Sep-06-2022, 10:47 PM
Last Post: snippsat
  Need Help writing data into Excel format ajitnayak87 8 2,503 Feb-04-2022, 03:00 AM
Last Post: Jeff_t
  I need help parsing through data and creating a database using beautiful soup username369 1 1,705 Sep-22-2021, 08:45 PM
Last Post: Larz60+
  Fastest Way of Writing/Reading Data JamesA 1 2,187 Jul-27-2021, 03:52 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020