SqlFilterBuilder GetPhrase Method (String,  String )CleanCode C# Libraries v1.2.03 API

Namespace: CleanCode.Data
Assembly: CleanCode (in CleanCode.dll) Version: (1.2.03)

public string GetPhrase(
	string fieldName,
	params string[] value


Type: OnlineSystem String
The database field name.
Type:  OnlineSystem String 
A singleton or a list of values.

Return Value

Equality, matching, or inclusion SQL predicate.

If a single value is provided, an equality clause or a matching clause is generated, as appropriate. If a list of values is provided, a range inclusion clause is generated, i.e. something like "xxx IN (a,b,c)".

It is often easier to generate a value list in your application with a fixed number of items, some of which you want to include and some you do not. Simply use null for the items to be ignored, as nulls will be skipped. Example:

GetPhrase("Type", (condition1? "abc" : null), (condition2? "def" : null))
Depending on condition1 and condition2 the resulting phrase could be any of these:
[Type] IN ('abc', 'def')
<empty string>

As shown, empty parts of the phrase are removed as needed. Additionally, the entire phrase is voided (i.e. an empty string) if there is no value at all. This has great utility when used with GetConjunction( String ) or GetAlternation( String ). The former method shows a specific example of how it may save unnecessary coding.

Note that field names are enclosed in bracket notation ([]) for safety; otherwise, a field name like "Part #" would cause an SQL syntax error. (An alternate form of @"Part #" is supposed to work also, but this implementation uses the more common bracket notation.)


MessageBox.Show(builder.GetPhrase("PartNum", "52%"));
  builder.GetPhrase("X", "a", "b"),
  builder.GetPhrase("zip", "99000")
See Also