On Mon, 2009-01-19 at 17:49 +0100, Matias Surdi wrote:
> Hi,
> 
> 
> I'm trying to run a sql query with parameters taken from a dict, here is 
> the relevant part of the code:
>       query = "select * from table where name='%(name)s'"
>       parameters = {'name':'valueofname'}
>          cursor = connection.cursor()
>          data = cursor.execute(query,parameters)
> 
> 
> The error I get is:
> 
> TypeError: format requires a mapping
> 
> 
> But, as far as I know (from PEP249) this should be possible.

Just to be accurate, PEP 249 says that a paramstyle of "pyformat" is one
possible value, which would permit the above sort of query. It does not
say that every conforming database wrapper is required to support it.
Although the PEP recommends supporting "numeric", "named" or pyformat"
styles of parameter markers, historically and practically, most database
wrappers have supported "format", although SQLite (and some other
databases that don't have backends in Django's core, although the exact
names escape me now) only supports "qmark".

Since you note later in the thread that you're using SQLite, that is the
cause of the confusion here. I don't think there's any bug.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to