Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
0.9.59
-
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 ...''') |