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

Docs: add named to the note describing the sqlite3.paramstyle attribute #99078

Merged
merged 2 commits into from
Nov 3, 2022

Conversation

ngnpope
Copy link
Contributor

@ngnpope ngnpope commented Nov 3, 2022

The documentation for sqlite3.paramstyle states that only qmark and numeric styles are supported for parameter placeholders but, according to the SQLite documentation, the named style is also supported.

See the following links for more details:

A simple example confirms that this is supported:

>>> import sqlite3
>>> con = sqlite3.connect(":memory:")
>>> cur = con.execute("CREATE TEMPORARY TABLE t (name TEXT)")
>>> cur.execute("INSERT INTO t (name) VALUES ('Bob'), ('Cat'), ('Joe')")
<sqlite3.Cursor object at 0x7fcbe373b940>
>>> cur.execute("SELECT * FROM t WHERE name = :name", {"name": "Cat"})
<sqlite3.Cursor object at 0x7fcbe373b940>
>>> print(cur.fetchone()[0])
Cat

@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Nov 3, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

The documentation for `sqlite3.paramstyle` states that only `qmark` and
`numeric` styles are supported for parameter placeholders but, according
to the SQLite documentation, the `named` style is also supported.

See the following links for more details:

- https://docs.python.org/3/library/sqlite3.html#sqlite3.paramstyle
- https://peps.python.org/pep-0249/#paramstyle
- https://www.sqlite.org/lang_expr.html#parameters

A simple example confirms that this is supported:

```pycon
>>> import sqlite3
>>> con = sqlite3.connect(":memory:")
>>> cur = con.execute("CREATE TEMPORARY TABLE t (name TEXT)")
>>> cur.execute("INSERT INTO t (name) VALUES ('Bob'), ('Cat'), ('Joe')")
<sqlite3.Cursor object at 0x7fcbe373b940>
>>> cur.execute("SELECT * FROM t WHERE name = :name", {"name": "Cat"})
<sqlite3.Cursor object at 0x7fcbe373b940>
>>> print(cur.fetchone()[0])
Cat
```
Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

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

Thanks; lgtm!

@erlend-aasland erlend-aasland changed the title Documented support for named paramstyle in sqlite3. Docs: add named to the note describing the sqlite3.paramstyle attribute Nov 3, 2022
@erlend-aasland erlend-aasland merged commit 016c7d3 into python:main Nov 3, 2022
@miss-islington
Copy link
Contributor

Thanks @ngnpope for the PR, and @erlend-aasland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 3, 2022
…r docs (pythonGH-99078)

(cherry picked from commit 016c7d3)

Co-authored-by: Nick Pope <nick@nickpope.me.uk>
@bedevere-bot
Copy link

GH-99081 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Nov 3, 2022
@bedevere-bot
Copy link

GH-99082 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Nov 3, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 3, 2022
…r docs (pythonGH-99078)

(cherry picked from commit 016c7d3)

Co-authored-by: Nick Pope <nick@nickpope.me.uk>
miss-islington added a commit that referenced this pull request Nov 3, 2022
…r docs (GH-99078)

(cherry picked from commit 016c7d3)

Co-authored-by: Nick Pope <nick@nickpope.me.uk>
miss-islington added a commit that referenced this pull request Nov 3, 2022
…r docs (GH-99078)

(cherry picked from commit 016c7d3)

Co-authored-by: Nick Pope <nick@nickpope.me.uk>
@ngnpope ngnpope deleted the sqlite3-named-paramstyle branch November 3, 2022 23:47
@ngnpope
Copy link
Contributor Author

ngnpope commented Nov 3, 2022

Thanks! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants