Yes, you are on track. The SQL I am using for this is basically:
Code:
SELECT c.ContentId, c.Title, c.Attribution, sc.ShelfName
FROM content c LEFT OUTER JOIN ShelfContent sc
ON c.ContentId = sc.ContentId AND c.ContentType = 6 AND sc._IsDeleted = 'false'
JOIN Shelf s ON s.Name = sc.ShelfName AND s._IsDeleted = 'false'
ORDER BY c.ContentId, sc.ShelfName
That will list each book with the shelves they are on. The "c.ContentType = 6" are the rows that describe each the book. And the "_IsDeleted" columns are a complication to the shelves that Kobo uses for their syncing.
As to adding the function, getting the shelves from the device has been asked for before. But, usually as part of the sync. I have just posted a beta version in
the plugins thread. I think it will do what you want. Tell me how it goes and if you have any suggestions to improve it.