Skip to content

Commit 56ee410

Browse files
[3.10] gh-89018: Improve documentation of sqlite3 exceptions (GH-27645) (#93838)
- Order exceptions as in PEP 249 - Reword descriptions, so they match the current behaviour Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>. (cherry picked from commit bb0b768) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com>
1 parent 095d09c commit 56ee410

File tree

1 file changed

+48
-17
lines changed

1 file changed

+48
-17
lines changed

Doc/library/sqlite3.rst

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ Cursor Objects
681681
:ref:`placeholders <sqlite3-placeholders>`.
682682

683683
:meth:`execute` will only execute a single SQL statement. If you try to execute
684-
more than one statement with it, it will raise a :exc:`.Warning`. Use
684+
more than one statement with it, it will raise a :exc:`Warning`. Use
685685
:meth:`executescript` if you want to execute multiple SQL statements with one
686686
call.
687687

@@ -883,43 +883,74 @@ Now we plug :class:`Row` in::
883883
Exceptions
884884
----------
885885

886+
The exception hierarchy is defined by the DB-API 2.0 (:pep:`249`).
887+
886888
.. exception:: Warning
887889

888-
A subclass of :exc:`Exception`.
890+
This exception is raised by ``sqlite3`` if an SQL query is not a
891+
:class:`string <str>`, or if multiple statements are passed to
892+
:meth:`~Cursor.execute` or :meth:`~Cursor.executemany`.
893+
``Warning`` is a subclass of :exc:`Exception`.
889894

890895
.. exception:: Error
891896

892-
The base class of the other exceptions in this module. It is a subclass
893-
of :exc:`Exception`.
897+
The base class of the other exceptions in this module.
898+
Use this to catch all errors with one single :keyword:`except` statement.
899+
``Error`` is a subclass of :exc:`Exception`.
900+
901+
.. exception:: InterfaceError
902+
903+
This exception is raised by ``sqlite3`` for fetch across rollback,
904+
or if ``sqlite3`` is unable to bind parameters.
905+
``InterfaceError`` is a subclass of :exc:`Error`.
894906

895907
.. exception:: DatabaseError
896908

897909
Exception raised for errors that are related to the database.
910+
This serves as the base exception for several types of database errors.
911+
It is only raised implicitly through the specialised subclasses.
912+
``DatabaseError`` is a subclass of :exc:`Error`.
913+
914+
.. exception:: DataError
915+
916+
Exception raised for errors caused by problems with the processed data,
917+
like numeric values out of range, and strings which are too long.
918+
``DataError`` is a subclass of :exc:`DatabaseError`.
919+
920+
.. exception:: OperationalError
921+
922+
Exception raised for errors that are related to the database's operation,
923+
and not necessarily under the control of the programmer.
924+
For example, the database path is not found,
925+
or a transaction could not be processed.
926+
``OperationalError`` is a subclass of :exc:`DatabaseError`.
898927

899928
.. exception:: IntegrityError
900929

901930
Exception raised when the relational integrity of the database is affected,
902931
e.g. a foreign key check fails. It is a subclass of :exc:`DatabaseError`.
903932

904-
.. exception:: ProgrammingError
933+
.. exception:: InternalError
905934

906-
Exception raised for programming errors, e.g. table not found or already
907-
exists, syntax error in the SQL statement, wrong number of parameters
908-
specified, etc. It is a subclass of :exc:`DatabaseError`.
935+
Exception raised when SQLite encounters an internal error.
936+
If this is raised, it may indicate that there is a problem with the runtime
937+
SQLite library.
938+
``InternalError`` is a subclass of :exc:`DatabaseError`.
909939

910-
.. exception:: OperationalError
940+
.. exception:: ProgrammingError
911941

912-
Exception raised for errors that are related to the database's operation
913-
and not necessarily under the control of the programmer, e.g. an unexpected
914-
disconnect occurs, the data source name is not found, a transaction could
915-
not be processed, etc. It is a subclass of :exc:`DatabaseError`.
942+
Exception raised for ``sqlite3`` API programming errors,
943+
for example trying to operate on a closed :class:`Connection`,
944+
or trying to execute non-DML statements with :meth:`~Cursor.executemany`.
945+
``ProgrammingError`` is a subclass of :exc:`DatabaseError`.
916946

917947
.. exception:: NotSupportedError
918948

919-
Exception raised in case a method or database API was used which is not
920-
supported by the database, e.g. calling the :meth:`~Connection.rollback`
921-
method on a connection that does not support transaction or has
922-
transactions turned off. It is a subclass of :exc:`DatabaseError`.
949+
Exception raised in case a method or database API is not supported by the
950+
underlying SQLite library. For example, setting *deterministic* to
951+
:const:`True` in :meth:`~Connection.create_function`, if the underlying SQLite library
952+
does not support deterministic functions.
953+
``NotSupportedError`` is a subclass of :exc:`DatabaseError`.
923954

924955

925956
.. _sqlite3-types:

0 commit comments

Comments
 (0)
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