On Mon, Jan 19, 2009 at 11:49 AM, Matias Surdi <[email protected]>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'"
Remove the single quotes around '%(name)s'. The backend will handle
quoting, I expect the extra quotes are causing confusion somewhere.
Karen
>
> 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.
> Basically, what I need, is to pass the parameters values in a dict, and
> not as a list or tuple as is shown in django docs.
>
> Which is the correct way to accomplish this?
>
> Thanks a lot.
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---