With pms-mlx, I’ve been working on a media library to extend the functionalities of the ps3 media server for some time now and just recently discovered a major flow in my concept; it is not possible to filter if using more than one one-to-many property.
Before asking questions, I should explain how it works.
Here’s the DB structure for the relevant part of the code. h2 is being used.

Every video is a file and has 0-n of the attached properties.
Once some videos have been stored, it is possible to view and play them in folders showing only a subset of all entries, by setting conditions. Here’s an example:

To retrieve the wanted files, the query is being constructed like this
SELECT <all_properties>
FROM FILE, VIDEO
LEFT JOIN VIDEOAUDIO ON VIDEO.FILEID = VIDEOAUDIO.FILEID
LEFT JOIN SUBTITLES ON VIDEO.FILEID = SUBTITLES.FILEID
LEFT JOIN FILETAGS ON VIDEO.FILEID = FILETAGS.FILEID
LEFT JOIN FILEPLAYS ON VIDEO.FILEID = FILEPLAYS.FILEID
WHERE <whereClause>
ORDER BY <orderBy>
Only the where and order by parts are dynamic. The where clause is being created by replacing the condition names (c1, c2) by their corresponding SQL counterparts. For the above example this where clause will be generated:
WHERE VIDEO.FILEID = FILE.ID
AND ((VIDEO.NAME LIKE 'A%' OR VIDEO.NAME LIKE 'B%')
AND FILE.DATEINSERTEDDB > '2011-09-28 18:48:43')
When doing the query, many rows will be returned for each file. While iterating through the results, the ‘new’ data contained in the raw will be added to create the object.
When the filter contains a one-to-many condition, the query is being done in two steps. First, the IDs of all the videos are being retrieved and then the data loaded.
What I’ve been missing until now, is that if having e.g. two file tags and both should be met, nothing works anymore.
If setting the filter:

Resulting in this where clause:
WHERE VIDEO.FILEID = FILE.ID
AND ((VIDEO.FILEID = FILETAGS.FILEID
AND FILETAGS.KEY = 'Actor' AND FILETAGS.VALUE LIKE 'A%')
AND (VIDEO.FILEID = FILETAGS.FILEID
AND FILETAGS.KEY = 'Actor' AND FILETAGS.VALUE LIKE 'B%'))
which is never met, as a single row only contains one key and one value field.
Would it be possible to create a query where all the data for a single video would be contained on one row? Or substitute the generated SQL condition by something else?
I’m no db expert and would love to here from someone having a good idea 🙂
The code to generate the where clause is in the method formatFilter on line 445 of DBFileInfo.java. The loading of the data is being done on line 189 of DBVideoFileInfo.java if anybody is interested to see the code.
Your complex table relationships is a bit confusing for a simple example of the problem, but can you not just build a bunch of criteria up?
Surely that would only return files that have Brad, Angelina and Elvis in? (Probably not many).