Skip to content

Commit a40d066

Browse files
miss-islingtonErlend Egeberg Aasland
and
Erlend Egeberg Aasland
authored
bpo-45677: Reword first section of sqlite3 docs (GH-29326) (GH-29567)
* bpo-45677: Avoid addressing the reader as 'you' in sqlite3 docs * Adjust wording * Adjust wording again * Typo * Update Doc/library/sqlite3.rst Co-authored-by: Jacob Walls <[email protected]> * Address review: adjust wording * Update Doc/library/sqlite3.rst Co-authored-by: Alex Waygood <[email protected]> * Update Lib/sqlite3/__init__.py Co-authored-by: Alex Waygood <[email protected]> * Update Doc/library/sqlite3.rst Co-authored-by: Alex Waygood <[email protected]> * Update Doc/library/sqlite3.rst Co-authored-by: Alex Waygood <[email protected]> * Update Lib/sqlite3/__init__.py Co-authored-by: Alex Waygood <[email protected]> * Update Doc/library/sqlite3.rst Co-authored-by: Alex Waygood <[email protected]> * Apply Alex' suggestion, and apply 80 char limit to PR * Minor adjustment Co-authored-by: Jacob Walls <[email protected]> Co-authored-by: Alex Waygood <[email protected]> (cherry picked from commit 6c5a312) Co-authored-by: Erlend Egeberg Aasland <[email protected]> Co-authored-by: Erlend Egeberg Aasland <[email protected]>
1 parent b0bdc09 commit a40d066

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

Doc/library/sqlite3.rst

+20-18
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ PostgreSQL or Oracle.
2020
The sqlite3 module was written by Gerhard Häring. It provides a SQL interface
2121
compliant with the DB-API 2.0 specification described by :pep:`249`.
2222

23-
To use the module, you must first create a :class:`Connection` object that
23+
To use the module, start by creating a :class:`Connection` object that
2424
represents the database. Here the data will be stored in the
2525
:file:`example.db` file::
2626

2727
import sqlite3
2828
con = sqlite3.connect('example.db')
2929

30-
You can also supply the special name ``:memory:`` to create a database in RAM.
30+
The special path name ``:memory:`` can be provided to create a temporary
31+
database in RAM.
3132

32-
Once you have a :class:`Connection`, you can create a :class:`Cursor` object
33+
Once a :class:`Connection` has been established, create a :class:`Cursor` object
3334
and call its :meth:`~Cursor.execute` method to perform SQL commands::
3435

3536
cur = con.cursor()
@@ -48,16 +49,17 @@ and call its :meth:`~Cursor.execute` method to perform SQL commands::
4849
# Just be sure any changes have been committed or they will be lost.
4950
con.close()
5051

51-
The data you've saved is persistent and is available in subsequent sessions::
52+
The saved data is persistent: it can be reloaded in a subsequent session even
53+
after restarting the Python interpreter::
5254

5355
import sqlite3
5456
con = sqlite3.connect('example.db')
5557
cur = con.cursor()
5658

57-
To retrieve data after executing a SELECT statement, you can either treat the
58-
cursor as an :term:`iterator`, call the cursor's :meth:`~Cursor.fetchone` method to
59-
retrieve a single matching row, or call :meth:`~Cursor.fetchall` to get a list of the
60-
matching rows.
59+
To retrieve data after executing a SELECT statement, either treat the cursor as
60+
an :term:`iterator`, call the cursor's :meth:`~Cursor.fetchone` method to
61+
retrieve a single matching row, or call :meth:`~Cursor.fetchall` to get a list
62+
of the matching rows.
6163

6264
This example uses the iterator form::
6365

@@ -72,27 +74,27 @@ This example uses the iterator form::
7274

7375
.. _sqlite3-placeholders:
7476

75-
Usually your SQL operations will need to use values from Python variables. You
76-
shouldn't assemble your query using Python's string operations because doing so
77-
is insecure; it makes your program vulnerable to an SQL injection attack
78-
(see the `xkcd webcomic <https://xkcd.com/327/>`_ for a humorous example of
79-
what can go wrong)::
77+
SQL operations usually need to use values from Python variables. However,
78+
beware of using Python's string operations to assemble queries, as they
79+
are vulnerable to SQL injection attacks (see the `xkcd webcomic
80+
<https://xkcd.com/327/>`_ for a humorous example of what can go wrong)::
8081

8182
# Never do this -- insecure!
8283
symbol = 'RHAT'
8384
cur.execute("SELECT * FROM stocks WHERE symbol = '%s'" % symbol)
8485

85-
Instead, use the DB-API's parameter substitution. Put a placeholder wherever
86-
you want to use a value, and then provide a tuple of values as the second
87-
argument to the cursor's :meth:`~Cursor.execute` method. An SQL statement may
86+
Instead, use the DB-API's parameter substitution. To insert a variable into a
87+
query string, use a placeholder in the string, and substitute the actual values
88+
into the query by providing them as a :class:`tuple` of values to the second
89+
argument of the cursor's :meth:`~Cursor.execute` method. An SQL statement may
8890
use one of two kinds of placeholders: question marks (qmark style) or named
8991
placeholders (named style). For the qmark style, ``parameters`` must be a
9092
:term:`sequence <sequence>`. For the named style, it can be either a
9193
:term:`sequence <sequence>` or :class:`dict` instance. The length of the
9294
:term:`sequence <sequence>` must match the number of placeholders, or a
9395
:exc:`ProgrammingError` is raised. If a :class:`dict` is given, it must contain
94-
keys for all named parameters. Any extra items are ignored. Here's an example
95-
of both styles:
96+
keys for all named parameters. Any extra items are ignored. Here's an example of
97+
both styles:
9698

9799
.. literalinclude:: ../includes/sqlite3/execute_1.py
98100

Lib/sqlite3/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
The sqlite3 extension module provides a DB-API 2.0 (PEP 249) compilant
2525
interface to the SQLite library, and requires SQLite 3.7.15 or newer.
2626
27-
To use the module, you must first create a database Connection object:
27+
To use the module, start by creating a database Connection object:
2828
2929
import sqlite3
3030
cx = sqlite3.connect("test.db") # test.db will be created or opened
3131
32-
You can also use the special database name ":memory:" to connect to a transient
32+
The special path name ":memory:" can be provided to connect to a transient
3333
in-memory database:
3434
3535
cx = sqlite3.connect(":memory:") # connect to a database in RAM
3636
37-
Once you have a Connection object, you can create a Cursor object and call its
38-
execute() method to perform SQL queries:
37+
Once a connection has been established, create a Cursor object and call
38+
its execute() method to perform SQL queries:
3939
4040
cu = cx.cursor()
4141

0 commit comments

Comments
 (0)