From 530d726da29515f0e72126976f74375300ee048b Mon Sep 17 00:00:00 2001 From: Kolenka Date: Mon, 4 Jun 2012 23:29:39 -0700 Subject: [PATCH 1/2] Typo fix + 'safe' lastrowid. --- src/calibre/devices/prst1/driver.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index 6e231a0d1c..74692447ab 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -314,6 +314,13 @@ class PRST1(USBMS): ' any notes/highlights, etc.')%dbpath)+' Underlying error:' '\n'+tb) + def get_lastrowid(self, cursor): + query = 'SELECT last_insert_rowid()' + cursor.execute(query) + row = cursor.fetchone() + + return long(row[0]) + def get_database_min_id(self, source_id): sequence_min = 0L if source_id == 1: @@ -471,10 +478,10 @@ class PRST1(USBMS): modified_date, lpath, os.path.basename(lpath), book.size, book.mime) cursor.execute(query, t) - book.bookId = cursor.lastrowid + book.bookId = self.get_lastrowid(cursor) if upload_covers: self.upload_book_cover(connection, book, source_id) - debug_print('Inserted New Book: ' + book.title) + debug_print('Inserted New Book: (%u) '%book.bookId + book.title) else: query = ''' UPDATE books @@ -609,8 +616,8 @@ class PRST1(USBMS): query = 'INSERT INTO collection (title, source_id) VALUES (?,?)' t = (collection, source_id) cursor.execute(query, t) - db_collections[collection] = cursor.lastrowid - debug_print('Inserted New Collection: ' + collection) + db_collections[collection] = self.get_lastrowid(cursor) + debug_print('Inserted New Collection: (%u) '%db_collections[collection] + collection) # Get existing books in collection query = ''' From a3e9886142f3cdbe10a3cdfd23440f79acf6ece8 Mon Sep 17 00:00:00 2001 From: Kolenka Date: Mon, 4 Jun 2012 23:31:52 -0700 Subject: [PATCH 2/2] Added comment --- src/calibre/devices/prst1/driver.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index 74692447ab..a2b3716c05 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -315,6 +315,8 @@ class PRST1(USBMS): '\n'+tb) def get_lastrowid(self, cursor): + # SQLite3 + Python has a fun issue on 32-bit systems with integer overflows. + # Issue a SQL query instead, getting the value as a string, and then converting to a long python int manually. query = 'SELECT last_insert_rowid()' cursor.execute(query) row = cursor.fetchone()