Skip to content

Commit 5a9920f

Browse files
gh-95235: Add explicit parameter list to some sqlite3 methods (GH-95240) (GH-95263)
Co-authored-by: CAM Gerlach <[email protected]> (cherry picked from commit 5012bed) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
1 parent 6284f23 commit 5a9920f

File tree

1 file changed

+143
-67
lines changed

1 file changed

+143
-67
lines changed

Doc/library/sqlite3.rst

Lines changed: 143 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Module functions and constants
276276
Can be ``"DEFERRED"`` (default), ``"EXCLUSIVE"`` or ``"IMMEDIATE"``;
277277
or :const:`None` to disable opening transactions implicitly.
278278
See :ref:`sqlite3-controlling-transactions` for more.
279-
:type isolation_level: str | None
279+
:type isolation_level: str | :const:`None`
280280

281281
:param check_same_thread:
282282
If :const:`True` (default), only the creating thread may use the connection.
@@ -306,7 +306,7 @@ Module functions and constants
306306
enabling various :ref:`sqlite3-uri-tricks`.
307307
:type uri: bool
308308

309-
:rtype: sqlite3.Connection
309+
:rtype: Connection
310310

311311
.. audit-event:: sqlite3.connect database sqlite3.connect
312312
.. audit-event:: sqlite3.connect/handle connection_handle sqlite3.connect
@@ -424,13 +424,36 @@ Connection Objects
424424

425425
.. method:: blobopen(table, column, row, /, *, readonly=False, name="main")
426426

427-
Open a :class:`Blob` handle to the :abbr:`BLOB (Binary Large OBject)`
428-
located in table name *table*, column name *column*, and row index *row*
429-
of database *name*.
430-
When *readonly* is :const:`True` the blob is opened without write
431-
permissions.
432-
Trying to open a blob in a ``WITHOUT ROWID`` table will raise
433-
:exc:`OperationalError`.
427+
Open a :class:`Blob` handle to an existing
428+
:abbr:`BLOB (Binary Large OBject)`.
429+
430+
:param table:
431+
The name of the table where the blob is located.
432+
:type table: str
433+
434+
:param column:
435+
The name of the column where the blob is located.
436+
:type column: str
437+
438+
:param row:
439+
The name of the row where the blob is located.
440+
:type row: str
441+
442+
:param readonly:
443+
Set to :const:`True` if the blob should be opened without write
444+
permissions.
445+
Defaults to :const:`False`.
446+
:type readonly: bool
447+
448+
:param name:
449+
The name of the database where the blob is located.
450+
Defaults to ``"main"``.
451+
:type name: str
452+
453+
:raises OperationalError:
454+
When trying to open a blob in a ``WITHOUT ROWID`` table.
455+
456+
:rtype: Blob
434457

435458
.. note::
436459

@@ -476,21 +499,35 @@ Connection Objects
476499

477500
.. method:: create_function(name, narg, func, *, deterministic=False)
478501

479-
Creates a user-defined function that you can later use from within SQL
480-
statements under the function name *name*. *narg* is the number of
481-
parameters the function accepts (if *narg* is -1, the function may
482-
take any number of arguments), and *func* is a Python callable that is
483-
called as the SQL function. If *deterministic* is true, the created function
484-
is marked as `deterministic <https://sqlite.org/deterministic.html>`_, which
485-
allows SQLite to perform additional optimizations. This flag is supported by
486-
SQLite 3.8.3 or higher, :exc:`NotSupportedError` will be raised if used
487-
with older versions.
502+
Create or remove a user-defined SQL function.
503+
504+
:param name:
505+
The name of the SQL function.
506+
:type name: str
507+
508+
:param narg:
509+
The number of arguments the SQL function can accept.
510+
If ``-1``, it may take any number of arguments.
511+
:type narg: int
488512

489-
The function can return any of
490-
:ref:`the types natively supported by SQLite <sqlite3-types>`.
513+
:param func:
514+
A callable that is called when the SQL function is invoked.
515+
The callable must return :ref:`a type natively supported by SQLite
516+
<sqlite3-types>`.
517+
Set to :const:`None` to remove an existing SQL function.
518+
:type func: :term:`callback` | :const:`None`
491519

492-
.. versionchanged:: 3.8
493-
The *deterministic* parameter was added.
520+
:param deterministic:
521+
If :const:`True`, the created SQL function is marked as
522+
`deterministic <https://sqlite.org/deterministic.html>`_,
523+
which allows SQLite to perform additional optimizations.
524+
:type deterministic: bool
525+
526+
:raises NotSupportedError:
527+
If *deterministic* is used with SQLite versions older than 3.8.3.
528+
529+
.. versionadded:: 3.8
530+
The *deterministic* parameter.
494531

495532
Example:
496533

@@ -499,15 +536,29 @@ Connection Objects
499536

500537
.. method:: create_aggregate(name, /, n_arg, aggregate_class)
501538

502-
Creates a user-defined aggregate function.
539+
Create or remove a user-defined SQL aggregate function.
540+
541+
:param name:
542+
The name of the SQL aggregate function.
543+
:type name: str
503544

504-
The aggregate class must implement a ``step`` method, which accepts the number
505-
of parameters *n_arg* (if *n_arg* is -1, the function may take
506-
any number of arguments), and a ``finalize`` method which will return the
507-
final result of the aggregate.
545+
:param n_arg:
546+
The number of arguments the SQL aggregate function can accept.
547+
If ``-1``, it may take any number of arguments.
548+
:type n_arg: int
508549

