From c16f5d67498ef00e1e3999f108bf7b79a4163b88 Mon Sep 17 00:00:00 2001 From: Erlend Egeberg Aasland Date: Sun, 19 Jun 2022 21:17:28 +0200 Subject: [PATCH] gh-93925: Improve clarity of sqlite3 commit/rollback, and close docs (GH-93926) Co-authored-by: CAM Gerlach (cherry picked from commit 6446592c89b0c581c00e170ae6278291e940755c) Co-authored-by: Erlend Egeberg Aasland --- Doc/library/sqlite3.rst | 17 ++++++++--------- Modules/_sqlite/clinic/connection.c.h | 14 ++++++++++---- Modules/_sqlite/connection.c | 18 ++++++++++++------ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index 4e3de6baf288fa..6981bed5bad627 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -413,21 +413,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]) diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h index dd86fb5b64f3f0..62d31b787ad717 100644 --- a/Modules/_sqlite/clinic/connection.c.h +++ b/Modules/_sqlite/clinic/connection.c.h @@ -248,7 +248,9 @@ PyDoc_STRVAR(pysqlite_connection_close__doc__, "close($self, /)\n" "--\n" "\n" -"Closes the connection."); +"Close the database connection.\n" +"\n" +"Any pending transaction is not committed implicitly."); #define PYSQLITE_CONNECTION_CLOSE_METHODDEF \ {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS, pysqlite_connection_close__doc__}, @@ -266,7 +268,9 @@ PyDoc_STRVAR(pysqlite_connection_commit__doc__, "commit($self, /)\n" "--\n" "\n" -"Commit the current transaction."); +"Commit any pending transaction to the database.\n" +"\n" +"If there is no open transaction, this method is a no-op."); #define PYSQLITE_CONNECTION_COMMIT_METHODDEF \ {"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS, pysqlite_connection_commit__doc__}, @@ -284,7 +288,9 @@ PyDoc_STRVAR(pysqlite_connection_rollback__doc__, "rollback($self, /)\n" "--\n" "\n" -"Roll back the current transaction."); +"Roll back to the start of any pending transaction.\n" +"\n" +"If there is no open transaction, this method is a no-op."); #define PYSQLITE_CONNECTION_ROLLBACK_METHODDEF \ {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS, pysqlite_connection_rollback__doc__}, @@ -1231,4 +1237,4 @@ getlimit(pysqlite_Connection *self, PyObject *arg) #ifndef DESERIALIZE_METHODDEF #define DESERIALIZE_METHODDEF #endif /* !defined(DESERIALIZE_METHODDEF) */ -/*[clinic end generated code: output=fb8908674e9f25ff input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8818c1c3ec9425aa input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 4ac0078eb83c21..99949baa0c62b9 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -470,12 +470,14 @@ blobopen_impl(pysqlite_Connection *self, const char *table, const char *col, /*[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]*/ { if (!pysqlite_check_thread(self)) { return NULL; @@ -522,12 +524,14 @@ int pysqlite_check_connection(pysqlite_Connection* con) /*[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]*/ { if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { return NULL; @@ -557,12 +561,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]*/ { if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { return NULL; 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