Assembly: CleanCode (in CleanCode.dll) Version: 1.2.3.0 (1.2.03)
Parameters
- fieldName
- Type:
System String
The database field name.
- value
- Type:
System 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))
[Type]='abc' [Type]='def' [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%")); MessageBox.Show(builder.GetPhrase("PartNum","23","42","67","122")); MessageBox.Show(builder.GetAlternation( builder.GetPhrase("Type","5"), builder.GetPhrase("X", "a", "b"), builder.GetPhrase("zip", "99000") ));