509-
The ``finalize`` method can return any of
510-
:ref:`the types natively supported by SQLite <sqlite3-types>`.
550+
:param aggregate_class:
551+
A class must implement the following methods:
552+
553+
* ``step()``: Add a row to the aggregate.
554+
* ``finalize()``: Return the final result of the aggregate as
555+
:ref:`a type natively supported by SQLite <sqlite3-types>`.
556+
557+
The number of arguments that the ``step()`` method must accept
558+
is controlled by *n_arg*.
559+
560+
Set to :const:`None` to remove an existing SQL aggregate function.
561+
:type aggregate_class: :term:`class` | :const:`None`
511562

512563
Example:
513564

@@ -516,25 +567,36 @@ Connection Objects
516567

517568
.. method:: create_window_function(name, num_params, aggregate_class, /)
518569

519-
Creates user-defined aggregate window function *name*.
570+
Create or remove a user-defined aggregate window function.
571+
572+
:param name:
573+
The name of the SQL aggregate window function to create or remove.
574+
:type name: str
575+
576+
:param num_params:
577+
The number of arguments the SQL aggregate window function can accept.
578+
If ``-1``, it may take any number of arguments.
579+
:type num_params: int
580+
581+
:param aggregate_class:
582+
A class that must implement the following methods:
520583

521-
*aggregate_class* must implement the following methods:
584+
* ``step()``: Add a row to the current window.
585+
* ``value()``: Return the current value of the aggregate.
586+
* ``inverse()``: Remove a row from the current window.
587+
* ``finalize()``: Return the final result of the aggregate as
588+
:ref:`a type natively supported by SQLite <sqlite3-types>`.
522589

523-
* ``step``: adds a row to the current window
524-
* ``value``: returns the current value of the aggregate
525-
* ``inverse``: removes a row from the current window
526-
* ``finalize``: returns the final value of the aggregate
590+
The number of arguments that the ``step()`` and ``value()`` methods
591+
must accept is controlled by *num_params*.
527592

528-
``step`` and ``value`` accept *num_params* number of parameters,
529-
unless *num_params* is ``-1``, in which case they may take any number of
530-
arguments.
531-
``finalize`` and ``value`` can return any of
532-
:ref:`the types natively supported by SQLite <sqlite3-types>`.
533-
Call :meth:`create_window_function` with
534-
*aggregate_class* set to :const:`None` to clear window function *name*.
593+
Set to :const:`None` to remove an existing SQL aggregate window function.
535594

536-
Aggregate window functions are supported by SQLite 3.25.0 and higher.
537-
:exc:`NotSupportedError` will be raised if used with older versions.
595+
:raises NotSupportedError:
596+
If used with a version of SQLite older than 3.25.0,
597+
which does not support aggregate window functions.
598+
599+
:type aggregate_class: :term:`class` | :const:`None`
538600

539601
.. versionadded:: 3.11
540602

@@ -734,29 +796,43 @@ Connection Objects
734796

735797
.. method:: backup(target, *, pages=-1, progress=None, name="main", sleep=0.250)
736798

737-
This method makes a backup of an SQLite database even while it's being accessed
738-
by other clients, or concurrently by the same connection. The copy will be
739-
written into the mandatory argument *target*, that must be another
740-
:class:`Connection` instance.
741-
742-
By default, or when *pages* is either ``0`` or a negative integer, the entire
743-
database is copied in a single step; otherwise the method performs a loop
744-
copying up to *pages* pages at a time.
745-
746-
If *progress* is specified, it must either be ``None`` or a callable object that
747-
will be executed at each iteration with three integer arguments, respectively
748-
the *status* of the last iteration, the *remaining* number of pages still to be
749-
copied and the *total* number of pages.
750-
751-
The *name* argument specifies the database name that will be copied: it must be
752-
a string containing either ``"main"``, the default, to indicate the main
753-
database, ``"temp"`` to indicate the temporary database or the name specified
754-
after the ``AS`` keyword in an ``ATTACH DATABASE`` statement for an attached
755-
database.
756-
757-
The *sleep* argument specifies the number of seconds to sleep by between
758-
successive attempts to backup remaining pages, can be specified either as an
759-
integer or a floating point value.
799+
Create a backup of an SQLite database.
800+
801+
Works even if the database is being accessed by other clients
802+
or concurrently by the same connection.
803+
804+
:param target:
805+
The database connection to save the backup to.
806+
:type target: Connection
807+
808+
:param pages:
809+
The number of pages to copy at a time.
810+
If equal to or less than ``0``,
811+
the entire database is copied in a single step.
812+
Defaults to ``-1``.
813+
:type pages: int
814+
815+
:param progress:
816+
If set to a callable, it is invoked with three integer arguments for
817+
every backup iteration:
818+
the *status* of the last iteration,
819+
the *remaining* number of pages still to be copied,
820+
and the *total* number of pages.
821+
Defaults to :const:`None`.
822+
:type progress: :term:`callback` | :const:`None`
823+
824+
:param name:
825+
The name of the database to back up.
826+
Either ``"main"`` (the default) for the main database,
827+
``"temp"`` for the temporary database,
828+
or the name of a custom database as attached using the
829+
``ATTACH DATABASE`` SQL statment.
830+
:type name: str
831+
832+
:param sleep:
833+
The number of seconds to sleep between successive attempts
834+
to back up remaining pages.
835+
:type sleep: float
760836

761837
Example 1, copy an existing database into another::
762838

0 commit comments

Comments
 (0)