-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
When there is one element on the list, the generated SQL was (1,) (python notation of a single element tuple, which is not valid in SQL.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,7 +180,10 @@ def execute(self, query, args=None): | |
if isinstance(query, unicode): | ||
query = query.encode(db.unicode_literal.charset) | ||
if args is not None: | ||
query = query % db.literal(args) | ||
if isinstance(args, dict): | ||
query = query % {key: db.literal(item) for key, item in args.iteritems()} | ||
else: | ||
query = query % tuple([db.literal(item) for item in args]) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rohitagarwal003
|
||
try: | ||
r = None | ||
r = self._query(query) | ||
|
1 comment
on commit 87d1145
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was made to fix a problem with queries with "WHERE column IN %s" and the argument being a one element list, because it was then transformed in "WHERE column IN ('foo',)" which is not valid in SQL.
As the execute docstring says:
Execute a query.
query -- string, query to execute on server
args -- optional sequence or mapping, parameters to use with query.
I believe the fact that cursor.execute(sql, 'passed_variable')
worked before was more a side effect of the previous implementation of execute than a wanted behaviour.
Also see the answer of @farcepest in #74
The convention I used for string replacement in 1.2.4 no longer works in 1.2.5, I believe because of this commit.
Ex:
sql = "SELECT * FROM table_name WHERE column = %s"
cursor.execute(sql, 'passed_variable')
Is the new convention to pass in a single string as a dict?