I found the cause of this magic "multiply by 3" but I don't understand
it well enough to offer a solution. In the mysql backend, there is this
clause (lines 69-70 in DatabaseWrapper.cursor):

        if self.connection.get_server_info() >= '4.1':
            cursor.execute("SET NAMES utf8")

Setting the connection to use utf8 has the side effect of returning
lengths 3 times their number of chars in the cursor.description() call
as this demonstrates:

>>> import MySQLdb
>>> cn = MySQLdb.connect(user='root',db='data',passwd='hejphund')
>>> cu = cn.cursor()
>>> cu.execute('select investId from trade limit 1')
1L
>>> cu.description
(('investId', 253, 3, 40, 40, 0, 0),)
>>> cu.execute('set names utf8')
0L
>>> cu.execute('select investId from trade limit 1')
1L
>>> cu.description
(('investId', 253, 3, 120, 120, 0, 0),)
>>>

Note that before the 'set names utf8' the data lenght of the field is
40 (it was created as a varchar(40) field). But after the 'set names
utf8' it shows a length of 120.

I guess that by default MySQL 4.1+ uses unicode so when you say you are
creating a column of varchar(40) that's really 40 unicode chars and
MySQL must use 3 bytes per unicode char. Then when you change the
connection to use UTF8 it is showing you the number of bytes (UTF8
chars) for the length.

But I don't understand if this is a problem to worry about or not.

Note: I also tried doing 'set names utf8' *before* I created my table
but it had no effect.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to