fix for problem in Table.insert_all on search for columns per chunk of rows

This commit is contained in:
Frans 2021-01-29 20:58:37 +01:00
commit 929ea75511
3 changed files with 27 additions and 12 deletions

View file

@ -1886,9 +1886,9 @@ class Table(Queryable):
if hash_id: if hash_id:
all_columns.insert(0, hash_id) all_columns.insert(0, hash_id)
else: else:
for record in chunk:
all_columns += [ all_columns += [
column column
for record in chunk
for column in record for column in record
if column not in all_columns if column not in all_columns
] ]

View file

@ -4,6 +4,7 @@ from click.testing import CliRunner
import json import json
import os import os
import pytest import pytest
import sys
from sqlite_utils.utils import sqlite3, find_spatialite from sqlite_utils.utils import sqlite3, find_spatialite
import textwrap import textwrap
@ -93,6 +94,9 @@ def test_tables_counts_and_columns_csv(db_path, format, expected):
result = CliRunner().invoke( result = CliRunner().invoke(
cli.cli, ["tables", "--counts", "--columns", format, db_path] cli.cli, ["tables", "--counts", "--columns", format, db_path]
) )
if sys.platform == 'win32':
assert result.output.strip().replace('\r', '') == expected
else:
assert result.output.strip() == expected assert result.output.strip() == expected
@ -860,11 +864,17 @@ def test_query_csv(db_path, format, expected):
cli.cli, [db_path, "select id, name, age from dogs", format] cli.cli, [db_path, "select id, name, age from dogs", format]
) )
assert 0 == result.exit_code assert 0 == result.exit_code
if sys.platform == 'win32':
assert result.output.replace('\r', '') == expected
else:
assert result.output == expected assert result.output == expected
# Test the no-headers option: # Test the no-headers option:
result = CliRunner().invoke( result = CliRunner().invoke(
cli.cli, [db_path, "select id, name, age from dogs", "--no-headers", format] cli.cli, [db_path, "select id, name, age from dogs", "--no-headers", format]
) )
if sys.platform == 'win32':
assert result.output.strip().replace('\r', '') == "\n".join(expected.split("\n")[1:]).strip()
else:
assert result.output.strip() == "\n".join(expected.split("\n")[1:]).strip() assert result.output.strip() == "\n".join(expected.split("\n")[1:]).strip()
@ -1750,6 +1760,9 @@ def test_search(tmpdir, fts, extra_arg, expected):
catch_exceptions=False, catch_exceptions=False,
) )
assert result.exit_code == 0 assert result.exit_code == 0
if sys.platform == 'win32':
assert result.output.replace('\r', '') == expected
else:
assert result.output == expected assert result.output == expected

View file

@ -1,3 +1,5 @@
import os
from sqlite_utils import cli, Database from sqlite_utils import cli, Database
from click.testing import CliRunner from click.testing import CliRunner
import pathlib import pathlib
@ -42,7 +44,7 @@ def test_insert_files():
one, two, three = ( one, two, three = (
rows_by_path["one.txt"], rows_by_path["one.txt"],
rows_by_path["two.txt"], rows_by_path["two.txt"],
rows_by_path["nested/three.txt"], rows_by_path[os.path.join("nested", "three.txt")],
) )
assert { assert {
"content": b"This is file one", "content": b"This is file one",
@ -64,7 +66,7 @@ def test_insert_files():
"content": b"Three is nested", "content": b"Three is nested",
"md5": "12580f341781f5a5b589164d3cd39523", "md5": "12580f341781f5a5b589164d3cd39523",
"name": "three.txt", "name": "three.txt",
"path": "nested/three.txt", "path": os.path.join("nested", "three.txt"),
"sha256": "6dd45aaaaa6b9f96af19363a92c8fca5d34791d3c35c44eb19468a6a862cc8cd", "sha256": "6dd45aaaaa6b9f96af19363a92c8fca5d34791d3c35c44eb19468a6a862cc8cd",
"size": 15, "size": 15,
}.items() <= three.items() }.items() <= three.items()