This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
vba:classes:yfilter [21.12.2015 11:16:05] yaslaw |
vba:classes:yfilter [15.01.2016 11:46:56] (current) yaslaw |
||
---|---|---|---|
Line 1: | Line 1: | ||
<const> | <const> | ||
- | version=1.2.0 | + | version=2.1.0 |
- | vdate=09.12.2015 | + | vdate=15.01.2016 |
fname=yfilter.cls | fname=yfilter.cls | ||
ns=%NAMESPACE% | ns=%NAMESPACE% | ||
Line 14: | Line 14: | ||
{{%%fname%%|Download %%fname%% (V-%%version%%)}}</WRAP> | {{%%fname%%|Download %%fname%% (V-%%version%%)}}</WRAP> | ||
+ | |||
+ | ===== Definitionen ===== | ||
+ | > Für die Ausgabe der Resultate verwendete ich die Funktion [[:vba:functions:print_r:|print_r() bzw. d()]]. | ||
+ | ==== Creatoren ==== | ||
+ | Es gibt verschiedene Möglichkeiten ein DateTime zu initialisieren | ||
+ | ^ Methode ^ Rückgabetyp ^ Beschreibung ^ | ||
+ | | [[#instance]] | %%YFilter%% | Erstellt eine neue Instance | | ||
+ | | [[#construct]] | %%YFilter%% | Initialisiert ein bestehendes Objekt neu | | ||
+ | | [[#createAnd]] | %%YFilter%% | Erstellt ein AND-Filter | | ||
+ | | [[#createOr]] | %%YFilter%% | Erstellt ein OR-Filter | | ||
+ | |||
+ | |||
+ | ===== Anwenden der Parameter ===== | ||
+ | Ob instance() oder construct(). Die Parameterreihenfolge und das Verhalten der Parameter sind gleich. Ich nehme darum nur [[#instance]] und gebe das Resultat direkt mit [[#filterText]] aus. | ||
+ | |||
+ | ==== Automatische Filter ==== | ||
+ | Einfache Aufrufe. Tabellen-/Feldnamen werden automatisch erkannt und auch der ValueTyp | ||
+ | <code vb>? YFilter("id", 13).filterText | ||
+ | [id] = 13 | ||
+ | |||
+ | ? YFilter("mytable.id", 13).filterText | ||
+ | [mytable].[id] = 13 | ||
+ | |||
+ | ? YFilter("name", "Yaslaw").filterText | ||
+ | [name] = "Yaslaw" | ||
+ | |||
+ | ? YFilter("name", "Yaslaw*").filterText | ||
+ | [name] LIKE "Yaslaw*" | ||
+ | </code> | ||
+ | |||
+ | Für ein Between oder ein IN(), können einfach die Values als Array übergeben werden | ||
+ | <code vb>? YFilter("id", array(13, 42)).filterText | ||
+ | ([id] BETWEEN 13 AND 42) | ||
+ | |||
+ | ? YFilter("id", array(13, 42, 72)).filterText | ||
+ | [id] IN (13, 42, 72)</code> | ||
+ | |||
+ | ==== Direkte Filter ==== | ||
+ | Manchmal macht es Sinn, ein Filter direkt einzugeben. Zm Beispiel als Untefilter bei [[#createAnd]] | ||
+ | <code vb>? YFilter("id = 123").filterText | ||
+ | id = 123 | ||
+ | |||
+ | 'Wenn der erste Parameter als Feldnamen erkannt wird, dann wird auf NULL geprüft | ||
+ | ? YFilter("id").filterText | ||
+ | [id] IS NULL</code> | ||
+ | |||
+ | ==== Filter mittels Paramter konkretisieren ==== | ||
+ | Mit 3 Parametern kann man dem Filter auch auf die Sprünge helfen, damit klar ist, was man haben will. | ||
+ | <code vb>'Ohne FilterType & ValueType | ||
+ | ? YFilter("id", "123").filterText | ||
+ | [id] = 123 | ||
+ | |||
+ | 'ValueType als String | ||
+ | ? YFilter("id", "123",, evtString).filterText | ||
+ | [id] = "123" | ||
+ | |||
+ | 'Mit FilterType Less or Equal | ||
+ | ? YFilter("id", "123", eftLe).filterText | ||
+ | [id] <= 123 | ||
+ | |||
+ | 'Prüfung auf NULL erzwingen | ||
+ | ? YFilter("id", "123",eftNull).filterText | ||
+ | [id] IS NULL | ||
+ | |||
+ | 'Und auf Not Null | ||
+ | ? YFilter("id", "123",eftNull + eftNot).filterText | ||
+ | [id] NOT IS NULL | ||
+ | |||
+ | 'ein einfacher NOT-Filter | ||
+ | ? YFilter("id", 123, eftNot).filterText | ||
+ | NOT [id] = 123</code> | ||
+ | |||
+ | Mit mehreren Werten. | ||
+ | <code vb>'Ohne Typedefinitionen | ||
+ | ? YFilter("id", array(13, 42)).filterText | ||
+ | ([id] BETWEEN 13 AND 42) | ||
+ | |||
+ | 'Als IN() anstelle von BETWEEN | ||
+ | ? YFilter("id", array(13, 42), eftIn).filterText | ||
+ | [id] IN (13, 42) | ||
+ | |||
+ | 'und mit NOT kombiniert als String-Vergleich | ||
+ | ? YFilter("id", array(13, 42), eftNot + eftIn, evtString).filterText | ||
+ | [id] NOT IN ("13", "42")</code> | ||
+ | |||
+ | Einige Beispiele zu weiteren Parameter | ||
+ | <code vb> | ||
+ | 'Logik umdrehen. Der erste Wert ist ein Value, die Zweiten sind Felder | ||
+ | ?YFilter("abc", array("Code1", "Code2"),,,efpFirstIsValue+efpSecoundIsName).filterText | ||
+ | ("abc" BETWEEN [Code1] AND [Code2]) | ||
+ | |||
+ | 'Wenn das erste Feld klar kein Feldname ist, dnn kann efpFirstIsValue auch weggelassen werden | ||
+ | ?YFilter(#05-15-2016#, array("from_date", "to_date"),,,efpSecoundIsName).filterText | ||
+ | (#05-15-2016 00:00:00# BETWEEN [from_date] AND [to_date]) | ||
+ | |||
+ | 'Ein Boolean-Text ohne Parameter efpParseBooleanString | ||
+ | ?YFilter("t2.flag1", "True").filterText | ||
+ | [t2].[flag1] = "True" | ||
+ | |||
+ | 'und mit Parameter efpParseBooleanString | ||
+ | ?YFilter("t2.flag1", "True",,,efpParseBooleanString).filterText | ||
+ | [t2].[flag1] = True | ||
+ | </code> | ||
+ | ===== Creatoren ===== | ||
+ | |||
+ | ==== instance ==== | ||
+ | <code>Set myFiler = YFilter.instance(filterName, [values [,FilterType [,ValueType [,FilterParameters]]]]) | ||
+ | Set myFiler = YFilter(filterName, [values [,FilterType [,ValueType [,FilterParameters]]]])</code> | ||
+ | <code vb>'/** | ||
+ | ' * erstellt ein Filter und gibt den Filterstring zurück | ||
+ | ' * @param String Feldname | ||
+ | ' * @param Variant Ein Wert oder ein Array mit Werten | ||
+ | ' * @param eFilterTypes Type des Filters. eftNot lässt sich mit den restlichen kombinieren | ||
+ | ' * @param eValueTypes Type des Vergleichsvalue | ||
+ | ' * @param eFilterParams Diverse weitere Einstellungen | ||
+ | ' * @return String | ||
+ | ' */ | ||
+ | Public Static Function instance( _ | ||
+ | Optional ByRef iItems1 As Variant = Empty, _ | ||
+ | Optional ByRef iItems2 As Variant = Null, _ | ||
+ | Optional ByVal iFilterType As eFilterTypes, _ | ||
+ | Optional ByVal iValueType As eValueTypes, _ | ||
+ | Optional ByVal iFilterParams As eFilterParams _ | ||
+ | ) As YFilter | ||
+ | 'Attribute instance.VB_UserMemId = 0 | ||
+ | Set instance = New YFilter | ||
+ | instance.construct iItems1, iItems2, iFilterType, iValueType, iFilterParams | ||
+ | End Function | ||
+ | </code> | ||
+ | |||
+ | == Beispiel == | ||
+ | <code vb>print_r YFilter("id", 13) | ||
+ | <Class Module::YFilter> ( | ||
+ | [filterText] => <String> '[id] = 13' | ||
+ | [fieldName] => <String> '[id]' | ||
+ | [valueType] => <Long> 19 | ||
+ | [values] => <Variant()> ( | ||
+ | [0] => <Integer> 13 | ||
+ | ) | ||
+ | [filterType] => <Long> 128 | ||
+ | [isNotFilter] => <Boolean> False | ||
+ | ) | ||
+ | |||
+ | ? YFilter("id", array(13, 42)).filterText | ||
+ | ([id] BETWEEN 13 AND 42) | ||
+ | |||
+ | YFilter("id", array(13, 42, 72)).filterText | ||
+ | [id] IN (13, 42, 72) | ||
+ | </code> | ||
+ | |||
+ | ==== construct ==== | ||
+ | <code>Set myFiler = new YFilter: myFilter.construct [values [,FilterType [,ValueType [,FilterParameters]]]]</code> | ||
+ | <code vb>'/** | ||
+ | ' * Initialisiert ein Filterobjekt | ||
+ | ' * @param String Feldname | ||
+ | ' * @param Variant Ein Wert oder ein Array mit Werten | ||
+ | ' * @param eFilterTypes Type des Filters. eftNot lässt sich mit den restlichen kombinieren | ||
+ | ' * @param eValueTypes Type des Vergleichsvalue | ||
+ | ' * @param eFilterParams Diverse weitere Einstellungen | ||
+ | ' * @return YFilter | ||
+ | ' */ | ||
+ | Public Function construct( _ | ||
+ | Optional ByRef iItems1 As Variant = Empty, _ | ||
+ | Optional ByRef iItems2 As Variant = Null, _ | ||
+ | Optional ByVal iFilterType As eFilterTypes, _ | ||
+ | Optional ByVal iValueType As eValueTypes, _ | ||
+ | Optional ByVal iFilterParams As eFilterParams _ | ||
+ | ) As YFilter</code> | ||
+ | |||
+ | == Beispiel == | ||
+ | <code vb>Dim myFilter As YFilter | ||
+ | myFilter.construct "id", 13</code> | ||
+ | |||
+ | ==== createAnd ==== | ||
+ | <code>Set myFiler = YFilter.createAnd([filter [,filter [...]])</code> | ||
+ | <code vb>'/** | ||
+ | ' * @param Array<Filter> Filter die mit AND verknüpft werden | ||
+ | ' * @return Filter | ||
+ | ' */ | ||
+ | Public Static Function createAnd(ParamArray iFilters() As Variant) As YFilter | ||
+ | </code> | ||
+ | |||
+ | == Beispiel == | ||
+ | <code vb>? YFilter.createAnd(YFilter("id", 13), YFilter("flag", true)).filterText | ||
+ | ([id] = 13) AND ([flag] = True) | ||
+ | </code> | ||
+ | |||
+ | ==== createOr ==== | ||
+ | Erstellt ein OR-Filter | ||
+ | <code>Set myFiler = YFilter.createOr([filter [,filter [...]])</code> | ||
+ | <code vb>'/** | ||
+ | ' * @param Array<Filter> Filter die mit OR verknüpft werden | ||
+ | ' * @return Filter | ||
+ | ' */ | ||
+ | Public Static Function createOr(ParamArray iFilters() As Variant) As YFilter | ||
+ | pSubIdx = -1 | ||
+ | Set createOr = New YFilter | ||
+ | createOr.filterType = [_OR] | ||
+ | Dim idx As Integer: For idx = 0 To UBound(iFilters) | ||
+ | createOr.addFilter iFilters(idx) | ||
+ | Next idx | ||
+ | End Function</code> | ||
+ | |||
+ | == Beispiel == | ||
+ | <code vb>? YFilter.createOr(yfilter.createAnd(YFilter("id", 13), YFilter("flag", true)), "master = 0").filterText | ||
+ | (([id] = 13) AND ([flag] = True)) OR (master = 0)</code> | ||
+ | |||
+ | ===== Weitere Beispiele ===== | ||
+ | Siehe auch [[vba:flexiblerfilter]]. | ||
+ | |||
===== Code ===== | ===== Code ===== | ||
<source '%%fpath%%/%%fname%%' vb> | <source '%%fpath%%/%%fname%%' vb> |