![]() |
#1 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
|
Can Excel SQL query get metadata out of calibredb?
This question needs some explaining.
Context: 1.0 Metadata going from Excel into calibre: 1.1 A couple weeks ago we discussed how to get author and title metadata out of Excel and into automatically created empty books in calibre. For each record in Excel Mac the formula to do that, when pasted into terminal, generated the empty book with title and author fields populated, then user could fill in the missing metadata using calibre metadata fetch. The formula that worked in Excel Mac is: CONCATENATE("calibredb add -e -a """&Table1[@Author]&""" -t """&Table1[@Title]&"""") 2.0 Metadata going from calibre into Excel: 2.1. Discussed last week, one method is using a macro to grab Calibre catalog.csv data to populate cells in a worksheet. The csv to macro worksheet method works ok. Question: 2.2. Is there another way using Excel SQL queries sent directly to calibredb to retrieve metadata back to Excel? All of a sudden I vaguely remembered some years ago doing queries from Excel to grab raw stock market data. And wondered if similar method might work using Excel-sent SQL queries to calibredb, bypassing the need for generating a catalog.csv. Does anyone have experience doing something like this? -------------------------------------------------- FYI here is relevant excerpt from Excel Help: To import data from a database, such as Microsoft SQL Server, you must have an ODBC driver that is compatible with Microsoft Query installed on your computer. Compatible ODBC drivers are available from third-party vendors. For more information, see ODBC drivers that are compatible with Excel for Mac. For more information about installing ODBC drivers, see Microsoft Query Help. 1. On the Data menu, point to Get External Data, and then click New Database Query. 2. Use Microsoft Query to connect to a data source and to create a query. When you have finished, click Return Data to import the data into Excel. For more information about connecting to a data source and using Microsoft Query, see Microsoft Query Help. 3. In the Returning External Data to Microsoft Excel dialog box, do any of the following: 4. To 5. Do this 6. Choose query definition, refresh control, and data layout options 7. Click Properties. 8. Change the settings for a parameter query 9. Click Parameters. 10. Return the external data to the active sheet 11. Click Existing sheet. On your sheet, click the cell where you want to place the upper-left corner of the external data range, and then click OK. 12. Return the external data to a new sheet 13. Click New sheet, and then click OK. Excel adds a new sheet to your workbook, and automatically pastes the external data range at the upper-left corner of the new sheet. 14. Create a PivotTable report by using the external data 15. Click PivotTable, and then click OK. Notes* * • Excel 2011 for Mac cannot import data from OLE DB or OLAP data sources. • By default, Excel for Mac uses tables to import data. To turn off tables when importing data, in the Returning External Data to Microsoft Excel dialog box, click Properties, and then clear the Use Table check box. • If the external data source you want to access is not on your local computer, you might need to contact the administrator of the database for a password, user permission, or other connection information. END POST ![]() |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,130
Karma: 91256
Join Date: Feb 2008
Location: Germany
Device: Cybook Gen3
|
You could, I believe, hack something together in VBScript (if I remember correctly, that's what the Office suite's internal scripting language is called) that calls calibredb to obtain a list of the books in the database. See the documentation of calibredb, I believe you ought to be able to use the --list command.
|
![]() |
![]() |
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,343
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
You will need an OBDC data source for SQLite and the calibre DB. I have no idea of there is an ODBC driver for SQLite, but google will be your friend.
|
![]() |
![]() |
![]() |
#4 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 146
Karma: 2594
Join Date: May 2009
Device: Kindle PW,Sony 700, Sony 950 (Daily Edition),Nook Color,iPad
|
Just for point of info, I haven't looked at but google points to...
http://www.patthoyts.tk/sqlite3odbc.html |
![]() |
![]() |
![]() |
#5 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
|
Thanks for the responses.
@manichean: re calibredb list, the command line calibredb list options provide more flexibility than the gui catalog csv export options. With calibredb list I'd still need to send the output to a file then import it into excel. As you said, maybe a VB script could grab output of calibredb list automatically. I'm looking at the ODBC possibilites because that seems much more flexible if I can put it together and make it work. @chaley & Maggie-Me, google is indeed my friend. The link M-M provided was good, it pointed further. Apparently there is only one ODBC Driver developer for SQLite, Christian Werner (http://www.ch-werner.de/sqliteodbc/). He hosts versions for Windows, Linux, and OS X. I installed to OS X and found a vital configuration app was missing from the package. Sent email to him explaining problem, just got response. Said he didn't have a Mac so couldn't help, "Can you build the driver from the source code?" I don't know, I haven't built from source code in 20 years. I guess that's the next step. Putting together pieces of this SQL-query-to-calibredb-to-spreadsheet puzzle: 1. I have MS Excel with VB scripting and macro recording (if necessary). 2. I have MS Query which can front-end the outgoing SQL queries, and put returning data into a spreadsheet, which seems like a better way than using a zillion formulas in spreadsheet cells to grab the data. 3. I don't yet have a functioning ODBC driver (the intermediary between front-end query and back-end data handled by SQLite in calibre). 4. All the pieces will need configuration to work together, except maybe SQLite in calibre which I hope would just provide data sedately when asked politely. For now, Item 3 appears to be the major piece of the puzzle that needs work. |
![]() |
![]() |
![]() |
#6 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,130
Karma: 91256
Join Date: Feb 2008
Location: Germany
Device: Cybook Gen3
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
#7 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
|
Manichean, the VB script method is probably what I'll end up doing since I have a feeling there will be problems with the ODBC method which I don't know much about either since I haven't used it in 10 years and my SQL is rusty, dim and cobwebby. Right now those are the paths that look promising.
And why (many of you may wonder) am I going through all this? Because calibre won't let me print or export to file it's pretty, formatted, gui metadata display. |
![]() |
![]() |
![]() |
#8 |
US Navy, Retired
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,890
Karma: 13806776
Join Date: Feb 2009
Location: North Carolina
Device: Icarus Illumina XL HD, Kindle PaperWhite SE 11th Gen
|
|
![]() |
![]() |
![]() |
#9 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
|
Quote:
(The original catalog.csv file has unformatted data with the columns in alpha order. So the spreadsheet is set to switch columns around.) Last edited by unboggling; 01-18-2011 at 07:23 AM. Reason: added comment re csv catalog being unformatted. |
|
![]() |
![]() |
![]() |
#10 | |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 146
Karma: 2594
Join Date: May 2009
Device: Kindle PW,Sony 700, Sony 950 (Daily Edition),Nook Color,iPad
|
Quote:
If you get that far let me know and I may be able to help more. |
|
![]() |
![]() |
![]() |
#11 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
|
Quote:
|
|
![]() |
![]() |
![]() |
#12 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
|
|
![]() |
![]() |
![]() |
#13 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,553
Karma: 950151
Join Date: Nov 2008
Device: Sony PRS-950, iphone/ipad (Marvin/iBooks/QuickReader)
|
if the output of the calibredb command has the information you want, then I would have thought it was much easier to load the csv file into the spreadsheet and manipulate it from there? A bit of VBA (rather than a recorded macro) could trivially re-arrange columns, apply formatting etc. That would avoid the need to construct complex ODBC queries (as well as the problem of getting the ODBC driver to work in the first place).
|
![]() |
![]() |
![]() |
#14 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
|
Quote:
|
|
![]() |
![]() |
![]() |
#15 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,065
Karma: 858115
Join Date: Jan 2011
Device: Kobo Clara, Kindle Paperwhite 10
|
Here is link to the thread asking for help with the build:
https://www.mobileread.com/forums/sho...d.php?t=117188 |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Defining Metadata with "calibredb add" command line function. | macr0t0r | Calibre | 3 | 03-01-2012 07:36 PM |
metadata query | turbotoes | Calibre | 2 | 12-27-2010 06:19 AM |
Bash Script/SQL Query for ISBN in filename? | zenrhino | Calibre | 1 | 09-26-2010 08:55 AM |
Editing the date in metadata query | Cyclops | Calibre | 11 | 09-22-2010 11:58 AM |
SQL Queries | iain_benson | Calibre | 9 | 06-04-2009 06:08 PM |