diff roundup/backends/back_mysql.py @ 7860:8b31893f5930

issue2551115/issue2551282 - utf8mb4 support in roundup Fix issues with utf8 support in Roundup. By default using: utf8mb4 charset utf8mb4_unicode_ci collation (case insensitive) utf8mb4_0900_ci collation (case sensitive) which are settable from config.ini. Sadly I couldn't come up with a way to mange these from one parameter. Doing a compatibility lookup table would have increased the maintenance burden and have me chasing MySQL changes. So I opted for the easy path and have the admins (with more MySQL experience) make the choices. Conversion directions added to upgrading.txt. I don't have any good testing for this. I was able to generate utf8/utf8mb3 tables and load a little data and convert. However this is a poor substitute for a conversion on a working tracker 8-(.
author John Rouillard <rouilj@ieee.org>
date Sat, 06 Apr 2024 22:47:25 -0400
parents 506c86823abb
children 3d7292d222d1
line wrap: on
line diff
--- a/roundup/backends/back_mysql.py	Sat Apr 06 20:37:45 2024 -0400
+++ b/roundup/backends/back_mysql.py	Sat Apr 06 22:47:25 2024 -0400
@@ -100,9 +100,13 @@
     kwargs = connection_dict(config)
     conn = MySQLdb.connect(**kwargs)
     cursor = conn.cursor()
-    command = "CREATE DATABASE %s COLLATE utf8_general_ci" % config.RDBMS_NAME
+    command = "CREATE DATABASE %s COLLATE %s" % (config.RDBMS_NAME,
+                                                 config.RDBMS_MYSQL_COLLATION)
     if sys.version_info[0] > 2:
-        command += ' CHARACTER SET utf8'
+        charset = config.RDBMS_MYSQL_CHARSET
+        if charset == 'default':
+            charset = 'utf8mb4'  # use full utf set.
+        command += ' CHARACTER SET %s' % charset
     logging.info(command)
     cursor.execute(command)
     conn.commit()
@@ -652,11 +656,15 @@
 
 
 class MysqlClass:
-    case_sensitive_equal = 'COLLATE utf8_bin ='
+
+    case_sensitive_equal = None # defined by self.get_case_sensitive_equal()
 
     # TODO: AFAIK its version dependent for MySQL
     supports_subselects = False
 
+    def get_case_sensitive_equal(self):
+        return 'COLLATE %s =' % self.db.config.RDBMS_MYSQL_BINARY_COLLATION
+
     def _subselect(self, proptree):
         ''' "I can't believe it's not a toy RDBMS"
            see, even toy RDBMSes like gadfly and sqlite can do sub-selects...

Roundup Issue Tracker: http://roundup-tracker.org/