/// <summary> /// 获取 String 类型的 SQL 片断 /// </summary> /// <param name="value">值</param> /// <param name="dbType">数据类型</param> /// <param name="size">长度</param> /// <returns></returns> protected override string GetSqlValueOfString(object value, object dbType, int?size = null) { bool unicode = SQLiteUtils.IsUnicode(dbType); string result = this.EscapeQuote(value.ToString(), unicode, true); return(result); }
/// <summary> /// 访问 Contains 方法 /// </summary> /// <param name="m">方法表达式</param> protected override Expression VisitStringContains(MethodCallExpression m) { _visitor.Visit(m.Object); if (this.NotOperands != null && this.NotOperands.Contains(m)) { _builder.Append(" NOT"); } _builder.Append(" LIKE "); if (m.Arguments[0].CanEvaluate()) { ColumnAttribute column = null; bool isUnicode = SQLiteUtils.IsUnicode(_visitedMark.Current, out column); string value = _constor.GetSqlValue(m.Arguments[0].Evaluate().Value, _builder.TranslateContext, column); if (!_builder.Parameterized && value != null) { value = value.TrimStart('N').Trim('\''); } if (_builder.Parameterized) { _builder.Append("'%' || "); _builder.Append(value); _builder.Append(" || '%'"); } else { if (isUnicode) { _builder.Append('N'); } _builder.Append("'%"); _builder.Append(value); _builder.Append("%'"); } } else { _builder.Append("('%' || "); _visitor.Visit(m.Arguments[0]); _builder.Append(" || '%')"); } return(m); }
/// <summary> /// 检查字段或属性成员声明的 DbType 是否为 Unicode 数据类型 /// </summary> /// <param name="m">将要检查的字段或属性成员</param> /// <param name="column">字段或属性成员显示声明的列特性</param> /// <returns></returns> public static bool IsUnicode(MemberVisitedStack.VisitedMember m, out ColumnAttribute column) { column = m != null?TypeUtils.GetColumnAttribute(m.Member, m.ReflectedType) : null; return(SQLiteUtils.IsUnicode(column == null ? null : column.DbType)); }
/// <summary> /// 检查字段或属性成员声明的 DbType 是否为 Unicode 数据类型 /// </summary> /// <param name="m">将要检查的字段或属性成员</param> /// <returns></returns> public static bool IsUnicode(MemberVisitedStack.VisitedMember m) { ColumnAttribute column = null; return(SQLiteUtils.IsUnicode(m, out column)); }