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

Error inserting utf8 character using Connection pool

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 0.9.59
    • 1.0.0
    • Performance
    • 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

          georg Georg Richter added a comment -

          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) ?

          georg Georg Richter added a comment - 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) ?
          sheldon Sheldon added a comment -

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

          sheldon Sheldon added a comment - The latest version in GitHub has solved the issue. Thank you!

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.