mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-16 13:34:10 +02:00
fix for problem in Table.insert_all on search for columns per chunk of rows
This commit is contained in:
parent
36dc7e3909
commit
929ea75511
3 changed files with 27 additions and 12 deletions
|
|
@ -1886,12 +1886,12 @@ class Table(Queryable):
|
|||
if hash_id:
|
||||
all_columns.insert(0, hash_id)
|
||||
else:
|
||||
all_columns += [
|
||||
column
|
||||
for record in chunk
|
||||
for column in record
|
||||
if column not in all_columns
|
||||
]
|
||||
for record in chunk:
|
||||
all_columns += [
|
||||
column
|
||||
for column in record
|
||||
if column not in all_columns
|
||||
]
|
||||
|
||||
validate_column_names(all_columns)
|
||||
first = False
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from click.testing import CliRunner
|
|||
import json
|
||||
import os
|
||||
import pytest
|
||||
import sys
|
||||
from sqlite_utils.utils import sqlite3, find_spatialite
|
||||
import textwrap
|
||||
|
||||
|
|
@ -93,7 +94,10 @@ def test_tables_counts_and_columns_csv(db_path, format, expected):
|
|||
result = CliRunner().invoke(
|
||||
cli.cli, ["tables", "--counts", "--columns", format, db_path]
|
||||
)
|
||||
assert result.output.strip() == expected
|
||||
if sys.platform == 'win32':
|
||||
assert result.output.strip().replace('\r', '') == expected
|
||||
else:
|
||||
assert result.output.strip() == expected
|
||||
|
||||
|
||||
def test_tables_schema(db_path):
|
||||
|
|
@ -860,12 +864,18 @@ def test_query_csv(db_path, format, expected):
|
|||
cli.cli, [db_path, "select id, name, age from dogs", format]
|
||||
)
|
||||
assert 0 == result.exit_code
|
||||
assert result.output == expected
|
||||
if sys.platform == 'win32':
|
||||
assert result.output.replace('\r', '') == expected
|
||||
else:
|
||||
assert result.output == expected
|
||||
# Test the no-headers option:
|
||||
result = CliRunner().invoke(
|
||||
cli.cli, [db_path, "select id, name, age from dogs", "--no-headers", format]
|
||||
)
|
||||
assert result.output.strip() == "\n".join(expected.split("\n")[1:]).strip()
|
||||
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()
|
||||
|
||||
|
||||
_all_query = "select id, name, age from dogs"
|
||||
|
|
@ -1750,7 +1760,10 @@ def test_search(tmpdir, fts, extra_arg, expected):
|
|||
catch_exceptions=False,
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert result.output == expected
|
||||
if sys.platform == 'win32':
|
||||
assert result.output.replace('\r', '') == expected
|
||||
else:
|
||||
assert result.output == expected
|
||||
|
||||
|
||||
_TRIGGERS_EXPECTED = '[{"name": "blah", "table": "articles", "sql": "CREATE TRIGGER blah AFTER INSERT ON articles\\nBEGIN\\n UPDATE counter SET count = count + 1;\\nEND"}]\n'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import os
|
||||
|
||||
from sqlite_utils import cli, Database
|
||||
from click.testing import CliRunner
|
||||
import pathlib
|
||||
|
|
@ -42,7 +44,7 @@ def test_insert_files():
|
|||
one, two, three = (
|
||||
rows_by_path["one.txt"],
|
||||
rows_by_path["two.txt"],
|
||||
rows_by_path["nested/three.txt"],
|
||||
rows_by_path[os.path.join("nested", "three.txt")],
|
||||
)
|
||||
assert {
|
||||
"content": b"This is file one",
|
||||
|
|
@ -64,7 +66,7 @@ def test_insert_files():
|
|||
"content": b"Three is nested",
|
||||
"md5": "12580f341781f5a5b589164d3cd39523",
|
||||
"name": "three.txt",
|
||||
"path": "nested/three.txt",
|
||||
"path": os.path.join("nested", "three.txt"),
|
||||
"sha256": "6dd45aaaaa6b9f96af19363a92c8fca5d34791d3c35c44eb19468a6a862cc8cd",
|
||||
"size": 15,
|
||||
}.items() <= three.items()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue