internal override object Eval(DataRow row, DataRowVersion version)
{
object vRight;
object vLeft = _left.Eval(row, version);
string substring;
if ((vLeft == DBNull.Value) || (_left.IsSqlColumn && DataStorage.IsObjectSqlNull(vLeft)))
return DBNull.Value;
if (_pattern == null)
{
vRight = _right.Eval(row, version);
if (!(vRight is string) && !(vRight is SqlString))
{
SetTypeMismatchError(_op, vLeft.GetType(), vRight.GetType());
}
if (vRight == DBNull.Value || DataStorage.IsObjectSqlNull(vRight))
return DBNull.Value;
string rightStr = (string)SqlConvert.ChangeType2(vRight, StorageType.String, typeof(string), FormatProvider);
// need to convert like pattern to a string
// Parce the original pattern, and get the constant part of it..
substring = AnalyzePattern(rightStr);
if (_right.IsConstant())
_pattern = substring;
}
else
{
substring = _pattern;
}
if (!(vLeft is string) && !(vLeft is SqlString))
{
SetTypeMismatchError(_op, vLeft.GetType(), typeof(string));
}
// WhiteSpace Chars Include : 0x9, 0xA, 0xB, 0xC, 0xD, 0x20, 0xA0, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x3000, and 0xFEFF.
char[] trimChars = new char[2] { (char)0x20, (char)0x3000 };
string tempStr;
if (vLeft is SqlString)
tempStr = ((SqlString)vLeft).Value;
else
tempStr = (string)vLeft;
string s1 = (tempStr).TrimEnd(trimChars);
switch (_kind)
{
case match_all:
return true;
case match_exact:
return (0 == table.Compare(s1, substring));
case match_middle:
return (0 <= table.IndexOf(s1, substring));
case match_left:
return (0 == table.IndexOf(s1, substring));
case match_right:
string s2 = substring.TrimEnd(trimChars);
return table.IsSuffix(s1, s2);
default:
Debug.Assert(false, "Unexpected LIKE kind");
return DBNull.Value;
}
}