Skip to content

Commit 8b068c4

Browse files
miss-islingtonErlend Egeberg Aasland
and
Erlend Egeberg Aasland
authored
gh-93925: Improve clarity of sqlite3 commit/rollback, and close docs (GH-93926)
Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM> (cherry picked from commit 6446592) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
1 parent 1073184 commit 8b068c4

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

Doc/library/sqlite3.rst

+8-9
Original file line numberDiff line numberDiff line change
@@ -413,21 +413,20 @@ Connection Objects
413413

414414
.. method:: commit()
415415

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

421419
.. method:: rollback()
422420

423-
This method rolls back any changes to the database since the last call to
424-
:meth:`commit`.
421+
Roll back to the start of any pending transaction.
422+
If there is no open transaction, this method is a no-op.
425423

426424
.. method:: close()
427425

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

432431
.. method:: execute(sql[, parameters])
433432

Modules/_sqlite/clinic/connection.c.h

+10-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/connection.c

+12-6
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)