Page 1 of 1

SDB.Database.ActiveFilterQuery function is inconsistent

Posted: Sun Feb 03, 2008 11:12 am
by bob61
I encountered a problem when using Magic Nodes. I'm using the latest release of MM3 (3.0.2.1134) on Windows XP. As part of the discussion with the script author (ZvezdanD) it appears to be a bug within MM3. ZvezdanD was very helpful and modified his script to provide some additional debug information that I've included below.

First, I set the Filters to Album View and then select this Magic Node

Code: Select all

Songs with lyrics|SQL filter:Length(Songs.Lyrics) > 0\<Artist>)

This is the resulting messages (first is from ZvezdanD's debug from his modified script):
Image
Image

For comparison, I then set the Filter to Available Tracks and everything then works. This is the message displayed:
Image


To further test I set Filters back to Album View and selected this MN

Code: Select all

Rating, Genre\<rating|statistic:count(all)>\<genre|statistic:count(all)>
This is the resulting messages (again first is debug info from ZvezdanD modified script):
Image
Image


Based on this information it appears the SDB.Database.ActiveFilterQuery function is inconsistent. For "Album View" filter it returns full SQL query:

Code: Select all

SELECT Songs.Id FROM Songs
For Available Tracks, Music and Audiobooks filters, it returns WHERE part of query. For example, for Available tracks, it is:

Code: Select all

(Songs.IdMedia in (31,28,29) OR Songs.CacheStatus=1)

Re: SDB.Database.ActiveFilterQuery function is inconsistent

Posted: Sun Feb 03, 2008 6:05 pm
by PetrCBR
Hi.

And what is "Album View" filter ? How looks rule you're used for this filter ?

Posted: Sun Feb 03, 2008 10:58 pm
by bob61
I don't even recall creating this Filter, I thought it was just part of the standard filter. However in taking a look at it it really doesn't have any filtering in it that I see:

Image

Posted: Mon Feb 04, 2008 4:30 am
by Bex
It seems that if you create a filter with no search criteria then MM returns:

Code: Select all

SELECT Songs.Id FROM Songs
Which obviously make some problem when using SDB.Database:ActiveFilterQuery in scripts.

Posted: Mon Feb 04, 2008 8:09 am
by PetrCBR
This issue will be fixed in next release. For "empty" filters will return "(1)" string.

Posted: Mon Feb 04, 2008 8:53 am
by Bex
Do you mean an empty string when you say "(1)" string?

Posted: Mon Feb 04, 2008 9:01 am
by ZvezdanD
PetrCBR wrote:This issue will be fixed in next release. For "empty" filters will return "(1)" string.
Please, could I get an answer for: http://www.mediamonkey.com/forum/viewtopic.php?t=25697?

I need to know a name of the active filter to display it after Magic Nodes caption between parenthesis in same way as Library display it. I tried to get a caption of Library node and parse such information, but this caption is always "Library" even when it displays "Library (Available Tracks)". If you already have INI key for this, why don't you use it?

Posted: Mon Feb 04, 2008 9:05 am
by ZvezdanD
Bex wrote:Do you mean an empty string when you say "(1)" string?
Hmm, maybe it should return something, because there is not another way to detect if some filter is active. For instance, if I have a line:

Code: Select all

If Len(SDB.Database.ActiveFilterQuery) > 0 Then
Maybe "True" is more logical.

Posted: Mon Feb 04, 2008 9:25 am
by PetrCBR
It will return "(1)" string. As you said, there's no other way how to detect filter is active so even if filter rule will be empty, ActiveFilterQuery will return something ( and "(1)" can be used without problems in query).

Posted: Mon Feb 04, 2008 12:40 pm
by Bex
:-?
I get errors when I use "(1)" i a query...

I still think the function should return an empty string if no sql is supposed to be returned regardless if any filter is active or not. That's make more sense.

But I would lbe nice with some additional functions/methods here which would tell you if any filter is active and possibility to sql's of non active filter etc, That would really be helpful.

Posted: Mon Feb 04, 2008 2:13 pm
by PetrCBR
OK Bex.

For next release i'll add following :

- ActiveFilterQuery returns empty string if filter's rule is empty
- new ActiveFilterID property will return ID of active filter (-1 when not filtered)
- new GetFilterQuery(ID) function will return query for filter specified by ID

Posted: Mon Feb 04, 2008 2:33 pm
by Bex
Great, thanks a lot! :D

I'm sure it will be used a lot in various script.
I will implement it in all my scripts, where applicable, as soon as it gets released.

What about a:
GetFilterList as StringList (returns a list of all configured Filters)

Not really needed since one could query the database but...

Posted: Mon Feb 04, 2008 2:41 pm
by PetrCBR
List of filters can be very easily queried from database so i think it's not necessary.

Posted: Mon Feb 04, 2008 2:53 pm
by Bex
Yes, Ok. Thanks again!