Edgewall Software
Modify

Opened 11 years ago

Closed 11 years ago

#11310 closed defect (fixed)

MySQLConnector.to_sql() ignores utf8mb4 if a plugin or a db-upgrade call

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 0.12.6
Component: database backend Version: 0.12-stable
Severity: normal Keywords: mysql utf8mb4
Cc: Branch:
Release Notes:

Fix MySQLConnector.to_sql() on mysql with utf8mb4 via Trac plugins and db upgrades

API Changes:
Internal Changes:

Description

Some plugins and db-upgrades call directly DatabaseManager(env).get_connector() and IDatabaseConnector.to_sql() to create tables. However, if the database is mysql with utf8mb4 charset, to_sql() generates DDL for utf8 charset.

We should handle utf8m4 charset in this case.

$ ~/venv/trac/0.12.5/bin/python
Python 2.4.3 (#1, Jan  9 2013, 06:49:54)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.env import open_environment
>>> from trac.db.api import DatabaseManager
>>> from trac.db.schema import Table, Column
>>> env = open_environment('/home/jun66j5/var/trac/0.12-mysql-utf8mb4')
>>> connector, args = DatabaseManager(env).get_connector()
>>> tab = Table('test', key='id')[Column('id'),]
>>> list(connector.to_sql(tab))
['CREATE TABLE test (\n    `id` text,\n    PRIMARY KEY (`id`(255))\n)']

Attachments (0)

Change History (2)

comment:1 by Jun Omae, 11 years ago

Owner: set to Jun Omae
Status: newassigned

The proposal fix can be found in [25abfaf1/jomae.git]. After the changes, to_sql() handles utf8mb4.

Python 2.4.3 (#1, Jan  9 2013, 06:49:54)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.env import open_environment
>>> from trac.db.api import DatabaseManager
>>> from trac.db.schema import Table, Column
>>> env = open_environment('/home/jun66j5/var/trac/0.12-mysql-utf8mb4')
>>> connector, args = DatabaseManager(env).get_connector()
>>> tab = Table('test', key='id')[Column('id'),]
>>> list(connector.to_sql(tab))
['CREATE TABLE test (\n    `id` text,\n    PRIMARY KEY (`id`(191))\n)']
Version 0, edited 11 years ago by Jun Omae (next)

comment:2 by Jun Omae, 11 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Fixed in [12096] and merged in [12097-12098].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.