On 10/29/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> So I have a function in views:
> #################################
> def getEntries(user):
> """Returns unique entries and page views for each of last 30 day
> """
> cursor = connection.cursor()
> query = cursor.execute('SELECT COUNT(DISTINCT(ip)) AS uniqs,
> COUNT(ip) AS views, date FROM pw_logs GROUP BY date LIMIT 30')
> return query.fetchall()
> #################################
I believe your code here is relying on undefined behavior, specifically the
return value of cursor.execute. In describing the .execute under the
description of cursor objects, the Python Database API Specification v2.0 (
http://www.python.org/dev/peps/pep-0249/) states:
Return values are not defined.
So it is permissible for one db backend (sqlite?) to return something on
which you can then call fetchall() and another (mysqldb) to return a long.
In mysqldb's case I believe it is returning the number of rows resulting
from the query.
If you want to write code that will work for all backends, you must limit
your code to behavior that is defined in the spec. In this specific case it
means you should call fetchall on the cursor object, not the return value of
execute.
Karen
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---