2008/7/8 Peter <[EMAIL PROTECTED]>:
>
> When I look at generated sql from connection.queries, it doesn't show
> any quotes around strings.
>
> For example:
>>>> from django.db import connection
>>>> from django.contrib.auth.models import User
>>>> User.objects.filter(username="bob")
> []
>>>> connection.queries[-1]
> {'time': '0.000', 'sql': u'SELECT `auth_user`.`id`,
> `auth_user`.`username`, `auth_user`.`first_name`,
> `auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`password`,
> `auth_user`.`is_staff`, `auth_user`.`is_active`,
> `auth_user`.`is_superuser`, `auth_user`.`last_login`,
> `auth_user`.`date_joined` FROM `auth_user` WHERE
> `auth_user`.`username` = bob  ORDER BY `auth_user`.`username` ASC'}
>>>>
>
> As one would imagine, when I execute:
>
> mysql> SELECT `auth_user`.`id`, `auth_user`.`username`,
> `auth_user`.`first_name`, `auth_user`.`last_name`,
> `auth_user`.`email`, `auth_user`.`password`, `auth_user`.`is_staff`,
> `auth_user`.`is_active`, `auth_user`.`is_superuser`,
> `auth_user`.`last_login`, `auth_user`.`date_joined` FROM `auth_user`
> WHERE `auth_user`.`username` = bob  ORDER BY `auth_user`.`username`
> ASC;
>
> It complains with "Unknown column 'bob' in 'where clause'".
>
> It's obvious how I would change that code to execute properly, but I'd
> like to know exactly what query django is building.
> (for example you can get away with passing a number into a query
> against a varchar, and that can affect the efficiency of complex
> queries)
>
> Is this Django-MySQL 5.x specific?  Is this a full-on django bug?
>

The behavior you see stems from the fact, that different database backends
need different quoting and escaping of values. The SQL queries from
connection.queries
are not literally executed; the statements and the parameters get passed
separately to the backend as as good practice recommends.

What you see is not a Django bug then, but maybe not Django-MySQL specific
either. If you need to know more you'd have to dig into the django db or the
python-mysql source code.

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

Reply via email to