Browse Source

Expression Bug

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
cc9e47246e
  1. 2
      SqlServerTest/Demos/1_Query.cs
  2. 24
      SqlServerTest/Program.cs
  3. 14
      SqlServerTest/UnitTest/ExpressionTest/Where.cs
  4. 15
      SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs
  5. 13
      SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs

2
SqlServerTest/Demos/1_Query.cs

@ -119,9 +119,11 @@ namespace OrmTest.Demo
private static void Ado()
{
var db = GetInstance();
db.Ado.BeginTran();
var t1 = db.Ado.SqlQuery<string>("select 'a'");
var t2 = db.Ado.GetInt("select 1");
var t3 = db.Ado.GetDataTable("select 1 as id");
db.Ado.CommitTran();
//more
//db.Ado.GetXXX...
}

24
SqlServerTest/Program.cs

@ -18,18 +18,18 @@ namespace OrmTest
static void Main(string[] args)
{
/***Unit Test***/
new Field(1).Init();
new Where(1).Init();
new Method(1).Init();
new JoinQuery(1).Init();
new SingleQuery(1).Init();
new SelectQuery(1).Init();
new AutoClose(1).Init();
new Insert(1).Init();
new Delete(1).Init();
new Update(1).Init();
new Mapping(1).Init();
new DataTest(1).Init();
//new Field(1).Init();
//new Where(1).Init();
//new Method(1).Init();
//new JoinQuery(1).Init();
//new SingleQuery(1).Init();
//new SelectQuery(1).Init();
//new AutoClose(1).Init();
//new Insert(1).Init();
//new Delete(1).Init();
//new Update(1).Init();
//new Mapping(1).Init();
//new DataTest(1).Init();
/***Performance Test***/
new SqlSugarPerformance(100).Select();

14
SqlServerTest/UnitTest/ExpressionTest/Where.cs

@ -34,6 +34,7 @@ namespace OrmTest.UnitTest
whereSingle11();
whereSingle12();
whereSingle13();
whereSingle14();
WhereMultiple1();
WhereMultiple2();
@ -235,6 +236,19 @@ namespace OrmTest.UnitTest
}, "whereSingle13");
}
private void whereSingle14()
{
Expression<Func<Student, bool>> exp = it =>true&& it.Name != null;
ExpressionContext expContext = new ExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(( 1 = 1 ) AND( [Name] IS NOT NULL ))", new List<SugarParameter>()
{
}, "whereSingle14");
}
}
public class WhereConst

15
SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs

@ -106,7 +106,22 @@ namespace SqlSugar
}
return null;
}
protected void AppendMember(ExpressionParameter parameter, bool? isLeft, object appendValue) {
Context.ParameterIndex++;
if (isLeft == true)
{
appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index;
}
if (this.Context.Result.Contains(ExpressionConst.Format0))
{
this.Context.Result.Replace(ExpressionConst.Format0, appendValue.ObjToString());
}
else
{
this.Context.Result.Append(appendValue);
}
}
protected void AppendValue(ExpressionParameter parameter, bool? isLeft, object value)
{
if (parameter.BaseExpression is BinaryExpression || parameter.BaseExpression == null)

13
SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs

@ -33,11 +33,18 @@ namespace SqlSugar
{
var parentIsBinary = parameter.BaseParameter.CurrentExpression is BinaryExpression;
var parentIsRoot = parameter.BaseParameter.CurrentExpression is LambdaExpression;
if (parentIsRoot&& value!=null&&value.GetType()==PubConst.BoolType) {
this.Context.Result.Append(value.ObjToBool()?"( 1 = 1 ) ": "( 1 = 2 ) ");
if (parentIsRoot && value != null && value.GetType() == PubConst.BoolType)
{
this.Context.Result.Append(value.ObjToBool() ? "( 1 = 1 ) " : "( 1 = 2 ) ");
break;
}
if (value == null && parentIsBinary) {
if (parentIsBinary && value != null && value.GetType() == PubConst.BoolType && parameter.OppsiteExpression is BinaryExpression)
{
AppendMember(parameter,isLeft,(value.ObjToBool() ? "( 1 = 1 ) " : "( 1 = 2 ) "));
break;
}
if (value == null && parentIsBinary)
{
parameter.BaseParameter.ValueIsNull = true;
value = "NULL";
}

Loading…
Cancel
Save