@@ -286,7 +286,7 @@ Module functions and constants
286
286
Can be ``"DEFERRED" `` (default), ``"EXCLUSIVE" `` or ``"IMMEDIATE" ``;
287
287
or :const: `None ` to disable opening transactions implicitly.
288
288
See :ref: `sqlite3-controlling-transactions ` for more.
289
- :type isolation_level: str | None
289
+ :type isolation_level: str | :const: ` None `
290
290
291
291
:param check_same_thread:
292
292
If :const: `True ` (default), only the creating thread may use the connection.
@@ -316,7 +316,7 @@ Module functions and constants
316
316
enabling various :ref: `sqlite3-uri-tricks `.
317
317
:type uri: bool
318
318
319
- :rtype: sqlite3. Connection
319
+ :rtype: Connection
320
320
321
321
.. audit-event :: sqlite3.connect database sqlite3.connect
322
322
.. audit-event :: sqlite3.connect/handle connection_handle sqlite3.connect
@@ -434,13 +434,36 @@ Connection Objects
434
434
435
435
.. method :: blobopen(table, column, row, /, *, readonly=False, name="main")
436
436
437
- Open a :class: `Blob ` handle to the :abbr: `BLOB ( Binary Large OBject ) `
438
- located in table name *table *, column name *column *, and row index *row *
439
- of database *name *.
440
- When *readonly * is :const: `True ` the blob is opened without write
441
- permissions.
442
- Trying to open a blob in a ``WITHOUT ROWID `` table will raise
443
- :exc: `OperationalError `.
437
+ Open a :class: `Blob ` handle to an existing
438
+ :abbr: `BLOB ( Binary Large OBject ) `.
439
+
440
+ :param table:
441
+ The name of the table where the blob is located.
442
+ :type table: str
443
+
444
+ :param column:
445
+ The name of the column where the blob is located.
446
+ :type column: str
447
+
448
+ :param row:
449
+ The name of the row where the blob is located.
450
+ :type row: str
451
+
452
+ :param readonly:
453
+ Set to :const: `True ` if the blob should be opened without write
454
+ permissions.
455
+ Defaults to :const: `False `.
456
+ :type readonly: bool
457
+
458
+ :param name:
459
+ The name of the database where the blob is located.
460
+ Defaults to ``"main" ``.
461
+ :type name: str
462
+
463
+ :raises OperationalError:
464
+ When trying to open a blob in a ``WITHOUT ROWID `` table.
465
+
466
+ :rtype: Blob
444
467
445
468
.. note ::
446
469
@@ -486,21 +509,35 @@ Connection Objects
486
509
487
510
.. method :: create_function(name, narg, func, *, deterministic=False)
488
511
489
- Creates a user-defined function that you can later use from within SQL
490
- statements under the function name *name *. *narg * is the number of
491
- parameters the function accepts (if *narg * is -1, the function may
492
- take any number of arguments), and *func * is a Python callable that is
493
- called as the SQL function. If *deterministic * is true, the created function
494
- is marked as `deterministic <https://sqlite.org/deterministic.html >`_, which
495
- allows SQLite to perform additional optimizations. This flag is supported by
496
- SQLite 3.8.3 or higher, :exc: `NotSupportedError ` will be raised if used
497
- with older versions.
512
+ Create or remove a user-defined SQL function.
513
+
514
+ :param name:
515
+ The name of the SQL function.
516
+ :type name: str
517
+
518
+ :param narg:
519
+ The number of arguments the SQL function can accept.
520
+ If ``-1 ``, it may take any number of arguments.
521
+ :type narg: int
498
522
499
- The function can return any of
500
- :ref: `the types natively supported by SQLite <sqlite3-types >`.
523
+ :param func:
524
+ A callable that is called when the SQL function is invoked.
525
+ The callable must return :ref: `a type natively supported by SQLite
526
+ <sqlite3-types>`.
527
+ Set to :const: `None ` to remove an existing SQL function.
528
+ :type func: :term: `callback ` | :const: `None `
501
529
502
- .. versionchanged :: 3.8
503
- The *deterministic * parameter was added.
530
+ :param deterministic:
531
+ If :const: `True `, the created SQL function is marked as
532
+ `deterministic <https://sqlite.org/deterministic.html >`_,
533
+ which allows SQLite to perform additional optimizations.
534
+ :type deterministic: bool
535
+
536
+ :raises NotSupportedError:
537
+ If *deterministic * is used with SQLite versions older than 3.8.3.
538
+
539
+ .. versionadded :: 3.8
540
+ The *deterministic * parameter.
504
541
505
542
Example:
506
543
@@ -509,15 +546,29 @@ Connection Objects
509
546
510
547
.. method :: create_aggregate(name, /, n_arg, aggregate_class)
511
548
512
- Creates a user-defined aggregate function.
549
+ Create or remove a user-defined SQL aggregate function.
550
+
551
+ :param name:
552
+ The name of the SQL aggregate function.
553
+ :type name: str
513
554
514
- The aggregate class must implement a `` step `` method, which accepts the number
515
- of parameters * n_arg * (if * n_arg * is -1, the function may take
516
- any number of arguments), and a `` finalize `` method which will return the
517
- final result of the aggregate.
555
+ :param n_arg:
556
+ The number of arguments the SQL aggregate function can accept.
557
+ If `` -1 ``, it may take any number of arguments.
558
+ :type n_arg: int
518
559
519
- The ``finalize `` method can return any of
520
- :ref: `the types natively supported by SQLite <sqlite3-types >`.
560
+ :param aggregate_class:
561
+ A class must implement the following methods:
562
+
563
+ * ``step() ``: Add a row to the aggregate.
564
+ * ``finalize() ``: Return the final result of the aggregate as
565
+ :ref: `a type natively supported by SQLite <sqlite3-types >`.
566
+
567
+ The number of arguments that the ``step() `` method must accept
568
+ is controlled by *n_arg *.
569
+
570
+ Set to :const: `None ` to remove an existing SQL aggregate function.
571
+ :type aggregate_class: :term: `class ` | :const: `None `
521
572
522
573
Example:
523
574
@@ -526,25 +577,36 @@ Connection Objects
526
577
527
578
.. method :: create_window_function(name, num_params, aggregate_class, /)
528
579
529
- Creates user-defined aggregate window function *name *.
580
+ Create or remove a user-defined aggregate window function.
581
+
582
+ :param name:
583
+ The name of the SQL aggregate window function to create or remove.
584
+ :type name: str
585
+
586
+ :param num_params:
587
+ The number of arguments the SQL aggregate window function can accept.
588
+ If ``-1 ``, it may take any number of arguments.
589
+ :type num_params: int
590
+
591
+ :param aggregate_class:
592
+ A class that must implement the following methods:
530
593
531
- *aggregate_class * must implement the following methods:
594
+ * ``step() ``: Add a row to the current window.
595
+ * ``value() ``: Return the current value of the aggregate.
596
+ * ``inverse() ``: Remove a row from the current window.
597
+ * ``finalize() ``: Return the final result of the aggregate as
598
+ :ref: `a type natively supported by SQLite <sqlite3-types >`.
532
599
533
- * ``step ``: adds a row to the current window
534
- * ``value ``: returns the current value of the aggregate
535
- * ``inverse ``: removes a row from the current window
536
- * ``finalize ``: returns the final value of the aggregate
600
+ The number of arguments that the ``step() `` and ``value() `` methods
601
+ must accept is controlled by *num_params *.
537
602
538
- ``step `` and ``value `` accept *num_params * number of parameters,
539
- unless *num_params * is ``-1 ``, in which case they may take any number of
540
- arguments.
541
- ``finalize `` and ``value `` can return any of
542
- :ref: `the types natively supported by SQLite <sqlite3-types >`.
543
- Call :meth: `create_window_function ` with
544
- *aggregate_class * set to :const: `None ` to clear window function *name *.
603
+ Set to :const: `None ` to remove an existing SQL aggregate window function.
545
604
546
- Aggregate window functions are supported by SQLite 3.25.0 and higher.
547
- :exc: `NotSupportedError ` will be raised if used with older versions.
605
+ :raises NotSupportedError:
606
+ If used with a version of SQLite older than 3.25.0,
607
+ which does not support aggregate window functions.
608
+
609
+ :type aggregate_class: :term: `class ` | :const: `None `
548
610
549
611
.. versionadded :: 3.11
550
612
@@ -744,29 +806,43 @@ Connection Objects
744
806
745
807
.. method :: backup(target, *, pages=-1, progress=None, name="main", sleep=0.250)
746
808
747
- This method makes a backup of an SQLite database even while it's being accessed
748
- by other clients, or concurrently by the same connection. The copy will be
749
- written into the mandatory argument *target *, that must be another
750
- :class: `Connection ` instance.
751
-
752
- By default, or when *pages * is either ``0 `` or a negative integer, the entire
753
- database is copied in a single step; otherwise the method performs a loop
754
- copying up to *pages * pages at a time.
755
-
756
- If *progress * is specified, it must either be ``None `` or a callable object that
757
- will be executed at each iteration with three integer arguments, respectively
758
- the *status * of the last iteration, the *remaining * number of pages still to be
759
- copied and the *total * number of pages.
760
-
761
- The *name * argument specifies the database name that will be copied: it must be
762
- a string containing either ``"main" ``, the default, to indicate the main
763
- database, ``"temp" `` to indicate the temporary database or the name specified
764
- after the ``AS `` keyword in an ``ATTACH DATABASE `` statement for an attached
765
- database.
766
-
767
- The *sleep * argument specifies the number of seconds to sleep by between
768
- successive attempts to backup remaining pages, can be specified either as an
769
- integer or a floating point value.
809
+ Create a backup of an SQLite database.
810
+
811
+ Works even if the database is being accessed by other clients
812
+ or concurrently by the same connection.
813
+
814
+ :param target:
815
+ The database connection to save the backup to.
816
+ :type target: Connection
817
+
818
+ :param pages:
819
+ The number of pages to copy at a time.
820
+ If equal to or less than ``0 ``,
821
+ the entire database is copied in a single step.
822
+ Defaults to ``-1 ``.
823
+ :type pages: int
824
+
825
+ :param progress:
826
+ If set to a callable, it is invoked with three integer arguments for
827
+ every backup iteration:
828
+ the *status * of the last iteration,
829
+ the *remaining * number of pages still to be copied,
830
+ and the *total * number of pages.
831
+ Defaults to :const: `None `.
832
+ :type progress: :term: `callback ` | :const:`None`
833
+
834
+ :param name:
835
+ The name of the database to back up.
836
+ Either ``"main" `` (the default) for the main database,
837
+ ``"temp" `` for the temporary database,
838
+ or the name of a custom database as attached using the
839
+ ``ATTACH DATABASE `` SQL statment.
840
+ :type name: str
841
+
842
+ :param sleep:
843
+ The number of seconds to sleep between successive attempts
844
+ to back up remaining pages.
845
+ :type sleep: float
770
846
771
847
Example 1, copy an existing database into another::
772
848
0 commit comments