User Tools

Site Tools


vba:classes:yfilter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
vba:classes:yfilter [22.12.2015 11:29:24]
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 16: Line 16:
  
 ===== Definitionen ===== ===== Definitionen =====
 +> Für die Ausgabe der Resultate verwendete ich die Funktion [[:​vba:​functions:​print_r:​|print_r() bzw. d()]].
 ==== Creatoren ==== ==== Creatoren ====
 Es gibt verschiedene Möglichkeiten ein DateTime zu initialisieren Es gibt verschiedene Möglichkeiten ein DateTime zu initialisieren
Line 21: Line 22:
 | [[#​instance]] | %%YFilter%% | Erstellt eine neue Instance ​ | | [[#​instance]] | %%YFilter%% | Erstellt eine neue Instance ​ |
 | [[#​construct]] | %%YFilter%% | Initialisiert ein bestehendes Objekt neu | | [[#​construct]] | %%YFilter%% | Initialisiert ein bestehendes Objekt neu |
-| [[#​createAnd]] | %%YFilter%% | Initialisiert ​ein bestehendes Objekt neu +| [[#​createAnd]] | %%YFilter%% | Erstellt ​ein AND-Filter ​
-| [[#​createOr]] | %%YFilter%% | Initialisiert ​ein bestehendes Objekt neu |+| [[#​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 ===== ===== Creatoren =====
  
 ==== instance ==== ==== instance ====
-<​code>​Set myFiler = YFilter.instance(feldName, [values [,filterType ​[,valueType]]]) +<​code>​Set myFiler = YFilter.instance(filterName, [values [,FilterType ​[,ValueType [,​FilterParameters]]]]) 
-Set myFiler = YFilter(feldName, [values [,filterType ​[,valueType]]])</​code>​ +Set myFiler = YFilter(filterName, [values [,FilterType ​[,ValueType [,​FilterParameters]]]])</​code>​ 
-<code vb> +<code vb>'/** 
-' * @param ​ String ​     Feldname/​FilterString +' * erstellt ein Filter und gibt den Filterstring zurück 
-' * @param ​ Variant ​    ​Ein Wert oder ein Array mit Werten +' * @param ​ String ​         Feldname 
-' * @param  ​eFilterType ​Type des Filters. eftNot lässt sich mit den restlichen kombinieren +' * @param ​ Variant ​        ​Ein Wert oder ein Array mit Werten 
-' * @param  ​eValueType  ​Type des Vergleichsvalue +' * @param  ​eFilterTypes ​   ​Type des Filters. eftNot lässt sich mit den restlichen kombinieren 
-' * @return ​YFilter+' * @param  ​eValueTypes ​    Type des Vergleichsvalue 
 +' * @param ​ eFilterParams ​  ​Diverse weitere Einstellungen 
 +' * @return ​String
 ' */ ' */
-Public Static ​Property Get instance( _ +Public Static ​Function ​instance( _ 
-    Optional ​ByVal iFieldName ​As Variant = Empty, _ +    Optional ​ByRef iItems1 ​As Variant = Empty, _ 
-    Optional ByRef iValues ​As Variant = Null, _ +    Optional ByRef iItems2 ​As Variant = Null, _ 
-    Optional ByVal iFilterType As eFilterType = eftAutomatic, _ +    Optional ByVal iFilterType As eFilterTypes, _ 
-    Optional ByVal iValueType As eValueType = evtAutomatic ​+    Optional ByVal iValueType As eValueTypes,​ _ 
-) As YFilter</​code>​+    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 == == Beispiel ==
-<code vb></​code>​+<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 ==== ==== construct ====
-<​code>​Set myFiler = new YFilter: myFilter.construct ​feldName, ​[values [,filterType ​[,valueType]]]</​code>​ +<​code>​Set myFiler = new YFilter: myFilter.construct [values [,FilterType ​[,ValueType [,​FilterParameters]]]]</​code>​ 
-<code vb> +<code vb>'/** 
-' * @param ​ String ​     Feldname/​FilterString+' * Initialisiert ein Filterobjekt 
 +' * @param ​ String ​     Feldname
 ' * @param ​ Variant ​    Ein Wert oder ein Array mit Werten ' * @param ​ Variant ​    Ein Wert oder ein Array mit Werten
-' * @param  ​eFilterType ​Type des Filters. eftNot lässt sich mit den restlichen kombinieren +' * @param  ​eFilterTypes ​Type des Filters. eftNot lässt sich mit den restlichen kombinieren 
-' * @param  ​eValueType ​ Type des Vergleichsvalue+' * @param  ​eValueTypes ​ Type des Vergleichsvalue 
 +' * @param ​ eFilterParams ​  ​Diverse weitere Einstellungen
 ' * @return YFilter ' * @return YFilter
 ' */ ' */
 Public Function construct( _ Public Function construct( _
-    Optional ​ByVal iFieldName ​As Variant = Empty, _ +    Optional ​ByRef iItems1 ​As Variant = Empty, _ 
-    Optional ByRef iValues ​As Variant = Null, _ +    Optional ByRef iItems2 ​As Variant = Null, _ 
-    Optional ByVal iFilterType As eFilterType = eftAutomatic, _ +    Optional ByVal iFilterType As eFilterTypes, _ 
-    Optional ByVal iValueType As eValueType = evtAutomatic ​_+    Optional ByVal iValueType As eValueTypes,​ _ 
 +    Optional ByVal iFilterParams As eFilterParams ​_
 ) As YFilter</​code>​ ) As YFilter</​code>​
  
 == Beispiel == == Beispiel ==
-<code vb></​code>​+<code vb>Dim myFilter As YFilter 
 +myFilter.construct "​id",​ 13</​code>​
  
 ==== createAnd ==== ==== createAnd ====
Line 75: Line 197:
  
 == Beispiel == == Beispiel ==
-<code vb></​code>​+<code vb>? YFilter.createAnd(YFilter("​id",​ 13), YFilter("​flag",​ true)).filterText 
 +([id] = 13) AND ([flag] = True) 
 +</​code>​
  
 ==== createOr ==== ==== createOr ====
Line 94: Line 218:
  
 == Beispiel == == Beispiel ==
-<code vb></​code>​+<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>
vba/classes/yfilter.1450780164.txt.gz · Last modified: 22.12.2015 11:29:24 by yaslaw