From 7d3711bf5aff8ebd8969961e6b00abd7fef5353d Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Sat, 1 Oct 2016 11:47:00 -0700 Subject: [PATCH] Add last_insert_id module to database --- plexpy/activity_processor.py | 3 +-- plexpy/database.py | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plexpy/activity_processor.py b/plexpy/activity_processor.py index 79ab36af..dabe91e3 100644 --- a/plexpy/activity_processor.py +++ b/plexpy/activity_processor.py @@ -265,8 +265,7 @@ class ActivityProcessor(object): 'reference_id': result[1]['reference_id']} else: # Get the last insert row id - result = self.db.select(query='SELECT last_insert_rowid() AS last_id') - last_id = result[0]['last_id'] if result else None + last_id = self.db.last_insert_id() query = 'UPDATE session_history SET reference_id = ? WHERE id = ? ' # If rating_key is the same in the previous session, then set the reference_id to the previous row, else set the reference_id to the new id diff --git a/plexpy/database.py b/plexpy/database.py index 2bd8902c..8073e914 100644 --- a/plexpy/database.py +++ b/plexpy/database.py @@ -203,3 +203,9 @@ class MonitorDatabase(object): # We want to know if it was an update or insert return trans_type + + def last_insert_id(self): + # Get the last insert row id + result = self.select_single(query='SELECT last_insert_rowid() AS last_id') + if result: + return result.get('last_id', None) \ No newline at end of file