Skip to content

Commit

Permalink
Don't insert records multiple times
Browse files Browse the repository at this point in the history
:func:`processEvent` was adding each record multiple times, so shift the
execution of the db update out of the location loop.
  • Loading branch information
wcarthur committed Sep 9, 2015
1 parent 09cb040 commit 2a16b72
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,17 @@ def processEvent(self, filename, locations):
float(locVa), float(locPr), " ", datetime.now())
params.append(locParams)

try:
self.executemany(INSWINDSPEED, params)
except sqlite3.Error as err:
log.exception("Cannot insert records into tblWindSpeed: {0}".\
format(err.args[0]))
return 0
except sqlite3.ProgrammingError as err:
log.exception("Programming error: {0}".format(err.args[0]))
return 0
else:
self.commit()
try:
self.executemany(INSWINDSPEED, params)
except sqlite3.Error as err:
log.exception("Cannot insert records into tblWindSpeed: {0}".\
format(err.args[0]))
return 0
except sqlite3.ProgrammingError as err:
log.exception("Programming error: {0}".format(err.args[0]))
return 0
else:
self.commit()

return 1

Expand Down Expand Up @@ -601,11 +601,9 @@ def locationRecordsExceeding(hazard_db, locId, windSpeed):
"""

query = ("SELECT l.locId, l.locName, w.wspd, w.eventId, "
"e.eventFile "
query = ("SELECT l.locId, l.locName, w.wspd, w.eventId "
"FROM tblLocations l "
"INNER JOIN tblWindSpeed w ON l.locId = w.locId "
"JOIN tblEvents e ON e.eventId = w.eventId "
"WHERE w.wspd > ? and l.locId = ? "
"ORDER BY w.wspd ASC" )

Expand Down

0 comments on commit 2a16b72

Please sign in to comment.