From f690dab1ffd43363310c5eca6c9a8922d2960011 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 16 Apr 2012 12:30:36 +0530 Subject: [PATCH] T1 driver: Fix books sent to SD card sometimes resulting problems when deleted. Fixes #943586 (Transfert ebook on Micro SD - PRS T1 problem) --- src/calibre/devices/prst1/driver.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index 12867e0859..c2b04f11f7 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -307,11 +307,21 @@ class PRST1(USBMS): # Work-around for Sony Bug (SD Card DB not using right SQLite sequence) if source_id == 1: + # Update any existing sequence numbers in the table that aren't in the required range sdcard_sequence_start = '4294967296' query = 'UPDATE sqlite_sequence SET seq = ? WHERE seq < ?' t = (sdcard_sequence_start, sdcard_sequence_start,) cursor.execute(query, t) + # Insert sequence numbers for tables we will be manipulating, if they don't already exist + query = ('INSERT INTO sqlite_sequence (name, seq) ' + 'SELECT ?, ? ' + 'WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = ?)'); + cursor.execute(query, ('books',sdcard_sequence_start,'books',)) + cursor.execute(query, ('collection',sdcard_sequence_start,'collection',)) + cursor.execute(query, ('collections',sdcard_sequence_start,'collections',)) + + for book in booklist: # Run through plugboard if needed if plugboard is not None: