I am working on a Class for DataBase functions. I have been stuck on this for over a week now. Erel says there is no macro substitution in B4A and so what would be pretty easy has now made my brain(what little I have):BangHead: explode. My goal is to write a filtering system for the stored data in the file. The programmer should be able to set the condition. They call another function that breaks their string into the Filters Type array like:
NOTE: I am looking for a way to do this with B4A code only. Hoping to not use libraries, etc.
Now any time the database is searched, the search calls the TestFilter() function below to see if it passes the filter condition. I would be grateful for any input on this.
NOTE: I am looking for a way to do this with B4A code only. Hoping to not use libraries, etc.
B4X:
db.SetFilters("name = jimmy AND zip_code # 37782 AND webpage @ facebook")
Now any time the database is searched, the search calls the TestFilter() function below to see if it passes the filter condition. I would be grateful for any input on this.
B4X:
Private Sub TestFilter(Felement As Int) As Boolean
If Empty(Filters(Felement).FieldName) Then Return True
If Filters(Felement).Comparator = "=" Then
If GetField(Filters(Felement).FieldName) = Filters(Felement).FilterValue Then
Return True
End If
End If
If Filters(Felement).Comparator = "<" Then
If GetField(Filters(Felement).FieldName) < Filters(Felement).FilterValue Then
Return True
End If
End If
If Filters(Felement).Comparator = ">" Then
If GetField(Filters(Felement).FieldName) > Filters(Felement).FilterValue Then
Return True
End If
End If
If Filters(Felement).Comparator = "#" Then
If GetField(Filters(Felement).FieldName) <> Filters(Felement).FilterValue Then
Return True
End If
End If
If Filters(Felement).Comparator = "@" Then
If At(GetField(Filters(Felement).FieldName), Filters(Felement).FilterValue) > -1 Then
Return True
End If
End If
Return False
End Sub
Last edited: