Skip to content

Commit 6446592

Browse files
Erlend Egeberg AaslandCAM-Gerlach
andauthored
gh-93925: Improve clarity of sqlite3 commit/rollback, and close docs (#93926)
Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent 62363bf commit 6446592

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

Doc/library/sqlite3.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,21 +423,20 @@ Connection Objects
423423

424424
.. method:: commit()
425425

426-
This method commits the current transaction. If you don't call this method,
427-
anything you did since the last call to ``commit()`` is not visible from
428-
other database connections. If you wonder why you don't see the data you've
429-
written to the database, please check you didn't forget to call this method.
426+
Commit any pending transaction to the database.
427+
If there is no open transaction, this method is a no-op.
430428

431429
.. method:: rollback()
432430

433-
This method rolls back any changes to the database since the last call to
434-
:meth:`commit`.
431+
Roll back to the start of any pending transaction.
432+
If there is no open transaction, this method is a no-op.
435433

436434
.. method:: close()
437435

438-
This closes the database connection. Note that this does not automatically
439-
call :meth:`commit`. If you just close your database connection without
440-
calling :meth:`commit` first, your changes will be lost!
436+
Close the database connection.
437+
Any pending transaction is not committed implicitly;
438+
make sure to :meth:`commit` before closing
439+
to avoid losing pending changes.
441440

442441
.. method:: execute(sql[, parameters])
443442

Modules/_sqlite/clinic/connection.c.h

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/connection.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,14 @@ blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
470470
/*[clinic input]
471471
_sqlite3.Connection.close as pysqlite_connection_close
472472
473-
Closes the connection.
473+
Close the database connection.
474+
475+
Any pending transaction is not committed implicitly.
474476
[clinic start generated code]*/
475477

476478
static PyObject *
477479
pysqlite_connection_close_impl(pysqlite_Connection *self)
478-
/*[clinic end generated code: output=a546a0da212c9b97 input=3d58064bbffaa3d3]*/
480+
/*[clinic end generated code: output=a546a0da212c9b97 input=b3ed5b74f6fefc06]*/
479481
{
480482
if (!pysqlite_check_thread(self)) {
481483
return NULL;
@@ -522,12 +524,14 @@ int pysqlite_check_connection(pysqlite_Connection* con)
522524
/*[clinic input]
523525
_sqlite3.Connection.commit as pysqlite_connection_commit
524526
525-
Commit the current transaction.
527+
Commit any pending transaction to the database.
528+
529+
If there is no open transaction, this method is a no-op.
526530
[clinic start generated code]*/
527531

528532
static PyObject *
529533
pysqlite_connection_commit_impl(pysqlite_Connection *self)
530-
/*[clinic end generated code: output=3da45579e89407f2 input=39c12c04dda276a8]*/
534+
/*[clinic end generated code: output=3da45579e89407f2 input=c8793c97c3446065]*/
531535
{
532536
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
533537
return NULL;
@@ -557,12 +561,14 @@ pysqlite_connection_commit_impl(pysqlite_Connection *self)
557561
/*[clinic input]
558562
_sqlite3.Connection.rollback as pysqlite_connection_rollback
559563
560-
Roll back the current transaction.
564+
Roll back to the start of any pending transaction.
565+
566+
If there is no open transaction, this method is a no-op.
561567
[clinic start generated code]*/
562568

563569
static PyObject *
564570
pysqlite_connection_rollback_impl(pysqlite_Connection *self)
565-
/*[clinic end generated code: output=b66fa0d43e7ef305 input=12d4e8d068942830]*/
571+
/*[clinic end generated code: output=b66fa0d43e7ef305 input=7f60a2f1076f16b3]*/
566572
{
567573
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
568574
return NULL;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy