Browse Source

Update Sqlite

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
c9ac1962c1
  1. 160
      Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs
  2. BIN
      Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite
  3. 128
      Src/Asp.Net/SqliteTest/UnitTest/ExpressionTest/Method.cs

160
Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs

@ -54,6 +54,12 @@ namespace SqlSugar
}
public class SqliteMethod : DefaultDbMethod, IDbMethods
{
public override string Length(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format("LENGTH({0})", parameter.MemberName);
}
public override string Contains(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
@ -65,15 +71,165 @@ namespace SqlSugar
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
return string.Format(" ({0} like '%'||{1}) ", parameter.MemberName, parameter2.MemberName);
return string.Format(" ({0} like {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 {1}||'%') ", parameter.MemberName, parameter2.MemberName);
return string.Format(" ({0} like '%'||{1}) ", parameter.MemberName, parameter2.MemberName);
}
public override string ToInt32(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS INTEGER)", parameter.MemberName);
}
public override string ToInt64(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS INTEGER)", parameter.MemberName);
}
public override string ToString(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS TEXT)", parameter.MemberName);
}
public override string ToGuid(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CAST({0} AS TEXT)", 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 ToDate(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" DATETIME({0})", parameter.MemberName);
}
public override string DateAddDay(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
if (parameter2.MemberValue.ObjToInt() < 0)
{
return string.Format(" DATE(DATETIME({0}), '-{1} days')", parameter.MemberName, Math.Abs(parameter2.MemberValue.ObjToInt()));
}
else
{
return string.Format(" DATE(DATETIME({0}), '+{1} days')", parameter.MemberName, parameter2.MemberValue);
}
}
public override string DateAddByType(MethodCallExpressionModel model)
{
var parameter = model.Args[0].MemberName;
var parameter2 = model.Args[1].MemberValue;
var parameter3 = model.Args[2].MemberValue;
if (parameter2.ObjToInt() < 0)
{
return string.Format(" DATETIME(DATETIME({0}), '+{1} {2}s')", parameter, Math.Abs(parameter2.ObjToInt()), parameter3);
}
else
{
return string.Format(" DATETIME(DATETIME({0}), '+{1} {2}s')", parameter, parameter2, parameter3);
}
}
public override string DateValue(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var typeName = model.Args[1].MemberValue.ToString();
var parameter2 = typeName;
var type = (DateType)Enum.Parse(typeof(DateType), parameter2, false);
switch (type)
{
case DateType.Year:
parameter2 = "%Y";
break;
case DateType.Month:
parameter2 = "%m";
break;
case DateType.Day:
parameter2 = "%d";
break;
case DateType.Hour:
parameter2 = "%H";
break;
case DateType.Second:
parameter2 = "%S";
break;
case DateType.Minute:
parameter2 = "%M";
break;
case DateType.Millisecond:
default:
Check.ThrowNotSupportedException(typeName);
break;
}
return string.Format(" CAST(STRFTIME('{1}', DATETIME(DATETIME({0}), 'LOCALTIME')) AS INTEGER)", parameter.MemberName, parameter2);
}
public override string DateIsSameDay(MethodCallExpressionModel model)
{
var parameter = model.Args[0].MemberName;
var parameter2 = model.Args[1].MemberName;
int time = 1;
return string.Format(" Cast((JulianDay({0}) - JulianDay({1})) *{2} As INTEGER)", parameter, parameter2, time);
}
public override string DateIsSameByType(MethodCallExpressionModel model)
{
var parameter = model.Args[0].MemberName;
var parameter2 = model.Args[1].MemberName;
var parameter3 = model.Args[2].MemberValue;
var type = (DateType)Enum.Parse(typeof(DateType), parameter3.ObjToString(), false);
int time = 1;
switch (type)
{
case DateType.Year:
time = time * 1 / 365;
break;
case DateType.Month:
time = time * 1 / 30;
break;
case DateType.Day:
break;
case DateType.Hour:
time = time * 24;
break;
case DateType.Second:
time = time * 24 * 60 * 60;
break;
case DateType.Minute:
time = time * 24 * 60;
break;
case DateType.Millisecond:
time = time * 24 * 60 * 60 * 1000;
break;
}
return string.Format(" Cast((JulianDay({0}) - JulianDay({1})) *{2} As INTEGER)", parameter, parameter2, time);
}
}
}

BIN
Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite

Binary file not shown.

128
Src/Asp.Net/SqliteTest/UnitTest/ExpressionTest/Method.cs

@ -75,11 +75,11 @@ namespace OrmTest.UnitTest
private void ExtendToString()
{
Expression<Func<Student, bool>> exp = it => it.Id.ToString() == "a";
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(CAST(`Id` AS CHAR) = @Const0 )", new List<SugarParameter>() {
base.Check(value, pars, "(CAST(`Id` AS TEXT) = @Const0 )", new List<SugarParameter>() {
new SugarParameter("@Const0","a")
}, "ExtendToString error");
}
@ -87,11 +87,11 @@ namespace OrmTest.UnitTest
private void ConvetToString()
{
Expression<Func<Student, bool>> exp = it => Convert.ToString(it.Id) == "a";
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(CAST(`Id` AS CHAR) = @Const0 )", new List<SugarParameter>() {
base.Check(value, pars, "(CAST(`Id` AS TEXT) = @Const0 )", new List<SugarParameter>() {
new SugarParameter("@Const0","a")
}, "ConvetToString error");
}
@ -100,7 +100,7 @@ namespace OrmTest.UnitTest
private void Length()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.Length("aaaa") > 1;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -113,7 +113,7 @@ namespace OrmTest.UnitTest
{
var x2 = Guid.NewGuid();
Expression<Func<Student, bool>> exp = it => SqlFunc.Replace("aaaa", "a", "1") == "a";
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -126,7 +126,7 @@ namespace OrmTest.UnitTest
{
var x2 = Guid.NewGuid();
Expression<Func<Student, bool>> exp = it => SqlFunc.Substring("aaaa", 0, 2) == "a";
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -138,7 +138,7 @@ namespace OrmTest.UnitTest
{
var x2 = Guid.NewGuid();
Expression<Func<Student, bool>> exp = it =>"aaaa".Substring(0, 2)== "a";
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -152,7 +152,7 @@ namespace OrmTest.UnitTest
{
var x2 = Guid.NewGuid();
Expression<Func<Student, bool>> exp = it => SqlFunc.ToBool("true") == true;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -165,7 +165,7 @@ namespace OrmTest.UnitTest
{
var x2 = Guid.NewGuid();
Expression<Func<Student, bool>> exp = it => SqlFunc.ToDouble("2") == 2;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -178,11 +178,11 @@ namespace OrmTest.UnitTest
{
var x2 = Guid.NewGuid();
Expression<Func<Student, bool>> exp = it => SqlFunc.ToGuid("A94027A3-476E-478D-8228-F4054394B874") == x2;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(CAST(@MethodConst0 AS CHAR) = @Const1 )", new List<SugarParameter>() {
base.Check(value, pars, "(CAST(@MethodConst0 AS TEXT) = @Const1 )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0","A94027A3-476E-478D-8228-F4054394B874"),new SugarParameter("@Const1",x2)
}, "ToGuid error");
}
@ -191,7 +191,7 @@ namespace OrmTest.UnitTest
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => SqlFunc.ToDecimal("22") == 1;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -204,11 +204,11 @@ namespace OrmTest.UnitTest
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => SqlFunc.ToString("2015-1-1") == "a";
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(CAST(@MethodConst0 AS CHAR) = @Const1 )", new List<SugarParameter>() {
base.Check(value, pars, "(CAST(@MethodConst0 AS TEXT) = @Const1 )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1","a")
}, "Tostring error");
}
@ -217,11 +217,11 @@ namespace OrmTest.UnitTest
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => SqlFunc.ToDate("2015-1-1") == x2;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(CAST(@MethodConst0 AS DATETIME) = @Const1 )", new List<SugarParameter>() {
base.Check(value, pars, "(DATETIME(@MethodConst0) = @Const1 )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1",x2)
}, "ToDate error");
}
@ -229,11 +229,11 @@ namespace OrmTest.UnitTest
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => Convert.ToDateTime("2015-1-1") == x2;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(CAST(@MethodConst0 AS DATETIME) = @Const1 )", new List<SugarParameter>() {
base.Check(value, pars, "(DATETIME(@MethodConst0) = @Const1 )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0","2015-1-1"),new SugarParameter("@Const1",x2)
}, "ExtendDate error");
}
@ -242,11 +242,11 @@ namespace OrmTest.UnitTest
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => SqlFunc.ToInt64("3") == 1;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(CAST(@MethodConst0 AS SIGNED) = @Const1 )", new List<SugarParameter>() {
base.Check(value, pars, "(CAST(@MethodConst0 AS INTEGER) = @Const1 )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0","3"),new SugarParameter("@Const1",(Int64)1)
}, "ToInt64 error");
}
@ -255,11 +255,11 @@ namespace OrmTest.UnitTest
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => SqlFunc.ToInt32("3") == 1;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(CAST(@MethodConst0 AS SIGNED) = @Const1 )", new List<SugarParameter>() {
base.Check(value, pars, "(CAST(@MethodConst0 AS INTEGER) = @Const1 )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0","3"),new SugarParameter("@Const1",1)
}, "ToInt32 error");
}
@ -268,11 +268,11 @@ namespace OrmTest.UnitTest
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => SqlFunc.DateValue(x2, DateType.Year) == 1;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, " ((@MethodConst1(@MethodConst0)) = @Const2 ) ", new List<SugarParameter>() {
base.Check(value, pars, "(CAST(STRFTIME('%Y', DATETIME(DATETIME(@MethodConst0), 'LOCALTIME')) AS INTEGER) = @Const2 )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",DateType.Year),new SugarParameter("@Const2",1)
}, "DateValue error");
}
@ -280,29 +280,29 @@ namespace OrmTest.UnitTest
private void StartsWith()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.StartsWith(it.Name, "a");
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, " (`Name` like concat(@MethodConst0,'%')) ", new List<SugarParameter>() {
base.Check(value, pars, " (`Name` like @MethodConst0||'%') ", new List<SugarParameter>() {
new SugarParameter("@MethodConst0","a")
}, "StartsWith error");
}
private void EndsWith()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.EndsWith(it.Name, "a");
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, " (`Name` like concat('%',@MethodConst0)) ", new List<SugarParameter>() {
base.Check(value, pars, " (`Name` like '%'||@MethodConst0) ", new List<SugarParameter>() {
new SugarParameter("@MethodConst0","a")
}, "EndsWith");
}
private void Between()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.Between(it.Name, 1, 2);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -314,38 +314,38 @@ namespace OrmTest.UnitTest
private void DateAddByType()
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => SqlFunc.DateAdd(x2, 11, DateType.Millisecond) == x2;
MySqlExpressionContext expContext = new MySqlExpressionContext();
Expression<Func<Student, bool>> exp = it => SqlFunc.DateAdd(x2, 11, DateType.Minute) == x2;
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "((DATE_ADD(@MethodConst1 INTERVAL @MethodConst2 @MethodConst0)) = @Const3 )", new List<SugarParameter>() {
base.Check(value, pars, "(DATETIME(DATETIME(@MethodConst0), '+11 Minutes') = @Const3 )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",11),new SugarParameter("@Const3",x2),
new SugarParameter("@MethodConst2",DateType.Millisecond)
new SugarParameter("@MethodConst2",DateType.Minute)
}, "DateAddByType error");
}
private void DateAddDay()
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => SqlFunc.DateAdd(x2, 1) == x2;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "((DATE_ADD(@MethodConst1 INTERVAL @MethodConst0 day)) = @Const2 )", new List<SugarParameter>() {
base.Check(value, pars, "(DATE(DATETIME(@MethodConst0), '+1 days') = @Const2 )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",1),new SugarParameter("@Const2",x2)
}, "DateIsSameByType error");
}, "DateAddDay error");
}
private void DateIsSameByType()
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => SqlFunc.DateIsSame(x2, x2, DateType.Millisecond);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, " (TIMESTAMPDIFF(@MethodConst2,@MethodConst0,@MethodConst1)=0) ", new List<SugarParameter>() {
base.Check(value, pars, " Cast((JulianDay(@MethodConst0) - JulianDay(@MethodConst1)) *86400000 As INTEGER)", new List<SugarParameter>() {
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2),
new SugarParameter("@MethodConst2",DateType.Millisecond)
}, "DateIsSameByType error");
@ -354,11 +354,11 @@ namespace OrmTest.UnitTest
{
var x2 = DateTime.Now;
Expression<Func<Student, bool>> exp = it => SqlFunc.DateIsSame(x2, x2);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(TIMESTAMPDIFF(day,@MethodConst0,@MethodConst1)=0) ", new List<SugarParameter>() {
base.Check(value, pars, " Cast((JulianDay(@MethodConst0) - JulianDay(@MethodConst1)) *1 As INTEGER)", new List<SugarParameter>() {
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2)
}, "DateIsSameDay error");
}
@ -366,7 +366,7 @@ namespace OrmTest.UnitTest
private void Equals()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.Equals(it.Name, "a");
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -376,7 +376,7 @@ namespace OrmTest.UnitTest
Expression<Func<Student, bool>> exp2 = it => SqlFunc.Equals("a", it.Name);
MySqlExpressionContext expContext2 = new MySqlExpressionContext();
SqliteExpressionContext expContext2 = new SqliteExpressionContext();
expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
var value2 = expContext2.Result.GetString();
var pars2 = expContext2.Parameters;
@ -387,7 +387,7 @@ namespace OrmTest.UnitTest
private void Equals_2()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.Equals(it.Name, it.Name);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -397,7 +397,7 @@ namespace OrmTest.UnitTest
Expression<Func<Student, bool>> exp2 = it => SqlFunc.Equals("a", "a2");
MySqlExpressionContext expContext2 = new MySqlExpressionContext();
SqliteExpressionContext expContext2 = new SqliteExpressionContext();
expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
var value2 = expContext2.Result.GetString();
var pars2 = expContext2.Parameters;
@ -409,22 +409,22 @@ namespace OrmTest.UnitTest
private void Contains()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.Contains(it.Name, "a");
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, " (`Name` like concat('%',@MethodConst0,'%')) ", new List<SugarParameter>() {
base.Check(value, pars, " (`Name` like '%'||@MethodConst0||'%') ", new List<SugarParameter>() {
new SugarParameter("@MethodConst0","a")
}, "Contains error");
}
private void Contains2(string name="a")
{
Expression<Func<Student, bool>> exp = it => SqlFunc.Contains(it.Name, name);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, " (`Name` like concat('%',@MethodConst0,'%')) ", new List<SugarParameter>() {
base.Check(value, pars, " (`Name` like '%'||@MethodConst0||'%') ", new List<SugarParameter>() {
new SugarParameter("@MethodConst0","a")
}, "Contains2 error");
}
@ -432,7 +432,7 @@ namespace OrmTest.UnitTest
private void ExtendContainsArray() {
var array = new string[] { "1", "2" }.ToList();
Expression<Func<Student, bool>> exp = it => array.Contains(it.Name);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -443,7 +443,7 @@ namespace OrmTest.UnitTest
{
string[] array = new string[] { "1", "2" };
Expression<Func<Student, bool>> exp = it => SqlFunc.ContainsArray(array, it.Name);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -453,7 +453,7 @@ namespace OrmTest.UnitTest
private void Trim()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.Trim(" a") == it.Name;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -465,7 +465,7 @@ namespace OrmTest.UnitTest
private void ToUpper()
{
Expression<Func<Student, bool>> exp = it => "a" == SqlFunc.ToUpper(it.Id);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -476,7 +476,7 @@ namespace OrmTest.UnitTest
private void ToLower()
{
Expression<Func<Student, bool>> exp = it => "a" == SqlFunc.ToLower(it.Id);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -489,7 +489,7 @@ namespace OrmTest.UnitTest
private void StringIsNullOrEmpty()
{
Expression<Func<Student, bool>> exp = it => it.Id > 2 || SqlFunc.IsNullOrEmpty(it.Id); ;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -500,7 +500,7 @@ namespace OrmTest.UnitTest
private void StringIsNullOrEmpty2()
{
Expression<Func<Student, bool>> exp = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(true); ;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -513,7 +513,7 @@ namespace OrmTest.UnitTest
{
int a = 1;
Expression<Func<Student, bool>> exp = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(a); ;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -526,7 +526,7 @@ namespace OrmTest.UnitTest
{
WhereConst.name = "xx";
Expression<Func<Student, bool>> exp = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(WhereConst.name); ;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -539,7 +539,7 @@ namespace OrmTest.UnitTest
{
WhereConst.name = "xx";
Expression<Func<Student, bool>> exp = it => !SqlFunc.IsNullOrEmpty(WhereConst.name); ;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -552,7 +552,7 @@ namespace OrmTest.UnitTest
private void HasValue()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.HasValue(it.Name);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -565,7 +565,7 @@ namespace OrmTest.UnitTest
private void HasNumber()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.HasNumber(it.Id);
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -579,7 +579,7 @@ namespace OrmTest.UnitTest
private void IIF()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(it.Id == 1, 1, 2)==1;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
@ -595,11 +595,11 @@ namespace OrmTest.UnitTest
private void IIF2()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(SqlFunc.Contains(it.Name,"a"), 1, 2)==1;
MySqlExpressionContext expContext = new MySqlExpressionContext();
SqliteExpressionContext expContext = new SqliteExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(( CASE WHEN (`Name` like concat('%',@MethodConst0,'%')) THEN @MethodConst1 ELSE @MethodConst2 END ) = @Const3 )", new List<SugarParameter>()
base.Check(value, pars, "(( CASE WHEN (`Name` like '%'||@MethodConst0||'%') THEN @MethodConst1 ELSE @MethodConst2 END ) = @Const3 )", new List<SugarParameter>()
{
new SugarParameter("@MethodConst0","a"),
new SugarParameter("@MethodConst1",1),

Loading…
Cancel
Save