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
(cherry picked from commit bf92597)
Co-authored-by: Erlend E. Aasland <[email protected]>
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>)
382
-
<sqlite3.Cursor object at 0x10b1fe840>
386
+
>>> sys.unraisablehook =debug
387
+
>>> cur = con.execute("select 1")
388
+
ZeroDivisionError('division by zero') in callback evil_trace
389
+
Error message: None
383
390
384
391
.. function:: register_adapter(type, adapter, /)
385
392
@@ -926,12 +933,12 @@ Connection objects
926
933
Useful when saving an in-memory database for later restoration.
927
934
Similar to the ``.dump`` command in the :program:`sqlite3` shell.
928
935
929
-
Example::
936
+
Example:
930
937
931
-
# Convert file existing_db.db to SQL dump file dump.sql
932
-
import sqlite3
938
+
.. testcode::
933
939
934
-
con = sqlite3.connect('existing_db.db')
940
+
# Convert file example.db to SQL dump file dump.sql
941
+
con = sqlite3.connect('example.db')
935
942
with open('dump.sql', 'w') as f:
936
943
for line in con.iterdump():
937
944
f.write('%s\n' % line)
@@ -974,27 +981,32 @@ Connection objects
974
981
The number of seconds to sleep between successive attempts
975
982
to back up remaining pages.
976
983
977
-
Example 1, copy an existing database into another::
984
+
Example 1, copy an existing database into another:
978
985
979
-
import sqlite3
986
+
.. testcode::
980
987
981
988
def progress(status, remaining, total):
982
989
print(f'Copied {total-remaining} of {total} pages...')
983
990
984
-
con = sqlite3.connect('existing_db.db')
985
-
bck = sqlite3.connect('backup.db')
986
-
with bck:
987
-
con.backup(bck, pages=1, progress=progress)
988
-
bck.close()
989
-
con.close()
991
+
src = sqlite3.connect('example.db')
992
+
dst = sqlite3.connect('backup.db')
993
+
with dst:
994
+
src.backup(dst, pages=1, progress=progress)
995
+
dst.close()
996
+
src.close()
990
997
991
-
Example 2, copy an existing database into a transient copy::
998
+
.. testoutput::
999
+
:hide:
992
1000
993
-
import sqlite3
1001
+
Copied 0 of 0 pages...
994
1002
995
-
source = sqlite3.connect('existing_db.db')
996
-
dest = sqlite3.connect(':memory:')
997
-
source.backup(dest)
1003
+
Example 2, copy an existing database into a transient copy:
1004
+
1005
+
.. testcode::
1006
+
1007
+
src = sqlite3.connect('example.db')
1008
+
dst = sqlite3.connect(':memory:')
1009
+
src.backup(dst)
998
1010
999
1011
.. versionadded:: 3.7
1000
1012
@@ -1010,12 +1022,20 @@ Connection objects
1010
1022
:raises ProgrammingError:
1011
1023
If *category* is not recognised by the underlying SQLite library.
1012
1024
1013
-
Example, query the maximum length of an SQL statement::
1025
+
Example, query the maximum length of an SQL statement
1026
+
for :class:`Connection` ``con`` (the default is 1000000000):
0 commit comments