On Mon, Jul 13, 2009 at 11:25 AM, ashwoods <[email protected]> wrote:
> > but django does call this sql, or does it call something else? > how can i use or see what django really calls? > > so there is no need to report this as i understand it? :) > > thx, ash > > On Jul 13, 6:06 pm, Alex Gaynor <[email protected]> wrote: > > On Mon, Jul 13, 2009 at 11:00 AM, stuff4ash <[email protected]> wrote: > > > > > using mysql. > > > > > model: only the times are relevant. > > > > > class Time(models.Model): > > > start = models.DateTimeField("zeitbeginn") > > > end = models.DateTimeField("zeitende", > > > blank=True,null=True) > > > user = models.ForeignKey(User) > > > project = models.ForeignKey(Project,verbose_name="Projekt") > > > phase = models.ForeignKey(Phase, verbose_name="Phase", > > > blank=True, null=True) > > > comment = models.CharField("kommentar",max_length=100,null=True) > > > telearbeit = models.NullBooleanField(blank=True, null=True) > > > > > if i look at at the sql when i filter with datetime. > > > > > Time.objects.filter(start__gt=datetime.now()).query.as_sql()[0] % > > > Time.objects.filter(start__gt=datetime.now()).query.as_sql()[1] > > > > > i get this: > > > SELECT `time_manager_time`.`id`, `time_manager_time`.`start`, > > > `time_manager_time`.`end`, `time_manager_time`.`user_id`, > > > `time_manager_time`.`project_id`, `time_manager_time`.`phase_id`, > > > `time_manager_time`.`comment`, `time_manager_time`.`telearbeit` FROM > > > `time_manager_time` WHERE `time_manager_time`.`start` > 2009-07-13 > > > 17:59:12 ORDER BY `time_manager_time`.`start` DESC > > > > > if i try to run the query manually, i get an error. mysql wants quotes > > > around the date: > > > SELECT `time_manager_time`.`id`, `time_manager_time`.`start`, > > > `time_manager_time`.`end`, `time_manager_time`.`user_id`, > > > `time_manager_time`.`project_id`, `time_manager_time`.`phase_id`, > > > `time_manager_time`.`comment`, `time_manager_time`.`telearbeit` FROM > > > `time_manager_time` WHERE `time_manager_time`.`start` > '2009-07-13 > > > 17:59:12' ORDER BY `time_manager_time`.`start` DESC > > > > > but using the queryset works. havent been able to find out why > > > > This isn't a bug. The reason for this is Django uses prepared queries > when > > sending SQL to the DB. That is it just leaves %s in the query and sets > the > > DB the params seperately. When you combine the strings Django > approxmates > > the quoting the database will do, but this often isn't totally correct. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." -- Voltaire > > "The people's good is the highest law." -- Cicero > > "Code can always be simpler than you think, but never as simple as you > want" > > -- Me > > > Nope, there's defintely no bug here. http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py#L2346is where the SQL is actually executed and as you can see teh SQL and the parameters are never combined into one strings, they are sent independently to either the Python module or all the way to the DB. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire "The people's good is the highest law." -- Cicero "Code can always be simpler than you think, but never as simple as you want" -- Me --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" 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-developers?hl=en -~----------~----~----~----~------~----~------~--~---
