Skip to content

Commit

Permalink
[3.10] gh-93925: Improve clarity of sqlite3 commit/rollback, and clos…
Browse files Browse the repository at this point in the history
…e 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>
  • Loading branch information
Erlend Egeberg Aasland authored Jun 19, 2022
1 parent beba102 commit c4440e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
17 changes: 8 additions & 9 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -360,21 +360,20 @@ Connection Objects

.. method:: commit()

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

.. method:: rollback()

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

.. method:: close()

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

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

Expand Down
14 changes: 10 additions & 4 deletions Modules/_sqlite/clinic/connection.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,14 @@ pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory)
/*[clinic input]
_sqlite3.Connection.close as pysqlite_connection_close
Closes the connection.
Close the database connection.
Any pending transaction is not committed implicitly.
[clinic start generated code]*/

static PyObject *
pysqlite_connection_close_impl(pysqlite_Connection *self)
/*[clinic end generated code: output=a546a0da212c9b97 input=3d58064bbffaa3d3]*/
/*[clinic end generated code: output=a546a0da212c9b97 input=b3ed5b74f6fefc06]*/
{
int rc;

Expand Down Expand Up @@ -445,12 +447,14 @@ PyObject* _pysqlite_connection_begin(pysqlite_Connection* self)
/*[clinic input]
_sqlite3.Connection.commit as pysqlite_connection_commit
Commit the current transaction.
Commit any pending transaction to the database.
If there is no open transaction, this method is a no-op.
[clinic start generated code]*/

static PyObject *
pysqlite_connection_commit_impl(pysqlite_Connection *self)
/*[clinic end generated code: output=3da45579e89407f2 input=39c12c04dda276a8]*/
/*[clinic end generated code: output=3da45579e89407f2 input=c8793c97c3446065]*/
{
int rc;
sqlite3_stmt* statement;
Expand Down Expand Up @@ -494,12 +498,14 @@ pysqlite_connection_commit_impl(pysqlite_Connection *self)
/*[clinic input]
_sqlite3.Connection.rollback as pysqlite_connection_rollback
Roll back the current transaction.
Roll back to the start of any pending transaction.
If there is no open transaction, this method is a no-op.
[clinic start generated code]*/

static PyObject *
pysqlite_connection_rollback_impl(pysqlite_Connection *self)
/*[clinic end generated code: output=b66fa0d43e7ef305 input=12d4e8d068942830]*/
/*[clinic end generated code: output=b66fa0d43e7ef305 input=7f60a2f1076f16b3]*/
{
int rc;
sqlite3_stmt* statement;
Expand Down

0 comments on commit c4440e6

Please sign in to comment.