[patch] Updates for MySQL backend
|Reported by:||Andy Dustman <farcepest@…>||Owned by:||mtredinnick|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||farcepest@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The patch (to be attached) is fairly heavily commented, and I intend to post a reference to this bug on django-users and encourage people to test it.
- requires MySQLdb-1.2.1 and newer.
- eliminates MysqlDebugWrapper in favor of the standard util.CursorDebugWrapper and using warning filtering to raise warnings as exceptions.
- sets character set to UTF8 in the the connection initiation
- returns non-binary character fields as unicode
- sets the server SQL mode
- ANSI makes it more SQL standards-compliant, including use of double-quotes
- TRADITIONAL mode turns warnings about bad values into errors
I've tested it with my own application and it seems to work fine. One gotcha I ran into that I actually get updates from an
external database, and the query string for that database needs strings and not unicodes, and I since I was now getting
unicode back from MySQL, I was trying to pass unicode to it, but that was easily fixed. Everything else in Django seems
to work fine for me with unicode.
- unicode values still might be breaking things; in this case, use_unicode=False should be set (charset implies use_unicode=True) as a workaround, but the plan is to make Django unicode-safe anyway, as I understand it.
- warning filtering may be redundant with TRADITIONAL mode, but not harmful.
- sql_mode is being set for ANSI,TRADITIONAL. The last options is new to MySQL-5.0, and this may cause errors for MySQL-4.1, or it might be ignored; I have only had time to test on MySQL-5.0. ANSI works going back to 4.1. ANSI_QUOTES is recognized by MySQL-4.0. If need be I can add some version tests.
The real question is, what is the earliest version of MySQL you want to support? I think either 4.1 or 5.0 would be a reasonable
cutoff, as the current stable version is 5.0, and 5.1 is in late beta, and 4.1 adds the good character set support.
Originally when I did this, I copied the mysql backend and called it mysql5, but you may not want to have multiple
backends (though there is a precedence for that). Ultimately I think it needs to be left to the end-users to decide
what the minimum version should be, since the Django developers prefer PostgreSQL.
Change History (26)
comment:8 Changed 9 years ago by Michael Radziej <mir@…>
- Triage Stage changed from Unreviewed to Design decision needed
comment:11 Changed 9 years ago by mtredinnick
- Triage Stage changed from Design decision needed to Ready for checkin
comment:13 Changed 9 years ago by mtredinnick
- Resolution set to fixed
- Status changed from new to closed
comment:14 follow-up: ↓ 17 Changed 9 years ago by derelm
- Resolution fixed deleted
- Status changed from closed to reopened
comment:16 Changed 9 years ago by mtredinnick
- Resolution set to fixed
- Status changed from reopened to closed