From c91f1e6957fc7f3678a04f23d969e587ed4eacb9 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 29 Nov 2021 15:29:23 -0800 Subject: [PATCH] iterdump() workaround for compatibility with pysqlite3 --- sqlite_utils/cli.py | 7 ++++--- sqlite_utils/utils.py | 1 + tests/test_analyze_tables.py | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index cd0be829b..c032bec36 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -19,6 +19,7 @@ from .utils import ( file_progress, find_spatialite, + iterdump, sqlite3, decode_base64_values, progressbar, @@ -326,7 +327,7 @@ def dump(path, load_extension): """Output a SQL dump of the schema and full contents of the database""" db = sqlite_utils.Database(path) _load_extensions(db, load_extension) - for line in db.conn.iterdump(): + for line in iterdump(db.conn): click.echo(line) @@ -1320,7 +1321,7 @@ def memory( return if dump: - for line in db.conn.iterdump(): + for line in iterdump(db.conn): click.echo(line) return @@ -1330,7 +1331,7 @@ def memory( if save: db2 = sqlite_utils.Database(save) - for line in db.conn.iterdump(): + for line in iterdump(db.conn): db2.execute(line) return diff --git a/sqlite_utils/utils.py b/sqlite_utils/utils.py index 00a3c02b5..4116b5f66 100644 --- a/sqlite_utils/utils.py +++ b/sqlite_utils/utils.py @@ -5,6 +5,7 @@ import io import json import os +from sqlite3.dump import _iterdump as iterdump from typing import cast, BinaryIO, Iterable, Optional, Tuple, Type import click diff --git a/tests/test_analyze_tables.py b/tests/test_analyze_tables.py index 5795a7a1b..2df2698c6 100644 --- a/tests/test_analyze_tables.py +++ b/tests/test_analyze_tables.py @@ -1,5 +1,6 @@ from sqlite_utils.db import Database, ColumnDetails from sqlite_utils import cli +from sqlite_utils.utils import iterdump from click.testing import CliRunner import pytest import sqlite3 @@ -79,7 +80,7 @@ def test_analyze_column(db_to_analyze, column, expected): def db_to_analyze_path(db_to_analyze, tmpdir): path = str(tmpdir / "test.db") db = sqlite3.connect(path) - db.executescript("\n".join(db_to_analyze.conn.iterdump())) + db.executescript("\n".join(iterdump(db_to_analyze.conn))) return path