Linux PYPYODBC read GB encoding MDB Chinese garbled solution

Source: Internet
Author: User
Tags odbc

The current 1.3.3 version of PYPYODBC on the Linux system has been able to read the MDB file with Chinese characters, no exception, but read the Chinese characters are all garbled.

The following are reasonable inferences based on a number of phenomena:

MDB files from the Windows system, where the Chinese characters using GB encoding is no doubt, but Linux system on the Mdbtools provided by the ODBC driver layer has been encoded conversion, the GB code into Unicode code, PYPYODBC again to convert so there is a problem.

The Pypyodbc.connect function has a parameter unicode_results, which defaults to true on the Python3 version, which returns a Unicode-encoded result set.

ODBC low-level drive conversion once encoded, PYPYODBC again, the tragedy inevitably appeared.

So the unicode_results of the Connect function is false, which means that the result set is returned as is, and then the field name and field values in the result set need to be decoded to a Unicode string:

$ python3
>>> conn=pypyodbc.connect (' Driver=mdbtools;dbq=/path/to/record.mdb ', unicode_results=false)
>>> conn.cursor (). Execute (' SELECT * from Build '). Fetchone () [0].decode (' UTF-8 ')

The decode (' utf-8′) decoding was successful, indicating that the result set returned by the ODBC driver for Mdbtools is already a Unicode encoded format.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.