|  02-03-2010, 02:51 PM | #1 | 
| Junior Member  Posts: 1 Karma: 10 Join Date: Feb 2010 Device: Sony touch | 
				
				manually editing database
			 
			
			Hello  I have just installed Calibre and it seems to be the software i need. The problem is that I did a bunch of cataloguing in another software. The question is: How can i open the Caliber database file as a spreadsheet, copy the information in the right fields (author, title, path) and save it again so that caliber recognizes the information next time i open it? Many thanks | 
|   |   | 
|  02-03-2010, 05:57 PM | #2 | 
| Wizard            Posts: 4,553 Karma: 950151 Join Date: Nov 2008 Device: Sony PRS-950, iphone/ipad (Marvin/iBooks/QuickReader) | 
			
			You cannot access the Calibre database in that way without constructing some very complicated SQL queries.
		 | 
|   |   | 
|  02-03-2010, 06:08 PM | #3 | |
| Well trained by Cats            Posts: 31,249 Karma: 61360164 Join Date: Aug 2009 Location: The Central Coast of California Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A | Quote: 
 It has its own file management (adds the DB ID to the file folder it keeps all the versions in). Don't muck with the file names or their individual placement if you still want things to work afterwards   | |
|   |   | 
|  02-04-2010, 04:23 AM | #4 | 
| Addict     Posts: 223 Karma: 356 Join Date: Aug 2007 Device: Rocket; Hiebook; N700; Sony 505; Kindle DX ... | 
			
			If I may insert myself in this thread, I wondered about the same things for some time... Given the time I spent inserting & manually editing the records for my books, I'd like the result to stay alive&working as long as possible. Of course I wish Kovid a long and productive life, but what happens if he for some reason stops developing calibre (or is kidnapped by aliens, or ...)? That's the reason we like open formats - as Calibre is, luckily. Therefore I am very interested in any info regarding <alternative> ways to delve into its structure. And since this structure is documented, any problems will surely be due to the operator mishandling it - backups are there for a reason... So, any info for hacking the database is welcome (I saw some people in other threads mention SQL queries, time ago), and if the thread can be made sticky, all the better alessandro | 
|   |   | 
|  02-04-2010, 04:32 AM | #5 | 
| Wizard            Posts: 4,553 Karma: 950151 Join Date: Nov 2008 Device: Sony PRS-950, iphone/ipad (Marvin/iBooks/QuickReader) | 
			
			As somebody mentioned it is not just a database issue.   The names of the files and folders on disk in the calibre library area that holds the ebooks themselves has to have names that match entries in the database exactly.  Any mismatch and the books will not be there as far as Calibre is concerned.
		 | 
|   |   | 
|  02-04-2010, 05:56 AM | #6 | 
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 Join Date: Jan 2010 Location: Notts, England Device: Kobo Libra 2 | 
			
			I have used SQL successfully to browse the calibre DB. Starson17 suggested using SQLiteSpy, and it works well for browsing. Modifying is a completely different proposition. Not only does one have the integrity issues raised by itimpi and theducks, but there are problems with triggers. Calibre uses SQLite triggers to handle several complex conditions; one is computing title_sort. Several of the triggers make reference to python functions in calibre, which means that SQL update queries outside of calibre will fail. For example, it is very difficult to modify a row in the book table because the triggers fail. My advice: browse the database to understand how calibre stores its information, but don't plan on doing any modifications outside of calibre. The probability of an update query not working or breaking some calibre integrity constraint is very high. | 
|   |   | 
|  02-04-2010, 11:33 AM | #7 | |
| Wizard            Posts: 4,004 Karma: 177841 Join Date: Dec 2009 Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T | Quote: 
 The triggers for each table can be seen by selecting the trigger (at the left), right click and choose the "Show CREATE" option. Then you can save that CREATE as an SQL. To remove it, choose DROP instead of Show CREATE. After dropping the triggers, normal SQL commands will work. When done making database changes, you would need to add the dropped trigger(s) back by running the saved SQL CREATE for each trigger. Changes to author or title will break your database without corresponding changes in the file structure. Changes in any table will need to replicate the functions in the triggers, and changes in the book table are particularly tricky (note the uuid related trigger). If you try this, you are playing with fire. If you break it, you get to keep both halves (or even more pieces), so make lots of backups and test very, very, carefully. Running the database integrity before and after would also be advisable. | |
|   |   | 
|  02-04-2010, 11:55 AM | #8 | 
| creator of calibre            Posts: 45,604 Karma: 28548974 Join Date: Oct 2006 Location: Mumbai, India Device: Various | 
			
			calibre provides a full programmatic interface to the database via the calibre-debug command Code: calibre-debug -c "from calibrelibrary.database2 import LibraryDatabase2; db = LibraryDatabase2('/path/to/library/folder'); db.execute('some sql statement');"calibre-debug -e path_to_script.py to execute long scripts | 
|   |   | 
|  02-04-2010, 01:45 PM | #9 | |
| Wizard            Posts: 4,004 Karma: 177841 Join Date: Dec 2009 Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T | Quote: 
 There are a lot of interrelated fields that include the author or title field, from the path to the books to various sort fields. IOW, would you need to separately fix the directory/filename in the library if you changed the title or author in the database? Would you need to update the path field if you changed the author, or could you leave the original path and not change the directory/filename in the library? This is mainly just curiosity, but the one feature that I've been tempted to deal with externally is merging different records for different formats of the same book into a single record. I see an open feature enhancement request for that, so perhaps it's going to be implemented. | |
|   |   | 
|  02-05-2010, 02:11 AM | #10 | 
| creator of calibre            Posts: 45,604 Karma: 28548974 Join Date: Oct 2006 Location: Mumbai, India Device: Various | 
			
			LibraryDatabse2 has a full interface you can use to do these kinds of tasks.
		 | 
|   |   | 
|  | 
| 
 | 
|  Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Troubleshooting Manually setting clock | Kumabjorn | Amazon Kindle | 7 | 08-09-2010 09:11 AM | 
| Firmware Update UNOFFICIAL How to Manually Update Your Kindle to 2.0.3 | sirbruce | Amazon Kindle | 34 | 07-04-2010 10:37 AM | 
| Manually add/delete ebooks to a database | sariel2413 | Calibre | 3 | 03-18-2010 04:45 PM | 
| Handling (deleting, editing) tags manually with Calibre | lakicsv | Calibre | 20 | 01-14-2010 05:09 AM | 
| Creating media.xml manually | pepak | Sony Reader | 5 | 11-28-2008 10:26 AM |