Skip to content
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

Allow adapters to be passed as arguments of cursor's execute() #107

Merged
merged 1 commit into from
Oct 23, 2019

Conversation

amigrave
Copy link

psycopg2 allows to pass Adapter instances as arguments of cursor's
execute(). This patch will make psycopg2cffi behave the same way.

Here's a test case that can be run against psycopg2 and psycopg2cffi

import psycopg2  # assuming psycopg2cffi-compat
from psycopg2.extensions import AsIs, Boolean

conn = psycopg2.connect(database='postgres')
cr = conn.cursor()
cr.execute("SELECT %s, %s", (AsIs("version()"), Boolean(True)))
print(cr.fetchone())

Basically psycopg2cffi does not allow users to pass an adapter in the argument list of execute() because the values will be converted/adapted no matter what.

This commit will check if the value is already an Adapter instance before trying to adapt it.

psycopg2 allows to pass Adapter instances as arguments of cursor's
execute(). This patch will make psycopg2cffi behave the same way.
Copy link
Member

@lopuhin lopuhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for PR @amigrave , the changes look good. Could you please add a test as well?

@lopuhin lopuhin merged commit 6dcc629 into chtd:master Oct 23, 2019
@lopuhin
Copy link
Member

lopuhin commented Oct 23, 2019

Thanks @amigrave and @thedrow

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