mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-28 04:44:26 +02:00
make sure to close fp in case of UnicodeDecodeError
This commit is contained in:
parent
d3f097901c
commit
6e342b89ee
1 changed files with 10 additions and 6 deletions
|
|
@ -1949,12 +1949,16 @@ def memory(
|
||||||
fp = file_path.open("rb")
|
fp = file_path.open("rb")
|
||||||
rows, format_used = rows_from_file(fp, format=format, encoding=encoding)
|
rows, format_used = rows_from_file(fp, format=format, encoding=encoding)
|
||||||
tracker = None
|
tracker = None
|
||||||
if format_used in (Format.CSV, Format.TSV) and not no_detect_types:
|
try:
|
||||||
tracker = TypeTracker()
|
if format_used in (Format.CSV, Format.TSV) and not no_detect_types:
|
||||||
rows = tracker.wrap(rows)
|
tracker = TypeTracker()
|
||||||
if flatten:
|
rows = tracker.wrap(rows)
|
||||||
rows = (_flatten(row) for row in rows)
|
if flatten:
|
||||||
db[file_table].insert_all(rows, alter=True)
|
rows = (_flatten(row) for row in rows)
|
||||||
|
db[file_table].insert_all(rows, alter=True)
|
||||||
|
except UnicodeDecodeError as e:
|
||||||
|
fp.close()
|
||||||
|
raise e
|
||||||
if tracker is not None:
|
if tracker is not None:
|
||||||
db[file_table].transform(types=tracker.types)
|
db[file_table].transform(types=tracker.types)
|
||||||
# Add convenient t / t1 / t2 views
|
# Add convenient t / t1 / t2 views
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue