You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a consequence of the added test, this commit also includes
fixes for broken examples.
- Add separate namespace for trace tests bco. module level callback
- Move more backup and cursor examples under separate namespaces
UnraisableHookArgs(exc_type=<class 'ZeroDivisionError'>, exc_value=ZeroDivisionError('division by zero'), exc_traceback=<traceback object at 0x10b559900>, err_msg=None, object=<function <lambda> at 0x10b4e3ee0>)
385
-
<sqlite3.Cursor object at 0x10b1fe840>
389
+
>>> sys.unraisablehook =debug
390
+
>>> cur = con.execute("select 1")
391
+
ZeroDivisionError('division by zero') in callback evil_trace
392
+
Error message: None
386
393
387
394
.. function:: register_adapter(type, adapter, /)
388
395
@@ -939,12 +946,12 @@ Connection objects
939
946
Useful when saving an in-memory database for later restoration.
940
947
Similar to the ``.dump`` command in the :program:`sqlite3` shell.
941
948
942
-
Example::
949
+
Example:
943
950
944
-
# Convert file existing_db.db to SQL dump file dump.sql
945
-
import sqlite3
951
+
.. testcode::
946
952
947
-
con = sqlite3.connect('existing_db.db')
953
+
# Convert file example.db to SQL dump file dump.sql
954
+
con = sqlite3.connect('example.db')
948
955
with open('dump.sql', 'w') as f:
949
956
for line in con.iterdump():
950
957
f.write('%s\n' % line)
@@ -987,27 +994,32 @@ Connection objects
987
994
The number of seconds to sleep between successive attempts
988
995
to back up remaining pages.
989
996
990
-
Example 1, copy an existing database into another::
997
+
Example 1, copy an existing database into another:
991
998
992
-
import sqlite3
999
+
.. testcode::
993
1000
994
1001
def progress(status, remaining, total):
995
1002
print(f'Copied {total-remaining} of {total} pages...')
996
1003
997
-
con = sqlite3.connect('existing_db.db')
998
-
bck = sqlite3.connect('backup.db')
999
-
with bck:
1000
-
con.backup(bck, pages=1, progress=progress)
1001
-
bck.close()
1002
-
con.close()
1004
+
src = sqlite3.connect('example.db')
1005
+
dst = sqlite3.connect('backup.db')
1006
+
with dst:
1007
+
src.backup(dst, pages=1, progress=progress)
1008
+
dst.close()
1009
+
src.close()
1003
1010
1004
-
Example 2, copy an existing database into a transient copy::
1011
+
.. testoutput::
1012
+
:hide:
1005
1013
1006
-
import sqlite3
1014
+
Copied 0 of 0 pages...
1007
1015
1008
-
source = sqlite3.connect('existing_db.db')
1009
-
dest = sqlite3.connect(':memory:')
1010
-
source.backup(dest)
1016
+
Example 2, copy an existing database into a transient copy:
1017
+
1018
+
.. testcode::
1019
+
1020
+
src = sqlite3.connect('example.db')
1021
+
dst = sqlite3.connect(':memory:')
1022
+
src.backup(dst)
1011
1023
1012
1024
.. versionadded:: 3.7
1013
1025
@@ -1023,12 +1035,20 @@ Connection objects
1023
1035
:raises ProgrammingError:
1024
1036
If *category* is not recognised by the underlying SQLite library.
1025
1037
1026
-
Example, query the maximum length of an SQL statement::
1038
+
Example, query the maximum length of an SQL statement
1039
+
for :class:`Connection` ``con`` (the default is 1000000000):
0 commit comments