Re: Question about inspectdb output

2006-03-01 Thread DavidA

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
-~--~~~~--~~--~--~---



Question about inspectdb output

2006-02-26 Thread DavidA

I'm experimenting with 'inspectdb' so I can use Django on an existing
database. I was curious to see what inspectdb would return for the
tutorial tables (Polls, Choices) and was confused by the output:

class PollsChoice(meta.Model):
id = meta.IntegerField()
poll_id = meta.IntegerField()
choice = meta.CharField(maxlength=600)
votes = meta.IntegerField()
class META:
db_table = 'polls_choices'

class PollsPoll(meta.Model):
id = meta.IntegerField()
question = meta.CharField(maxlength=600)
pub_date = meta.DateTimeField()
class META:
db_table = 'polls_polls'

Why are the choice and question fields maxlength of 600 when they were
specified as 200 in the model? I also tried on a different table I
created with a varchar(40) field and it came back with maxlength of 120
so it seems to consistently multiply the length by 3 (I'm using MySQL
4.1.18).


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---