Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
fix segments not being quoted if they contain a comma, commit db tran…
Browse files Browse the repository at this point in the history
…sactions between COPY's
  • Loading branch information
jamesmeneghello committed Feb 11, 2015
1 parent 9926b72 commit b9bd6c2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pynab/parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def save_all(parts):
s.write('"' + part[item].replace(tzinfo=None).strftime('%Y-%m-%d %H:%M:%S').replace('"',
'\\"') + '",')
elif item == 'xref':
# leave off the tab
# leave off the comma
s.write('"' + part[item].replace('"', '\\"') + '"')
else:
s.write('"' + str(part[item]).replace('"', '\\"') + '",')
Expand All @@ -69,6 +69,8 @@ def save_all(parts):

copy_file(engine, s, ordering, Part)

db.commit()

with db_session() as db:
existing_parts = dict(
((part.hash, part) for part in
Expand Down Expand Up @@ -111,14 +113,16 @@ def save_all(parts):
for item in ordering:
if item == 'part_id':
# leave off the tab
s.write(str(segment[item]))
s.write('"' + str(segment[item]).replace('"', '\\"') + '"')
else:
s.write(str(segment[item]) + ",")
s.write('"' + str(segment[item]).replace('"', '\\"') + '",')
s.write("\n")
s.seek(0)

copy_file(engine, s, ordering, Segment)

db.commit()

end = time.time()

log.debug('parts: saved {} parts and {} segments in {:.2f}s'.format(
Expand Down

0 comments on commit b9bd6c2

Please sign in to comment.