Skip to content

Commit c4440e6

Browse files
author
Erlend Egeberg Aasland
authored
[3.10] gh-93925: Improve clarity of sqlite3 commit/rollback, and close docs (GH-93926) (#94011)
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 beba102 commit c4440e6

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
@@ -360,21 +360,20 @@ Connection Objects
360360

361361
.. method:: commit()
362362

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

368366
.. method:: rollback()
369367

370-
This method rolls back any changes to the database since the last call to
371-
:meth:`commit`.
368+
Roll back to the start of any pending transaction.
369+
If there is no open transaction, this method is a no-op.
372370

373371
.. method:: close()
374372

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

379378
.. method:: execute(sql[, parameters])
380379

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
@@ -351,12 +351,14 @@ pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory)
351351
/*[clinic input]
352352
_sqlite3.Connection.close as pysqlite_connection_close
353353
354-
Closes the connection.
354+
Close the database connection.
355+
356+
Any pending transaction is not committed implicitly.
355357
[clinic start generated code]*/
356358

357359
static PyObject *
358360
pysqlite_connection_close_impl(pysqlite_Connection *self)
359-
/*[clinic end generated code: output=a546a0da212c9b97 input=3d58064bbffaa3d3]*/
361+
/*[clinic end generated code: output=a546a0da212c9b97 input=b3ed5b74f6fefc06]*/
360362
{
361363
int rc;
362364

@@ -445,12 +447,14 @@ PyObject* _pysqlite_connection_begin(pysqlite_Connection* self)
445447
/*[clinic input]
446448
_sqlite3.Connection.commit as pysqlite_connection_commit
447449
448-
Commit the current transaction.
450+
Commit any pending transaction to the database.
451+
452+
If there is no open transaction, this method is a no-op.
449453
[clinic start generated code]*/
450454

451455
static PyObject *
452456
pysqlite_connection_commit_impl(pysqlite_Connection *self)
453-
/*[clinic end generated code: output=3da45579e89407f2 input=39c12c04dda276a8]*/
457+
/*[clinic end generated code: output=3da45579e89407f2 input=c8793c97c3446065]*/
454458
{
455459
int rc;
456460
sqlite3_stmt* statement;
@@ -494,12 +498,14 @@ pysqlite_connection_commit_impl(pysqlite_Connection *self)
494498
/*[clinic input]
495499
_sqlite3.Connection.rollback as pysqlite_connection_rollback
496500
497-
Roll back the current transaction.
501+
Roll back to the start of any pending transaction.
502+
503+
If there is no open transaction, this method is a no-op.
498504
[clinic start generated code]*/
499505

500506
static PyObject *
501507
pysqlite_connection_rollback_impl(pysqlite_Connection *self)
502-
/*[clinic end generated code: output=b66fa0d43e7ef305 input=12d4e8d068942830]*/
508+
/*[clinic end generated code: output=b66fa0d43e7ef305 input=7f60a2f1076f16b3]*/
503509
{
504510
int rc;
505511
sqlite3_stmt* statement;

0 commit comments

Comments
 (0)