Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added try / except to write_records #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions healthkit_to_sqlite/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from xml.etree import ElementTree as ET
import sqlite3


def find_all_tags(fp, tags, progress_callback=None):
Expand Down Expand Up @@ -139,9 +140,12 @@ def write_records(records, db):
records_by_type.setdefault(table, []).append(record)
# Bulk inserts for each one
for table, records_for_table in records_by_type.items():
db[table].insert_all(
records_for_table,
alter=True,
column_order=["startDate", "endDate", "value", "unit"],
batch_size=50,
)
try:
db[table].insert_all(
records_for_table,
alter=True,
column_order=["startDate", "endDate", "value", "unit"],
batch_size=50,
)
except (sqlite3.OperationalError, sqlite3.IntegrityError):
pass