summaryrefslogtreecommitdiff
path: root/Doc/library/sqlite3.rst
diff options
context:
space:
mode:
authorGerhard Häring <gh@ghaering.de>2008-03-29 01:27:37 +0000
committerGerhard Häring <gh@ghaering.de>2008-03-29 01:27:37 +0000
commit4130930b4cb2e41b758d69e5bcd5be678391c85b (patch)
tree56a2aa9484293262920314f0b5bbf625c14f5117 /Doc/library/sqlite3.rst
parent554d4f0c138df458d73031661a1bad91f6a02380 (diff)
downloadcpython-git-4130930b4cb2e41b758d69e5bcd5be678391c85b.tar.gz
Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
complained about commit, rollback and close not being documented.
Diffstat (limited to 'Doc/library/sqlite3.rst')
-rw-r--r--Doc/library/sqlite3.rst48
1 files changed, 43 insertions, 5 deletions
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst
index da313fd597..29d5e490b7 100644
--- a/Doc/library/sqlite3.rst
+++ b/Doc/library/sqlite3.rst
@@ -232,6 +232,24 @@ A :class:`Connection` instance has the following attributes and methods:
:class:`sqlite3.Cursor`.
+.. method:: Connection.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 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.
+
+.. method:: Connection.rollback()
+
+ This method rolls back any changes to the database since the last call to
+ :meth:`commit`.
+
+.. method:: Connection.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!
+
.. method:: Connection.execute(sql, [parameters])
This is a nonstandard shortcut that creates an intermediate cursor object by
@@ -245,7 +263,6 @@ A :class:`Connection` instance has the following attributes and methods:
calling the cursor method, then calls the cursor's :meth:`executemany` method
with the parameters given.
-
.. method:: Connection.executescript(sql_script)
This is a nonstandard shortcut that creates an intermediate cursor object by
@@ -332,6 +349,19 @@ A :class:`Connection` instance has the following attributes and methods:
one. All necessary constants are available in the :mod:`sqlite3` module.
+.. method:: Connection.set_progress_handler(handler, n)
+
+ .. versionadded:: 2.6
+
+ This routine registers a callback. The callback is invoked for every *n*
+ instructions of the SQLite virtual machine. This is useful if you want to
+ get called from SQLite during long-running operations, for example to update
+ a GUI.
+
+ If you want to clear any previously installed progress handler, call the
+ method with :const:`None` for *handler*.
+
+
.. attribute:: Connection.row_factory
You can change this attribute to a callable that accepts the cursor and the
@@ -701,10 +731,6 @@ Otherwise leave it at its default, which will result in a plain "BEGIN"
statement, or set it to one of SQLite's supported isolation levels: DEFERRED,
IMMEDIATE or EXCLUSIVE.
-As the :mod:`sqlite3` module needs to keep track of the transaction state, you
-should not use ``OR ROLLBACK`` or ``ON CONFLICT ROLLBACK`` in your SQL. Instead,
-catch the :exc:`IntegrityError` and call the :meth:`rollback` method of the
-connection yourself.
Using pysqlite efficiently
@@ -736,3 +762,15 @@ case-insensitively by name:
.. literalinclude:: ../includes/sqlite3/rowclass.py
+
+Using the connection as a context manager
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. versionadded:: 2.6
+
+Connection objects can be used as context managers
+that automatically commit or rollback transactions. In the event of an
+exception, the transaction is rolled back; otherwise, the transaction is
+committed:
+
+.. literalinclude:: ../includes/sqlite3/ctx_manager.py