View Single Post
Old 02-26-2017, 03:33 PM   #12
milady133
Groupie
milady133 ought to be getting tired of karma fortunes by now.milady133 ought to be getting tired of karma fortunes by now.milady133 ought to be getting tired of karma fortunes by now.milady133 ought to be getting tired of karma fortunes by now.milady133 ought to be getting tired of karma fortunes by now.milady133 ought to be getting tired of karma fortunes by now.milady133 ought to be getting tired of karma fortunes by now.milady133 ought to be getting tired of karma fortunes by now.milady133 ought to be getting tired of karma fortunes by now.milady133 ought to be getting tired of karma fortunes by now.milady133 ought to be getting tired of karma fortunes by now.
 
Posts: 188
Karma: 616200
Join Date: May 2014
Location: Spain
Device: Kobo Forma, Hisense A5
OK, for those interested I'm going to write a small guide on how to get your collections and content back, but beware, this is not a step by step guide on purpose, because there may be to many different circunstances and you'll have to tweak yourself, so if you are going to follow my instructions, you need to be tech savvy enough to google for a solution if you have a problem, you don't need to be a database expert, but you need the patience to look for a solution. And also the patience to understand my English, cause it's not my native language, so some phrasing it's going to be weird

What you need:
  1. A backup of your KoboReader.sqlite database where the collections are present, if you use Calibre KoboUtilities plugin, you'll have it.
  2. A sqllite database manager, I have a firefox add-on named SQLite Manager, but anything that can open .sqlite databases will do.
  3. A backup of your Kobo device to restore it if anything goes wrong.

Now we are going to proceed:
  1. Connect your Kobo to your PC and open both databases, de Backup and the actual database in Kobo (it's in the .kobo folder), I recommend putting a different name to your backup database so you know wich one you are working on, for example, with SQLite Manager, if I rename the backup database from KoboReader.sqlite to backup.sqlite before opening it, I can see the name of the database file in the window so I avoid making mistakes.
  2. First, you are going to restore the content of the table with all the collections, the name of that table is Shelf.
    1. Select the content of that table in both databases to check that the structure of the table hasn't changed (they have the same columns) and the rows in kobo database have mostly dissapeared. You do that writing this order and executing the query:
      Code:
      SELECT * FROM Shelf ORDER BY Name
    2. When I compare the results, only one of the old collections survived, Wishlist, that collection I wasn't aware it existed, it was created by kobo and I never knew it was there, in the new kobo database I see that collection, and two new ones, another collection with the name Wishlist, but the Type is SystemTag instead of Custom, and another named ReadingList. I also see a new column in the table, _SyncTime, and the old collection has that column empty, so when I insert my collections I'm going to leave it empty.
    3. So now we are going to retrieve all the collections from the backup database, and we are going to create the INSERT order to create them in the Kobo database. Go to the backup and execute this query:
      Code:
      SELECT "INSERT INTO Shelf (CreationDate, Id, InternalName, LastModified, Name, Type, _IsDeleted, _IsVisible, _IsSynced) VALUES ('" || CreationDate || "', '" || Id || "', '" || InternalName || "', '" || LastModified || "', '" || Name || "', '" || Type || "', '" || _IsDeleted || "', '" || _IsVisible || "', '" || _IsSynced || "');" AS MyInsOrder FROM Shelf ORDER BY Name
    4. You get a list of your collections with the SQL order to insert them in your Kobo database, try only with one first, copy the first row and paste it where you have your Kobo database opened, and execute it, if it all goes well, then copy the rest of the lines (but the first one you have already executed not) and executed them.
    5. A couple of things, when I execute an insert, update or delete, I'm used to getting a message saying it all went well, but SQLite Manager doesn't say anything, only if something goes wrong (at least not the version I'm running), so to make sure everything goes well, I just execute the select order again to see the Kobo database now has the collections (SELECT * FROM Shelf ORDER BY Name). Another thing that puzzles me, is that I don't need to COMMIT my operations to the database, they are recorded inmediatly, I think is the usual with sqlite databases, but it's not the usual for me
  3. OK, now you have all your collections restored, we are going to reassociate our books with our collections, that happens in the ShelfContent table.
    1. Again, we are going to compare the tables in both databases, the backup and Kobo one, we run this select order:
      Code:
      SELECT * FROM ShelfContent ORDER BY ContentId, ShelfName
    2. In the Kobo database, I only see some items in the ReadingList and Wishlist collections, and I don't see new columns, so for me it's easy. You'll have to adapt this part of the instructions if you have deleted books between backups, or just try if trying to add a book that doesn't exists gives you an error (it's not going to break anything, but maybe if you run all the inserts at once, the rest of the inserts after the first error are going to be ignored).
    3. So the same as with the Shelf table, now we run this select in the backup database to get all the book-collection pairs we had:
      Code:
      SELECT "INSERT INTO ShelfContent (ShelfName, ContentId, DateModified, _IsDeleted, _IsSynced) VALUES ('" || ShelfName || "', '" || ContentId || "', '" || DateModified || "', '" || _IsDeleted || "', '" || _IsSynced ||"');" AS MyInsOrder FROM ShelfContent WHERE ShelfName <> 'Wishlist' ORDER BY ContentId, ShelfName
    4. You take the results, only the first line to test, and run the INSERT statement in the Kobo database to check everything is OK, and then the rest of the insert orders if everything goes well.
  4. You are done, as a last precaution, check the Kobo database to see it isn't corrupt (the application probably will have an utility to do that), close the database in the application, and unplug your Kobo from your PC the usual way. You should see now your collections restored.
That's all, I hope it's useful for someone.
Regards
milady133 is offline   Reply With Quote