Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-69

Error inserting utf8 character using Connection pool

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 0.9.59
    • Fix Version/s: 1.0.0
    • Component/s: Performance
    • Labels:
    • 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 ...''')
      

        Attachments

          Activity

            People

            Assignee:
            georg Georg Richter
            Reporter:
            sheldon Sheldon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: