[CONPY-69] Error inserting utf8 character using Connection pool Created: 2020-06-01  Updated: 2020-06-02  Resolved: 2020-06-02

Status: Closed
Project: MariaDB Connector/Python
Component/s: Performance
Affects Version/s: 0.9.59
Fix Version/s: 1.0.0

Type: Bug Priority: Critical
Reporter: Sheldon Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: Connector, utf8
Environment:

Raspberry pi 4B, Python 3.7.3



 Description   

I'm trying to insert Chinese characters into my database. The same SQL statement works perfectly when I'm using an individual connection to execute it. However, a different behavior was observed when I'm using a connection from connection pool.

When I'm using connection pool, all Chinese characters in the SQL statement will be converted to ASCII, for example, "7.26å„„" will be stored in the database, where the number part was correct. Also, if the database name is in Chinese, "Runtime error Failed to create exception" will happen if my SQL statement was trying to use that database.

class dbConnect():
    def __init__(self, db):
        self.db = db
    def __enter__(self):
        self.db.sem.acquire()
        try:
            self.pconn = self.db.pool.get_connection()
        except mariadb.PoolError as e:
            print(e)
        
        return self.pconn
    def __exit__(self, exc_type, exc_value, exc_traceback):
        self.pconn.close()
        self.db.sem.release()
        if exc_type is not None:
            logging.info("Logging an uncaught exception",
                 exc_info=(exc_type, exc_value, exc_traceback))
        return True
 
class dbConnection:
    def __init__(self, sem, size=100):
        self.sem = sem
        self.pool = mariadb.ConnectionPool(...)
    def insertSomething(self):
        pconn = self.newConnection() #using mariadb.connect(**config)
        # with dbConnect(self) as pconn: #connection pool
        cur = pconn.cursor() 
        cur.execute(f''' INSERT INTO ...''')



 Comments   
Comment by Georg Richter [ 2020-06-01 ]

I'm not sure if my latest commit fixed all the issues - the problem not only for pooled connections but also for "normal" connection was that we send the character set not before authentication phase.

Would it be possible for you to download/clone from gitub and build it on your raspberry for checking if the fix solves your problems (and to give some feedback) ?

Comment by Sheldon [ 2020-06-02 ]

The latest version in GitHub has solved the issue.
Thank you!

Generated at Thu Feb 08 03:30:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.