﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
2765	MySQL with utf8_bin collation for case-sensitive comparison goodness requires MySQLdb 1.2.1	dave AT avaragado.org	Adrian Holovaty	"By default, MySQL 4.1 (at least) uses a case-insensitive collation, utf8_general_ci. This means that checks for equality are, annoyingly, case-insensitive. You can set the collation for a database in the CREATE DATABASE command, or you can set it per-server with an option in the MySQL my.cnf file. You can also set it per-column if you want.

Sadly, using a collation like utf8_bin, which gives case-sensitive comparisons, causes unexpected results through the ORM.

To reproduce:
 - Edit your my.cnf file to include the line
{{{
collation-server = utf8_bin
}}}
 - Restart mysqld

Run ""python manage.py test"" such that it tests this models.py:

{{{
#!python
from django.db import models

class Dummy(models.Model):
    """"""
    >>> d = Dummy(ok='ok', notok='not ok')
    >>> d.save()

    >>> d = Dummy.objects.all()[0]
    >>> d.ok, d.notok
    ('ok', 'not ok')
    """"""
    ok = models.CharField(maxlength=100)
    notok = models.TextField()
}}}

You'll get something like this (irrelevant info removed):

{{{
Failed example:
    d.ok, d.notok
Expected:
    ('ok', 'not ok')
Got:
    ('ok', array('c', 'not ok'))
}}}

Without the collation-server line in my.cnf, the tests pass. Even without that line the tests fail if the CREATE DATABASE line specifies utf8_bin as the collation (and I imagine other binary collations), but the test framework uses the server defaults for those.

My own scrabbling around discovered that MySQLdb (version 1.2.0, at least) includes a suspicious class in __init__.py:
{{{
def Binary(x):
    from array import array
    return array('c', x)
}}}
... but that's as far as my limited knowledge goes - I have no idea how it gets used."	defect	closed	Core (Other)	dev	normal	fixed	mysql mysqldb utf8 case		Design decision needed	0	0	0	0	0	0
