You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

135 lines
5.1 KiB

namespace SqlSugar
{
public class MySqlExpressionContext : ExpressionContext, ILambdaExpressions
{
public SqlSugarClient Context { get; set; }
public MySqlExpressionContext()
{
base.DbMehtods = new MySqlMethod();
}
public override string SqlTranslationLeft { get { return "`"; } }
public override string SqlTranslationRight { get { return "`"; } }
}
public class MySqlMethod : DefaultDbMethod, IDbMethods
{
public override string DateValue(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
return string.Format(" {0}({1}) ", parameter2.MemberValue, parameter.MemberName);
}
public override string Contains(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
return string.Format(" ({0} like concat('%',{1},'%')) ", parameter.MemberName, parameter2.MemberName );
}
public override string StartsWith(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
return string.Format(" ({0} like concat({1},'%')) ", parameter.MemberName, parameter2.MemberName);
}
public override string EndsWith(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
return string.Format(" ({0} like concat('%',{1}))", parameter.MemberName,parameter2.MemberName);
}
public override string DateIsSameDay(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
return string.Format(" (TIMESTAMPDIFF(day,{0},{1})=0) ", parameter.MemberName, parameter2.MemberName); ;
}
public override string DateIsSameByType(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
var parameter3 = model.Args[2];
return string.Format(" (TIMESTAMPDIFF({2},{0},{1})=0) ", parameter.MemberName, parameter2.MemberName, parameter3.MemberValue);
}
public override string DateAddByType(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
var parameter3 = model.Args[2];
return string.Format(" (DATE_ADD({1} , INTERVAL {2} {0})) ", parameter3.MemberValue, parameter.MemberName, parameter2.MemberName);
}
public override string DateAddDay(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
return string.Format(" (DATE_ADD({1} INTERVAL {0} day)) ", parameter.MemberName, parameter2.MemberName);
}
public override string ToInt32(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS SIGNED)", parameter.MemberName);
}
public override string ToInt64(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS SIGNED)", parameter.MemberName);
}
public override string ToString(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS CHAR)", parameter.MemberName);
}
public override string ToGuid(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS CHAR)", parameter.MemberName);
}
public override string ToDouble(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS DECIMAL(18,4))", parameter.MemberName);
}
public override string ToBool(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS SIGNED)", parameter.MemberName);
}
public override string ToDecimal(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS DECIMAL(18,4))", parameter.MemberName);
}
public override string Length(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" LENGTH({0})", parameter.MemberName);
}
public override string MergeString(params string[] strings)
{
return " concat("+string.Join(",", strings).Replace("+", "") + ") ";
}
public override string IsNull(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter1 = model.Args[1];
return string.Format("IFNULL({0},{1})", parameter.MemberName, parameter1.MemberName);
}
public override string GetDate()
{
return "NOW()";
}
}
}