Skip to content

Fix escaping for args for python3 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

dpedu
Copy link

@dpedu dpedu commented Jan 14, 2014

Prior to this change, passing a dict or tuple of args to connection.execute did not work, the %s would be left in the query without the replacements being substituted in.

@davispuh
Copy link
Owner

yes, that's because this implementation uses Python's 3 str.format way, take a look at usage example and I don't plan to change it. For old % way I would suggest using other fork like dailyinsight/MySQL-for-Python-3

@davispuh davispuh closed this Jan 14, 2014
@dpedu
Copy link
Author

dpedu commented Jan 14, 2014

I don't agree that anything str.format offers has any business in a database query. The current str.format implementation also breaks compatibility with programs expecting identical usage to MySQLdb for Python 2.x. For example, using this module with django 1.6, it expects to be able to do:

c.execute("SELECT * FROM table WHERE x=%s", ("test",))

But cannot. Additionally, through using the "old" % method, you could already do what is displayed in the Usage example:

c.execute("SELECT * FROM table WHERE x=%(myvalue)s", {"myvalue":"test"})

@davispuh
Copy link
Owner

It's not really related to database itself, but to this library. For different languages there's different ways how to implement parameter queries. Anyway full story why format is used and not % is that I ported this library very early when Py3 was released and then % modifier was removed. They added it back later, but I already had went with format. Also when I ported this library I dropped all support for Py2 and it never was meant to be compatible with original MySQLdb. And personally like format better than %. I would accept PR if both ways would work as currently this library have been using format for few years and I'm not going to drop that. And yeah I know that with % same results can be achieved, but it's just this new Py3 syntax which here is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants